【发布时间】:2017-06-29 21:48:01
【问题描述】:
我有以下代码成功识别短(少于 1 分钟)测试音频文件,但识别另一个长音频文件(1.5 小时)失败。
from google.cloud import speech
def run_quickstart():
speech_client = speech.Client()
sample = speech_client.sample(source_uri="gs://linear-arena-2109/zoom0070.flac", encoding=speech.Encoding.FLAC)
alternatives = sample.recognize('uk-UA')
for alternative in alternatives:
print(u'Transcript: {}'.format(alternative.transcript))
with open("Output.txt", "w") as text_file:
for alternative in alternatives:
text_file.write(alternative.transcript.encode('utf8'))
if __name__ == '__main__':
run_quickstart()
这两个文件都上传到 Google Cloud。
第一个: https://storage.googleapis.com/linear-arena-2109/sample.flac
第二个: https://storage.googleapis.com/linear-arena-2109/zoom0070.flac
两者都是使用 ffmpeg 实用程序从 mp3 转换而来的:
ffmpeg -i sample.mp3 -ac 1 sample.flac
ffmpeg -i zoom0070.mp3 -ac 1 zoom0070.flac
第一个文件被成功识别,但第二个文件输出如下错误:
google.gax.errors.RetryError: GaxError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.INVALID_ARGUMENT, Sync input too long. For audio longer than 1 min use LongRunningRecognize with a 'uri' parameter.)>)
但我已经在我的 python 脚本中使用了uri 参数。怎么了?
更新
@NieDzejkob 帮助理解了错误。因此,应该使用方法long_running_recognize 而不是recognize。综合long_running_recognize使用示例可以在对应的document page上找到
【问题讨论】:
-
阅读错误信息以获得答案。
-
你是对的。应该改用
long_running_recognize方法。我已经修复了代码。我的音频文件目前正在由google-cloud-speech处理。