谷歌演讲api被禁止

时间:2017-03-09 05:45:38

标签: python speech-recognition google-speech-api

Hey Guys我正在使用python语音识别模型研究谷歌语音api。我已经尝试使用默认的api和它们,它的工作原理。但是当我尝试将它与我的api一起使用时。我收到以下错误:

  

无法请求Google语音识别服务的结果;   识别请求失败:禁止

这是我的代码

import speech_recognition as sr
from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "file.wav")

r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
    audio = r.record(source) # read the entire audio file
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("Google Speech Recognition thinks you said " + r.recognize_google(audio, key="AIzaSyAqwPcs_F6cyNltsrZPGRQKRFakDX3d85"))
except sr.UnknownValueError:
   print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
   print("Could not request results from Google Speech Recognition   service; {0}".format(e))

感谢任何形式的帮助。

2 个答案:

答案 0 :(得分:0)

我建议首先将您的凭据设置为本地变量:

export GOOGLE_APPLICATION_CREDENTIALS='/home/user/Documents/your_credentials.json'

此处的详细信息:https://cloud.google.com/docs/authentication/getting-started

然后这可能会有助于较长的.wav成绩单:https://cloud.google.com/speech-to-text/docs/async-recognize?hl=es

语言由“ en-US”定义,例如英语US。请参阅完整列表https://cloud.google.com/speech-to-text/docs/languages?hl=es

答案 1 :(得分:0)

请注意,当您在没有密钥的情况下使用 googles 语音识别 API 时,语音识别模块将使用默认密钥。但是,Google 可以随时拒绝该请求。在这种情况下,您将收到错误 recognition request failed: Forbidden。如果您使用错误的密钥,也会发生这种情况。 引用 __init__.py 模块第 810 行:

<块引用>

audio_data(一个 AudioData 实例),使用 Google Speech Recognition API。谷歌演讲 识别 API 密钥由 key 指定。如果未指定,则使用 一个开箱即用的通用密钥。这个一般应该用 仅用于个人或测试目的,因为它可能会被撤销 随时谷歌。要获取您自己的 API 密钥,只需按照 API Keys <http://www.chromium.org/developers/how-tos/api-keys>__ 页面上的步骤 Chromium 开发者网站。在 Google Developers Console 中,Google 语音识别被列为“语音 API”。

要么给自己拿一把钥匙,要么如果你真的不想使用内置的 recognize_sphynx(audio) 或雪童。