Open Elnur01 opened 3 years ago
Try increasing the recognizer_instance.energy_threshold. In a loud environment, this helps. The microphone must be picking up small noises hence taking a long time to respond. More info in the Troubleshooting section of the library.
Adding r.adjust_for_ambient_noise(source)
before r.listen()
will auto adjust to the environment.
When I run my code it starts to listen me. Okay, this part is good. But it took too long. I often wait for 5 minutes.
def takeCommand():
r=sr.Recognizer()
with sr.Microphone() as source:
print('LISTENING')
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing")
statement = r.recognize_google(audio, Language='en-in')
print(f"User said: {statement}\n")
except Exception as e:
return statement
OR
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)
try:
print("Recognizing...")
statement = r.recognize_google(audio, language='en-US')
print(f"user said:{statement}\n")
except Exception as e:
print(e)
speak("Pardon me, Please say that again")
return takeCommand()
Expected behavior Recognize my audio much faster.
(What did you expect to happen?)
Actual behavior For recognizing my voice I wait for 3-5 minutes.
System information
My system is Windows 10
My Python version is Python 3.9.1
My pip version is pip 21.1.1
My SpeechRecognition library version is 3.8.1
My PyAudio library version is 0.2.11
My microphones are ['Microsoft Sound Mapper - Input', 'Microphone (2- High Definition ', 'Microsoft Sound Mapper - Output', 'Speakers (2- High Definition Au', 'Primary Sound Capture Driver', 'Microphone (2- High Definition Audio Device)', 'Primary Sound Driver', 'Speakers (2- High Definition Audio Device)', 'Speakers (2- High Definition Audio Device)', 'Microphone (2- High Definition Audio Device)', 'Speakers (HD Audio Headphone/Speakers)', 'Microphone (HD Audio Microphone)']
I don't know installed PocketSphinx