1

I am trying to use Google Speech API to recognize speech from mic input in real time. I have tried https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/speech/cloud-client/transcribe_streaming_mic.py but this error came out. Anybody knows how to solve this?

from google.cloud.speech import enums
ImportError: cannot import name 'enums'

Update: I have solved the problem by running the code in virtual environment as suggested by the official Cloud Speech API website. However, I still dont understand why we need to run that in virtual environment instead of my original environment as the virtual environment is not Linux or other OS.

sttc1998
  • 51
  • 2
  • 10

3 Answers3

0

I am using cloud function to transcribe the audio to text. I believe the documentation for google-cloud-speech has been updated, you may refer to the documentation. https://pypi.org/project/google-cloud-speech/. I believe the class is now called speech_v1, you can use the alias "as speech" to make the github sample codes work.

from google.cloud import speech_v1 as speech
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types

HTH.

James Ching
  • 456
  • 1
  • 5
  • 10
0

I got mine working with the following import

from google.cloud.speech_v1.gapic import enums
Varveler
  • 1
  • 1
0

Using pip install google.cloud.speech, you are getting the latest version, currently V2.

In V2, enums and types have been removed and are no longer needed.

https://github.com/googleapis/python-speech/blob/master/UPGRADING.md#enums-and-types

Hassan
  • 123
  • 1
  • 2
  • 11