python - 语音识别未知值错误
问题描述
我已经在 python shell 3.5.8 上试过了
import speech_recognition as sr
import webbrowser as wb
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe
%s'
# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Please wait. Calibrating microphone...")
# listen for 5 seconds and create the ambient noise energy level
r.adjust_for_ambient_noise(source, duration=5)
print("Say something!")
audio = r.listen(source)
# recognize speech
try:
text = r.recognize_google(audio)
print("I thinks you said '" + r.recognize_google(audio) + "'")
f_text='https://www.google.co.in/search?q=' + text
wb.get(chrome_path).open(f_text)
#except sr.UnknownValueError:
# print("I could not understand audio")
except sr.RequestError as e:
print("error; {0}".format(e))
except Exception as e:
print (e)
File "C:\Users\manoj\AppData\Local\Programs\Python\Python35\lib\site-
packages\speech_recognition\__init__.py", line 858, in recognize_google
if not isinstance(actual_result, dict) or
len(actual_result.get("alternative", [])) == 0: raise UnknownValueError()
speech_recognition.UnknownValueError
解决方案
试试这个
try:
text = r.recognize_google(audio, language = 'en-IN', show_all = True )
print("I thinks you said '" + r.recognize_google(audio) + "'")
f_text='https://www.google.co.in/search?q=' + text
wb.get(chrome_path).open(f_text)
我认为这是由于噪声中断算法而发生的。由于噪音,它给出了 UnknownValueError
推荐阅读
- python-3.x - 如何将字符串中的列表变为 Python 中的真实列表?
- php - 如何阻止 WordPress 插入帖子创建重复的帖子
- amazon-web-services - 如何使用 AWS Lambda 函数访问启用了 VPC 的 Elasticsearch
- mysql - 无法连接到在 WSL 中运行的 mysql
- python - Pyspark:之前已经购买的产品的标志
- django - 根据 URL 切换 django 缓存后端
- powershell - 为什么转换后的批处理没有运行我的 powershell 脚本?
- sql-server - 在 MSSQL 中,如何检查列的值是否是另一列的子字符串?
- facebook-graph-api - 无法使用 Graph API 在 Facebook 页面上发帖
- next.js - Nextjs 使用纱线工作空间生成嵌套的 node_modules 文件夹