首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >google cloud speech API出错

google cloud speech API出错
EN

Stack Overflow用户
提问于 2018-01-29 05:37:59
回答 1查看 1.2K关注 0票数 2

我正在尝试使用Google Cloud Speech API将音频转换为文本,但收到以下错误:

代码语言:javascript
复制
Traceback (most recent call last):
  File "/home/prateek/Google Drive/projects/linuxAI/src/linuxAI.py", line 6, in <module>
    client = speech.SpeechClient()
  File "/usr/lib/python3.6/site-packages/google/cloud/gapic/speech/v1/speech_client.py", line 146, in __init__
    ssl_credentials=ssl_credentials)
  File "/usr/lib/python3.6/site-packages/google/gax/grpc.py", line 106, in create_stub
    credentials = _grpc_google_auth.get_default_credentials(scopes)
  File "/usr/lib/python3.6/site-packages/google/gax/_grpc_google_auth.py", line 62, in get_default_credentials
    credentials, _ = google.auth.default(scopes=scopes)
  File "/usr/lib/python3.6/site-packages/google/auth/_default.py", line 283, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or
explicitly create credential and re-run the application. For more
information, please see
https://developers.google.com/accounts/docs/application-default-credentials.

我使用的是以下代码:

代码语言:javascript
复制
"""Transcribe the given audio file."""
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types

client = speech.SpeechClient()
speech_file = "output.wav"
with open(speech_file, 'rb') as audio_file:
    content = audio_file.read()

audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(
    encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000,
    language_code='en-US')

response = client.recognize(config, audio)
# Each result is for a consecutive portion of the audio. Iterate through
# them to get the transcripts for the entire audio file.
for result in response.results:
    # The first alternative is the most likely one for this portion.
    print('Transcript: {}'.format(result.alternatives[0].transcript))

我在here上找到了教程。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-01-29 05:42:28

您是否使用凭据进行了身份验证?

首先,您需要创建api密钥。https://support.google.com/cloud/answer/6158862?hl=en

请阅读本教程进行身份验证。https://cloud.google.com/speech/docs/auth

您可以看到Google提供的一些示例应用程序。https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/speech/cloud-client

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48491601

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档