我正在使用Google Speech API转录音频,使用long-running-recognize endpoint通过Python Cloud Speech API Client Library .
我的音频文件通常是15-90分钟 . 在大多数情况下,API调用工作正常,返回我的音频转录 . 但是,如果我的音频包含长时间的静音(大约超过一分钟),则转录失败 . Python客户端库调用返回的错误是 google.gax.errors.GaxError: Server unavailable, please try again later.
一个简单的工作代码示例(一旦下载了Python Cloud Speech API客户端库)如下:
from google.cloud import speech_v1
from google.cloud.speech_v1 import types, enums
client = speech_v1.SpeechClient()
audio = types.RecognitionAudio(uri=filepath)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.ENCODING_UNSPECIFIED,
language_code='en-US',
enable_word_time_offsets=True,
max_alternatives=30
)
# Start the async operation
op = client.long_running_recognize(
audio=audio,
config=config
)
# Wait for the operation to complete
response = op.result()
如何使用Google Speech API转录长时间静音的音频文件?