运行脚本时出错:Google Speech API



我一直在尝试从这个链接运行以下代码。

import io
import os
# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
file_name = os.path.join(
os.path.dirname(__file__),
'resources',
'audio.raw')
# Loads the audio into memory
with io.open(file_name, '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')
# Detects speech in the audio file
response = client.recognize(config, audio)
for result in response.results:
print('Transcript: {}'.format(result.alternatives[0].transcript))

然而,当我在树莓派上使用python 3.4.2运行它时,我得到了以下错误。

Traceback (most recent call last):
File "script.py", line 10, in <module>
client = speech.SpeechClient()
File "/usr/local/lib/python3.4/dist-   packages/google/cloud/speech_v1/gapic/speech_client.py", line 137, in __init__
credentials=credentials,
File "/usr/local/lib/python3.4/dist-packages/google/cloud/speech_v1/gapic/transports/speech_grpc_transport.py", line 76, in __init__
channel)
File "/usr/local/lib/python3.4/dist- packages/google/api_core/operations_v1/operations_client.py", line 59, in     __init__
self.operations_stub = operations_pb2.OperationsStub(channel)
AttributeError: 'module' object has no attribute 'OperationsStub'

我已经试着克服这个问题大约3天了,但我没有找到任何解决方案。如有任何帮助,我们将不胜感激。

不确定是否仍然存在问题。今天早上我也经历了同样的事情。

I、 显然似乎安装了在没有GRPC支持的情况下构建的googleapis-common-protos版本(1.6.0b6(。我将其降级为1.5.3,重新启动jupyter服务器,它现在工作得很好。请参阅此链接。谷歌云Github

最新更新