尝试Google语音API,但会在客户端模块上获得Importerror



我需要为一个项目进行语音识别(以法语(,然后选择Google Speeck 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并使用我的帐户登录然后,我使用此行安装了Python的Google Cloud演讲:

$ 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语音0.25.1
Google-Cloud客户端

您需要安装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
>>> 

相关内容

  • 没有找到相关文章

最新更新