我有以下代码成功识别短(不到 1 分钟)测试音频文件,但识别另一个长音频文件(1.5h)失败。
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.)>)
但我已经uri
在我的 python 脚本中使用了参数。怎么了?
更新
@NieDzejkob 帮助理解了错误。因此,long_running_recognize
应该使用 method 而不是recognize
. 综合long_running_recognize
使用示例可以在对应的文档页面找到