python - 为语音识别库启用音频输入
问题描述
如何使用语音识别库为所有设备索引打开音频输入?由于我想传递音频进行测试,并且库可能使用不同的音频输入设备。如何让它从所有索引中获取音频输入?
解决方案
您可以将麦克风用作默认音频输入设备,下面是代码片段:
import speech_recognition as sr
r=sr.Recognizer() # this is a recognizer which recognize our voice3
with sr.Microphone() as source: # in this we are using a microphone to record our voicecmd
speak.speak("What can i do for you!") # this a speak invoke method w3hich ask us something
print("Ask me Something!") # this a print statement which come on console to ask something
audio=r.listen(source,timeout=60,phrase_time_limit=3)
data = ""
try:
"""
this is a try block it will recognize it our voice and say what we have told
"""
data= r.recognize_google(audio,language="en-US")
print("dynamo think you said!" + " "+data) # this will print on your console what will going to recognize by google apis
except:
"""
this is a except block which except the error which come in try block and the code is not able to run it will pass a value
"""
print("not able to listen you or your microphone is not good")
exit()
推荐阅读
- python - OpenAI健身房cartpole-v0理解观察和动作关系
- r - 映射矩阵 R
- android - 为什么会出现此错误:在调用超类型构造函数之前无法引用“ViewHolder.itemView”
- android - 如何在 Android Studio 中对裁剪图像进行实时图像处理
- android - 无法修改 HERE Maps 重新路由路线选项
- android - Android - 如何在 RecyclerView 中更新自定义列表项单个组件?
- c++ - 如果我不关闭 ifstream 会导致内存泄漏吗?
- preg-match - 我想使用 preg_match() 函数添加阿拉伯字符
- plot - 如何创建分解数据到类别的图表?
- react-native - react-native响应错误代码500