我正在尝试使用 Google 语音转文本来实时转录麦克风中的音频。我还想设置一个超时时间,规定 Google 在超时之前等待的时间。我尝试在 python 中使用以下代码
client = speech.SpeechClient()
activityTimeout = speech.StreamingRecognitionConfig.VoiceActivityTimeout()
activityTimeout.speech_start_timeout = Duration(seconds=60)
config = speech.RecognitionConfig(
encoding=speech.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=SAMPLE_RATE,
language_code="en-US",
max_alternatives=1,
model="command_and_search",
use_enhanced=True,
)
streaming_config = speech.StreamingRecognitionConfig(
config=config,
interim_results=False,
enable_voice_activity_events=True,
voice_activity_timeout=activityTimeout
)
但是,每次我用音频内容打电话给 Google 时,我得到的只是:
google.api_core.exceptions.Cancelled: 499 The operation was cancelled.
堆栈跟踪返回到此文件:
google\api_core\grpc_helpers.py", line 115, in __next__
raise exceptions.from_grpc_error(exc) from exc
我在这里做错了什么,拨打超时电话吗?
如果我不使用超时,一切都会完美运行,除了程序坐在那里等待某些内容发送到 Google 进行转录之外。我希望程序在设定的时间段(例如 60 秒)后超时。
我也有同样的问题...你找到答案了吗?