如何在 Python 中使用麦克风获取语音输入
python 621
原文标题 :How to get voice input with microphone in Python
将 Speech_recognition 导入为 sr
r = sr.Recognizerwith sr.Microphone() 作为源:
r.adjust_for_ambient_noise(source, duration=1)
print ("Listening...)
audio = r.listen(source)
try:
text = r.recognize_google(audio)
except:
print ("sorry"
回复
我来回复-
Hugh Bollen 评论
您需要更具体地了解您的用例。你考虑过pyaudio或sound设备吗?两者看起来都是用 Python 处理音频的可行库
2年前 -
nemesis 评论
使用谷歌语音识别,
import speech_recognition as sr print(sr.__version__) # just to print the version not required r = sr.Recognizer() my_mic = sr.Microphone(device_index=1) #my device index is 1, you have to put your device index with my_mic as source: print("Say now!!!!") r.adjust_for_ambient_noise(source) #reduce noise audio = r.listen(source) #take voice input from the microphone print(r.recognize_google(audio)) #to print voice into text
2年前