ImportError:无法导入名称'speech_v1p1beta1'

时间:2018-06-09 09:55:55

标签: python google-cloud-speech

我试图在python中运行以下脚本,将视频文件转换为文本:

from google.cloud import speech_v1p1beta1 as speech
client = speech.SpeechClient()

with open(speech_file, 'rb') as audio_file:
    content = audio_file.read()

audio = speech.types.RecognitionAudio(content=content)

config = speech.types.RecognitionConfig(
    encoding=speech.enums.RecognitionConfig.AudioEncoding.LINEAR16,
    sample_rate_hertz=16000,
    language_code='en-US',
    model='video')

response = client.recognize(config, audio)

for i, result in enumerate(response.results):
    alternative = result.alternatives[0]
    print('-' * 20)
    print('First alternative of result {}'.format(i))
    print(u'Transcript: {}'.format(alternative.transcript))

当我运行此脚本时,我收到以下错误:

  

ImportError:无法导入名称'speech_v1p1beta1'

有关如何解决此问题的任何建议?

1 个答案:

答案 0 :(得分:2)

尝试跑步 $ pip install --upgrade google-cloud-speech更新您的依赖关系。