Python – Set up the problem of Snowboy hot word detection in conjunction with the python SpeechRecognition library

Set up the problem of Snowboy hot word detection in conjunction with the python SpeechRecognition library… here is a solution to the problem.

Set up the problem of Snowboy hot word detection in conjunction with the python SpeechRecognition library

I want to use both the Snowboy hot word detection library and the SpeechRecognition library in my python project. However, I’ve encountered a lot of different mistakes when trying to get the two to live in harmony.

Initially, I set it to Snowboy’s callback function that would launch SpeechRecognition’s monitor function to receive audio after a hot word was detected. However, both libraries appear to lock down access to the microphone when their respective instances are created. Therefore, this code throws an error from PyAudio indicating that SpeechRecognition is trying to access a microphone that is already in use by (Snowboy).

I tried several ways to fix this, including using multithreading/multiprocessing and deleting each microphone instance as soon as they were done, and then recreating them when they were needed again (very ugly). I didn’t get any luck with any of these workarounds, though.

My most recent attempt was to use SpeechRecognition’s built-in Snowboy buzzword implementation. I knew about this feature for a long time, but avoided it until now because I prefer to be able to control what happens between hot word detection and STT translation. Doing so got me to solve the problem of sharing the microphone between the two libraries, but now the hotword model I trained from Snowboy’s website doesn’t seem to work at all. I tried creating different models with different microphones and adjusting sensitivity settings, but to no avail.

At this point, I’m considering reconsidering the idea of removing/recreating the microphone instance to go back to using Snowboy’s library for hotword detection instead of the built-in implementation in SpeechRecognition, as I feel that the difference between the two approaches is enough to cause my current problem with the model. Before switching the implementation of SpeechRecognition, hot word detection worked much better.

There are a few points to note:

  • Runs on a Raspberry Pi 3 B+ with Raspbian
  • Can find my current codehere
  • The Snowboy library is copied directly to the repository. Its implementation can be found here
  • SpeechRecognition implementation where you can find Snowboy buzzwords here

If anyone wants to see logs, error output, etc., please let me know.

Thanks for all the help.

Solution

For anyone who might be experiencing the same or similar issue, I found a solution. All the methods I tried didn’t work in the end, but I found that the feature I was looking for was already built into the Snowboy library. However, pre-built binaries that can be downloaded directly are obsolete and do not yet have this feature. So, to get the features I described, you have to follow the instructions in Snowboy’s GitHub repository to complete the process of compiling your own custom binaries.

Making this change immediately solved the problem I was experiencing, allowing me to continue with my project.

Hopefully this helps others who might be stuck on this issue.

Related Problems and Solutions