【问题标题】:403(Forbidden), Invalid Key Error On Google Speech API403(禁止),Google Speech API 上的无效键错误
【发布时间】:2016-12-05 06:15:51
【问题描述】:

我正在尝试使用以下 url 访问语音 api,但总是收到 403(禁止)错误,无效密钥。

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

我已尝试使用服务器密钥和浏览器密钥,如此 Keys 图像所示。

我正在使用 .NET HTTP 客户端发送 http 请求;代码sn-p如下:

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;

谁能帮我找出这里的问题。

谢谢, 简介

【问题讨论】:

  • 有完全相同的问题。你找到解决方案了吗?
  • 你可以试试这个网址:google.com/speech-api/v2/…
  • 悬停时黄色警告图标表示什么?如果从浏览器发送请求,则只能使用浏览器密钥。最后,您的代码似乎没有使用密钥本身。
  • 您找到解决方案了吗?

标签: c# .net google-cloud-platform http-status-code-403 google-speech-api


【解决方案1】:

对于那个API endpoint,不再提供使用配额。而且,显然,它是the Chromium project 的社区开发人员专用的端点。

Google 的语音 API 是 the Cloud Speech API

您引用的keys 似乎是在您的 Google Cloud 项目 (GCP) 中设置的。 GCP,隐含的那些键,可以链接到Cloud Speech API,正如here所指出的那样,而不是https://www.google.com/speech-api/v2/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-05
    • 1970-01-01
    • 2013-12-26
    相关资源
    最近更新 更多