麦克风不收听
Microphone is not Listening
我制作了一个 Python 程序,你可以说是人工智能。
但是当我 运行 它时,它显示 Listening 但不听我说
我用其他应用程序检查我的麦克风它工作正常但它不工作
在我的代码中。代码如下:-
import pyttsx3
import speech_recognition as sr
import datetime
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("Hey Sir.")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(r, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
wishMe()
takeCommand()
告诉我解决方案它听我说或者可能是代码错误。
假设:
我根据您的评论做出假设,即 "nothing" 您的意思是您的代码堆叠在 return "None"
行上,这确实是真的:
yes stucked at listenig and do nothing
✔️ 解决方案:
所以 我试着调试你的代码,我发现它在第 37
行抛出一个异常,它说 ``audio_data`` must be audio data
,要修复它只需更改:
query = r.recognize_google(r, language='en-in')
与:
query = r.recognize_google(audio, language='en-in')
它可能也适合你 :) .
我制作了一个 Python 程序,你可以说是人工智能。 但是当我 运行 它时,它显示 Listening 但不听我说 我用其他应用程序检查我的麦克风它工作正常但它不工作 在我的代码中。代码如下:-
import pyttsx3
import speech_recognition as sr
import datetime
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("Hey Sir.")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(r, language='en-in')
print(f"User said: {query}\n")
except Exception as e:
print("Say that again please...")
return "None"
return query
if __name__ == "__main__":
wishMe()
takeCommand()
告诉我解决方案它听我说或者可能是代码错误。
假设:
我根据您的评论做出假设,即 "nothing" 您的意思是您的代码堆叠在 return "None"
行上,这确实是真的:
yes stucked at listenig and do nothing
✔️ 解决方案:
所以 我试着调试你的代码,我发现它在第 37
行抛出一个异常,它说 ``audio_data`` must be audio data
,要修复它只需更改:
query = r.recognize_google(r, language='en-in')
与:
query = r.recognize_google(audio, language='en-in')
它可能也适合你 :) .