Я пытался запустить следующий код из этой ссылки .
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 на Raspberry Pi.
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 дней, и я не нашел никакого решения.
Любая помощь будет оценена.