[英]google speech api forbidden
大家好,我正在使用 python 语音识别模型开发 google 语音 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))
任何形式的帮助表示赞赏。
我建议首先将您的凭据设置为局部变量:
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”定义,例如英语美国。 在此处查看完整列表https://cloud.google.com/speech-to-text/docs/languages?hl=es
请注意,当您在没有密钥的情况下使用 google 语音识别 API 时,语音识别模块将使用默认密钥。 但是,Google 可以随时拒绝该请求。 在这种情况下,您将收到错误recognition request failed: Forbidden
。 如果您使用错误的密钥,也会发生这种情况。 引用__init__.py
模块的第 810 行:
使用 Google Speech Recognition API 对
audio_data
(一个AudioData
实例)执行语音识别。 Google Speech Recognition API 密钥由key
指定。 如果未指定,则它使用开箱即用的通用密钥。 这通常应仅用于个人或测试目的,因为它可能随时被 Google 撤销。 要获取您自己的 API 密钥,只需按照 Chromium 开发人员站点上的API Keys <http://www.chromium.org/developers/how-tos/api-keys>
__ 页面上的步骤操作即可。 在 Google Developers Console 中,Google Speech Recognition 被列为“Speech API”。
要么给自己一个钥匙,要么如果你真的不想使用内置的recognize_sphynx(audio)
或snowboy。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.