在做语音识别时,我们需要调用recognize_google()函数来识别我们的音频数据,但是却出现了以下错误:
r.recognize_google(audio)
RequestError: recognition connection failed: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
'the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle taste fine with ham tacos al Pastore are my favorite acceptable food is be hot cross bun'
如果还是不行,先关掉你的程序,重新打开运行。或者试下以下方法。
r.recognize_google(audio,show_all=True)
输出:
{'alternative': [{'transcript': 'the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle taste fine with ham tacos al Pastore are my favorite acceptable food is be hot cross bun',
'confidence': 0.74890465},
{'transcript': 'the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle taste fine with ham tacos al Pastore are my favorite a vegetable food is be hot cross bun'},
{'transcript': 'the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores Health invest a salt pickle taste fine with ham tacos al Pastore are my favorite acceptable food is be hot cross bun'},
{'transcript': 'the stale smell of old beer lingers it takes heat to bring out the Oder a cold dip restores health and zest a salt pickle taste fine with ham tacos al Pastore are my favorite a vegetable food is be hot cross bun'},
{'transcript': 'the stale smell of old beer lingers it takes heat to bring out the odor a cold dip restores health and zest a salt pickle tastes fine with ham tacos al Pastore are my favorite acceptable food is be hot cross bun'}],
'final': True}
可以看到,recognition_google()返回了一个关键字为 ‘alternative’ 的列表,指的是所有可能的响应列表,即你所识别的音频全部可能输出。