我正在尝试从我的音频创建srt文件。事实上,为了这个,我正在跟踪这个tutorial。但是当我运行命令python3 speech2srt.py --storage_uri gs://subtitlingsc/en.wav
时,它显示以下错误:
Transcribing gs://subtitlingsc/en.wav ...
Traceback (most recent call last):
File "speech2srt.py", line 152, in <module>
main()
File "speech2srt.py", line 146, in main
subs = long_running_recognize(args)
File "speech2srt.py", line 44, in long_running_recognize
operation = client.long_running_recognize(config, audio)
TypeError: long_running_recognize() takes from 1 to 2 positional arguments but 3 were given
如果有人能帮忙解决这个问题
speech2srt.pyfile的链接
出现这种情况的原因是,您提供了参数config和audio,这两个参数都应该是关键字参数。要解决此问题,可以将
client.long_running_recognize(config, audio)
替换为client.long_running_recognize(config = config, audio = audio)
您可以确认here,函数long\u running\u recognize的定义如下:
在Python中,带有参数(arg1、arg2、*、arg3、agr4、…)的函数定义意味着只有*前面的参数才能作为位置参数提供。在这种情况下,*后面的所有参数都应作为关键字参数提供
例如,让我们使用我提到的参数创建一个函数:
如果我尝试将此函数调用为
function(1,2,3,4)
,它将失败,因为只需要两个位置参数。为了正确地调用它,我应该提供两个位置参数和两个关键字参数,因此正确的调用应该是function(1, 2, arg3 = 3, arg4 = 4)
相关问题 更多 >
编程相关推荐