1

我需要为一个项目进行语音识别(法语),我选择了谷歌语音 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))

我关注这两个页面:
google-cloud-speech 0.25.1
google-cloud client

4

1 回答 1

1

您需要安装 google-cloud 客户端

sudo pip install google-cloud

应该这样做

:~ $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.cloud import speech
>>> 
于 2017-05-19T16:43:44.270 回答