从google.cloud.speech_v1导入枚举时遇到问题



我有这样的代码:

from google.cloud import speech_v1
from google.cloud.speech_v1 import enums
import os
import importlib
# Import the enums module from the google.cloud.speech_v1 package
enums = importlib.import_module("google.cloud.speech_v1.enums")
# Set your Google Cloud project and service account credentials
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "creds.json"

# Create a client for the Google Cloud Speech-to-Text API
stt_client = speech_v1.SpeechClient()
# Transcribe the audio data
response = stt_client.recognize(
audio=speech_v1.types.RecognitionAudio(uri="gs://focus-0/speech-to-text-sample.wav"),
config=speech_v1.types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
sample_rate_hertz=48000,
language_code="en-US"
)
)
# Print the transcribed text
for result in response.results:
print("Transcription: {}".format(result.alternatives[0].transcript))

当我运行它时,我得到这个:

Traceback (most recent call last):
File "/Users/dir/git/fp-scrapers/speech/1-STT.py", line 5, in <module>
from google.cloud.speech_v1 import enums
ImportError: cannot import name 'enums' from 'google.cloud.speech_v1' (/opt/homebrew/lib/python3.9/site-packages/google/cloud/speech_v1/__init__.py)

我已经尝试了几种导入枚举的方法,但是没有一种是有效的。

有人看到我做错了什么吗?

枚举和类型已被删除。库的X版本

在这个github中提到。请参阅此迁移指南。您可以参考这个快速入门来获取安装说明和更新的客户端库

:

from google.cloud import speech
encoding = speech.enums.RecognitionConfig.AudioEncoding.LINEAR16
audio = speech.types.RecognitionAudio(content=content)

:

from google.cloud import speech
encoding = speech.RecognitionConfig.AudioEncoding.LINEAR16
audio = speech.RecognitionAudio(content=content)

相关内容

  • 没有找到相关文章

最新更新