def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 0.8
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-in')
print("User said: {} \n".format(query))
except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return query
以上代码未从麦克风获取声音
只需使用conda install来安装pyaudio,它的作用相同。