gpt4 book ai didi

python-3.x - Google 语音 - googleapiclient.errors.UnknownApiNameOrVersion : name: speech version: v1beta1

转载 作者:行者123 更新时间:2023-12-02 02:58:35 24 4
gpt4 key购买 nike

我有以下代码

import speech_recognition as sr

filename = 'audio.flac'

r = sr.Recognizer()

with sr.AudioFile(filename) as source:
print('Recording started....')
audio_data = r.record(source)
print('Recording completed....')
with open(service_auth_file) as f:
text = r.recognize_google_cloud(audio_data)
print('completed the recognition')
print(text)

它需要一个名为 GOOGLE_APPLICATION_CREDENTIAL 的环境变量。引用:https://cloud.google.com/speech-to-text/docs/reference/libraries 。因此,我添加了包含以下数据的文件的位置(仅提及 JSON 文件中的 key ,因为其他信息是 secret 的)

{
"type": "service_account",
"project_id": "PROJECT_NAME",
"private_key_id": "PROJECT_KEY",
"private_key": "PRIVATE_KEY",
"client_email": "CLIENT_EMAIL",
"client_id": "CLIENT_ID",
"auth_uri": "AUTH_URI",
"token_uri": "TOKEN_URI",
"auth_provider_x509_cert_url": "AUTH_CERT_URL",
"client_x509_cert_url": "CLIENT_CERT_URL"
}

但是当我运行上面的代码时,我收到以下错误

Traceback (most recent call last):
File "./speech_recognizer.py", line 23, in <module>
text = r.recognize_google_cloud(audio_data)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/speech_recognition/__init__.py", line 800, in recognize_google_cloud
speech_service = build("speech", "v1beta1", credentials=api_credentials)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Users/sumitsurana/miniconda3/envs/gsp/lib/python3.8/site-packages/googleapiclient/discovery.py", line 233, in build
raise UnknownApiNameOrVersion(
googleapiclient.errors.UnknownApiNameOrVersion: name: speech version: v1beta1

当我搜索错误时,我发现了一个名为 gapic-google-cloud-speech-v1beta1 的包。因此,也尝试在安装后运行该文件。但仍然遇到同样的错误。

最佳答案

我不确定该错误的根源。您似乎已正确配置 GOOGLE_APPLICATION_CREDENTIALS。但使用 Google API 时需要检查一些事项。

  1. 检查您使用的服务帐户是否具有与语音 API 交互所需的权限。 (通常这应该返回一个身份验证错误。在这种情况下不太可能。)
  2. 检查您是否已启用 API。
  3. 如果您正在对 Google 服务帐户使用委派权限,请检查委派帐户是否拥有必要的权限并已启用 API。

关于python-3.x - Google 语音 - googleapiclient.errors.UnknownApiNameOrVersion : name: speech version: v1beta1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60527135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com