Uberi / speech_recognition

Speech recognition module for Python, supporting several engines and APIs, online and offline.
https://pypi.python.org/pypi/SpeechRecognition/
BSD 3-Clause "New" or "Revised" License
8.3k stars 2.39k forks source link

Script stuck on hotword detection #398

Open furqanahmedmtbc opened 5 years ago

furqanahmedmtbc commented 5 years ago

Steps to reproduce

I try to run the following script but it seems it is stuck on wake-word detection. I have spoken multiple times but the script does not seem to recognize the wake-word. (Note: The recognition works fine without the wake-word part, It just seems like the addition of wakeword requirement is not working.)

I'm using the Google cloud Speech API on a Raspberry Pi 3.

Code:

pmdl = ['/home/pi/AoD_Final/V4/Squeak.pmdl']
sbLoc = '/home/pi/AoD_Final/V4/'
sbCfg = (sbLoc,pmdl)

print(sbCfg)

# use the audio file as the audio source
mic = sr.Microphone(device_index=3)
r = sr.Recognizer()

print("A moment of silence, please...")
with mic as source:
    r.adjust_for_ambient_noise(source)
    print("Set minimum energy threshold to {}".format(r.energy_threshold))

with mic as source:
    r.adjust_for_ambient_noise(source)
    #r.snowboy_wait_for_hot_word(source, "/AoD_Final/V4", "Squeak.pmdl", source, timeout=None)
    audio = r.listen(source,snowboy_configuration=("/home/pi/AoD_Final/V4",["/home/pi/AoD_Final/V4/Squeak.pmdl"]))
    #audio = r.listen(source,snowboy_configuration=sbCfg)
    #audio = r.listen(source)

-------------------------Output-------------------------------------------------------------------


attempt to connect to server failed
A moment of silence, please...
Set minimum energy threshold to 817.50242197
^CTraceback (most recent call last):
  File "with_listen.py", line 31, in <module>
    audio = r.listen(source,snowboy_configuration=("/home/pi/AoD_Final/V4",["/home/pi/AoD_Final/V4/Squeak.pmdl"]))
  File "/home/pi/.local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 638, in listen
    buffer, delta_time = self.snowboy_wait_for_hot_word(snowboy_location, snowboy_hot_word_files, source, timeout)
  File "/home/pi/.local/lib/python2.7/site-packages/speech_recognition/__init__.py", line 573, in snowboy_wait_for_hot_word
    snowboy_result = detector.RunDetection(b"".join(resampled_frames))
  File "/home/pi/AoD_Final/V4/snowboydetect.py", line 111, in RunDetection
    return _snowboydetect.SnowboyDetect_RunDetection(self, *args)
KeyboardInterrupt
furqanahmedmtbc commented 5 years ago

I did some digging around. Looks like the scrip is stuck on snowboy_result = detector.RunDetection(b"".join(resampled_frames)) in the speech recognition init file. The "_snowboyresult" value remains 0 even after speaking into the mic multiple times. The hotword is supposed to be detected when this value goes above 0. Any idea how I can solve this issue?

achen88 commented 2 years ago

https://github.com/Uberi/speech_recognition/issues/329