首页 > 解决方案 > Google Speech to text Error Raspberry Pi - “模块对象没有属性 RecognitionAudio”

问题描述

我一直在关注谷歌 API 语音到文本转换的快速入门指南。

https://cloud.google.com/speech-to-text/docs/libraries

每当我尝试运行示例 python 脚本时,我都会收到一条错误消息,指出语音模块没有 RecognitionAudio 属性。我已按照教程运行 pip install --upgrade google-cloud-speech。还有什么可能是错的?

这是我正在运行的示例 python 代码。那些音频 = 语音.RecognitionAudio(uri=gcs_uri) 的错误

# Imports the Google Cloud client library
from google.cloud import speech


# Instantiates a client
client = speech.SpeechClient()

# The name of the audio file to transcribe
gcs_uri = "gs://cloud-samples-data/speech/brooklyn_bridge.raw"

audio = speech.RecognitionAudio(uri=gcs_uri)

config = speech.RecognitionConfig(
    encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000,
    language_code="en-US",
)

# Detects speech in the audio file
response = client.recognize(config=config, audio=audio)

for result in response.results:
    print("Transcript: {}".format(result.alternatives[0].transcript))

标签: pythongoogle-cloud-speech

解决方案


推荐阅读