'Attribute Error when importing SpeechClient from google.cloud.speech

I am trying to use Google cloud platform to transcript audio to text. I am stuck really at the beginning.

When I try to import :

import os
from google.cloud import speech
    
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'speech-333807-fbe7e537e3a2.json'
speech_client = speech.SpeechClient()

The error pops out:

AttributeError: module 'google.cloud.speech' has no attribute 'SpeechClient'

When I try to import this inside python shell, the above error pops out right away after import : from google.cloud import speech. But strangely enough, when I import it second time, import goes ok.

Do you have any clue why this is not working?

Thanks a lot!



Solution 1:[1]

I just managed to make the audio-to-text speech API work for me. You should try this instead:

from google.cloud import speech_v1 as speech

It's maybe just a version issue.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lucas D. Meier