Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: cannot import name 'speech_v1p1beta1'

i`m trying to run the following script in python which converts video file into text:

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))

when i run this script i get the following error:

ImportError: cannot import name 'speech_v1p1beta1'

Any suggestions on how to fix this?

like image 867
Or Bar Avatar asked Jan 28 '23 23:01

Or Bar


1 Answers

Try running $ pip install --upgrade google-cloud-speechto update your dependency.

like image 194
Torry Yang Avatar answered Jan 30 '23 11:01

Torry Yang