简体   繁体   English

谷歌语音api被禁止

[英]google speech api forbidden

Hey Guys I am working on google speech api using python speech recognition model.大家好,我正在使用 python 语音识别模型开发 google 语音 api。 I have tried using the default api along with them and it works.我曾尝试将默认 api 与它们一起使用,并且可以正常工作。 But when I try to use it along with my api.但是当我尝试将它与我的 api 一起使用时。 I am getting the following error:我收到以下错误:

Could not request results from Google Speech Recognition service;无法从 Google 语音识别服务请求结果; recognition request failed: Forbidden识别请求失败:禁止

And this is my code这是我的代码

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))

Any kind of help is appreciated.任何形式的帮助表示赞赏。

I suggest first set your credentials as a local variable:我建议首先将您的凭据设置为局部变量:

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

Details here: https://cloud.google.com/docs/authentication/getting-started详情请见: https : //cloud.google.com/docs/authentication/getting-started

Then this could help for long .wav transcripts: https://cloud.google.com/speech-to-text/docs/async-recognize?hl=es那么这可能有助于长 .wav 成绩单: https : //cloud.google.com/speech-to-text/docs/async-recognize?hl=es

The language is defined by 'en-US' for example for english US.该语言由“en-US”定义,例如英语美国。 See here the complete list https://cloud.google.com/speech-to-text/docs/languages?hl=es在此处查看完整列表https://cloud.google.com/speech-to-text/docs/languages?hl=es

notice that when you use googles speech recognition API without a key, the speech recognition module will use a default key.请注意,当您在没有密钥的情况下使用 google 语音识别 API 时,语音识别模块将使用默认密钥。 However Google can reject that request at any time.但是,Google 可以随时拒绝该请求。 In that case you will get the error recognition request failed: Forbidden .在这种情况下,您将收到错误recognition request failed: Forbidden This will also happen if you use a wrong key.如果您使用错误的密钥,也会发生这种情况。 Quote from the module at __init__.py at line 810:引用__init__.py模块的第 810 行:

Performs speech recognition on audio_data (an AudioData instance), using the Google Speech Recognition API.使用 Google Speech Recognition API 对audio_data (一个AudioData实例)执行语音识别。 The Google Speech Recognition API key is specified by key . Google Speech Recognition API 密钥由key指定。 If not specified, it uses a generic key that works out of the box.如果未指定,则它使用开箱即用的通用密钥。 This should generally be used for personal or testing purposes only, as it may be revoked by Google at any time .这通常应仅用于个人或测试目的,因为它可能随时被 Google 撤销 To obtain your own API key, simply following the steps on the API Keys <http://www.chromium.org/developers/how-tos/api-keys> __ page at the Chromium Developers site.要获取您自己的 API 密钥,只需按照 Chromium 开发人员站点上的API Keys <http://www.chromium.org/developers/how-tos/api-keys> __ 页面上的步骤操作即可。 In the Google Developers Console, Google Speech Recognition is listed as "Speech API".在 Google Developers Console 中,Google Speech Recognition 被列为“Speech API”。

Just either get yourself a key or if you really don't want to then use the inbuilt recognize_sphynx(audio) or the snowboy.要么给自己一个钥匙,要么如果你真的不想使用内置的recognize_sphynx(audio)或snowboy。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM