使用recognize_google() 出现 RequestError: recognition connection failed: [WinError 10060] 由于连接方在一段时间后没有

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’ 的列表,指的是所有可能的响应列表,即你所识别的音频全部可能输出。

  • 13
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小小_喻

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值