python-语音识别

在做语音识别时,我们需要调用recognize_google()函数来识别我们的音频数据,但是却出现了以下错误:

r.recognize_google(audio)

RequestError: recognition connection failed: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

方法一:在你安装的speech_recognition包里(位置大概的这样的,\Lib\site-packages\speech_recognition)。找到包位置,并打开__init__.py文件,找到以下位置,把.com 改成 .cn 重新运行一下:(得到了我的音频文件的内容)

'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'

如果还是不行,先关掉你的程序,重新打开运行。或者试下以下方法。

方法二通过把 recognition_google()中 True 参数改成 show_all 来给出完整响应。 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’ 的列表,指的是所有可能的响应列表,即你所识别的音频全部可能输出。

参考链接

评论可见,请评论后查看内容,谢谢!!!评论后请刷新页面。