refer to url ImportError: cannot import name 'enums'
google cloud speech ImportError: cannot import name 'enums'
I got the error when using google-cloud-speech api for my project. I'm NOT using pipenv for virtual environment. I installed google-cloud-speech api with
pip3 install google-cloud-speech
and
pip3 update google-cloud-speech
environment win10 python3.6.8
google-api-core 1.14.2
google-auth 1.6.3
google-cloud 0.34.0
google-cloud-core 1.0.3
google-cloud-speech 1.2.0
google-cloud-storage 1.18.0
google-resumable-media 0.3.3
googleapis-common-protos 1.6.0
grpc-google-cloud-speech-v1beta1 1.0.1
enum34 1.1.6 enums 0.0.2
the error contents
from google.cloud.speech import enums
ImportError: cannot import name 'enums'
I already tried the pip command follow.
pip3 install enums
pip3 install enum34
pip3 install google-cloud-speech
pip3 upgrade google-cloud-speech
here the code when the code did in google cloud shell of GCP, the following code works well and I didn't get the error.
# !/usr/bin/env python
# coding: utf-8
import argparse
import io
import sys
import codecs
import datetime
import locale
from google.cloud import storage
from google.cloud import speech_v1 as speech
from google.cloud.speech_v1 import enums
from google.cloud.speech_v1 import types
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
def transcribe_gcs(gcs_uri):
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
audio = types.RecognitionAudio(uri=gcs_uri)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC, # wavsetting
sample_rate_hertz=44100, # hertz must be fix raw files
language_code='ja-JP') #for japanese language
operation = client.long_running_recognize(config, audio)
print('Waiting for operation to complete...')
operationResult = operation.result()
d = datetime.datetime.today()
today = d.strftime("%Y%m%d-%H%M%S")
fout = codecs.open('output{}.txt'.format(today), 'a', 'utf-8')
for result in operationResult.results:
for alternative in result.alternatives:
fout.write(u'{}\n'.format(alternative.transcript))
print('alternative.transcript===',format(alternative.transcript))
fout.close()
print('alternative.transcript===',format(alternative.transcript))
print('operationResult===',operationResult)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument(
'path', help='GCS path for audio file to be recognized')
args = parser.parse_args()
transcribe_gcs(args.path)
Thanks in advance.