我需要为一个项目进行语音识别(法语),我选择了谷歌语音 api,但出现以下错误:
pi@raspberrypi:~ $ sudo python ~/sttG.py
Traceback (most recent call last):
File "sttG.py", line 1, in <module>
from google.cloud import speech
File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/__init__.py", line 22, in <module>
from google.cloud.speech.client import Client
File "/usr/local/lib/python2.7/dist-packages/google/cloud/speech/client.py", line 19, in <module>
from google.cloud.client import Client as BaseClient
ImportError: No module named client
首先我安装 google sdk 并使用我的帐户登录,然后我使用以下行安装 google cloud speech for python:
$ pip install --upgrade google-cloud-speech
当我尝试启动此代码时出现此错误:
from google.cloud import speech
client = speech.Client()
sample = client.sample(source_uri='gs://my-bucket/recording.flac',
encoding=speech.Encoding.FLAC,
sample_rate=44100)
results = sample.sync_recognize(
language_code='en-GB', max_alternatives=2)
for result in results:
for alternative in result.alternatives:
print('=' * 20)
print('transcript: ' + alternative.transcript)
print('confidence: ' + str(alternative.confidence))