3

我想訪問語音api使用以下網址,並總是得到403(禁止)錯誤,無效的關鍵。403(禁止),谷歌語音API無效的關鍵錯誤

https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key= {}的myKey

我有兩個服務器密鑰和瀏覽器鍵嘗試這個Keys圖像,如圖所示。

我使用.NET HTTP Client發送http請求;代碼片段如下:

Stream stream = null; 
      StreamReader sr = null; 
      WebResponse response = null; 
      JSon.RecognizedItem result; 
      try 
      { 
       WebRequest request = WebRequest.Create(Constants.GoogleRequestString); 
       request.Method = "POST"; 
       request.ContentType = "audio/x-flac; rate=" + sampleRate; 
       request.ContentLength = bytes.Length; 

       stream = request.GetRequestStream(); 

       stream.Write(bytes, 0, bytes.Length); 
       stream.Close(); 

       response = request.GetResponse(); 

       stream = response.GetResponseStream(); 
       if (stream == null) 
       { 
        throw new Exception("Can't get a response from server. Response stream is null."); 
       } 
       sr = new StreamReader(stream); 

       //Get response in JSON format 
       string respFromServer = sr.ReadToEnd(); 

       var parsedResult = JSon.Parse(respFromServer); 
       result = 
        parsedResult.hypotheses.Where(d => d.confidence == parsedResult.hypotheses.Max(p => p.confidence)).FirstOrDefault(); 
      } 
      finally 
      { 
       if (stream != null) 
        stream.Close(); 

       if (sr != null) 
        sr.Close(); 

       if (response != null) 
        response.Close(); 
      } 

      return result == null ? "" : result.utterance; 

有沒有人可以幫助我在這裏找出問題。

謝謝, Ab。

+1

有完全相同的問題。你有沒有找到解決方案? –

+0

您可以嘗試以下網址:https://www.google.com/speech-api/v2/recognize?client=chromium&lang=en_US&key=[YOUR_KEY_HERE] –

+0

黃色警告圖標在盤旋時顯示的內容是什麼?如果從瀏覽器發送請求,則只能使用瀏覽器密鑰。最後,你的代碼似乎並不使用密鑰本身。 – Nick

回答