New to Raspberry Pi - I want to create a device which upon hearing a particular word it will activate/deactivate something. E.g. if I say the word "light", it will turn on/off an LED light. The device will only recognize this one and only word that I program it with. Hoping to use it at home which might have some background noise.

The key part that I'm not sure how to implement is the voice recognition. Would open-source libraries like mycroft and jasper help with this, or is there any other solution? If I were to use it in a home setting with various background noises is rnnnoise the state-of-the-art noise cancelling technique or are the open-source packages enough?

Edit: Sorry I should've specified, I want this device to be disconnected from the internet, so using Alexa / Google would be off the table.

  • how will the device know that you are giving it a command?
    – jsotola
    Sep 27, 2018 at 5:55

2 Answers 2


I think the next links can help you:



It explains how to implement voice recognition with the help of Google Voice Commands.

About background noises, I have experimented at work the Google solutions, and it's really a big issue... When your commands can be delayed, you can filter the noises like explained here (https://www.techsmith.com/blog/not-late-reduce-audio-noise-recordings-free/) but sure , it's not easy :)

  • You should include the important content in your answer, so that it remains useful even if the links are gone. Sep 27, 2018 at 13:41
  • Hello @DmitryGrigoryev, I have a similar project forcasted. As you sugest, I will prepare a full reply so, effectively, if the links are gone, nothing will be lost :) Oct 3, 2018 at 12:06

Installation of latest Pocketsphinx 5prealpha

Install ALSA and other sound card utilities

sudo apt-get install alsa-utils bison libasound2-dev -y

Install Sphinx-base

wget https://sourceforge.net/projects/cmusphinx/files/sphinxbase/5prealpha/sphinxbase-5prealpha.tar.gz/download -O sphinxbase.tar.gz
tar -xzvf sphinxbase.tar.gz
cd sphinxbase-5prealpha
./configure --enable-fixed
make clean all
sudo make install

Install Pocketsphinx

wget https://sourceforge.net/projects/cmusphinx/files/pocketsphinx/5prealpha/pocketsphinx-5prealpha.tar.gz/download -O pocketsphinx.tar.gz
tar -xzvf pocketsphinx.tar.gz
cd ..
cd pocketsphinx-5prealpha
sudo make install
export LD_LIBRARY_PATH=/usr/local/lib 
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

Testing in the terminal

pocketsphinx_continuous -inmic yes

Example code

from pocketsphinx import LiveSpeech

trigger = "hey chloe"
speech = LiveSpeech(lm=False, keyphrase='forward', kws_threshold=1e+20)

for phrase in speech:
    tts = phrase.segments(detailed=True)
    if tts == trigger:
       triggered = True

    while triggered==True:
        tts = phrase.segments(detailed=True)
        if tts == "light on" or tts == "lights on":
        # turn lights on here
            triggered = False
        elif saying == "light off" or saying == "lights off":
        # turn light off here
            triggered = False

Documentation for setup of CMUSphinx

  • What are Sphinx-base and Pocketsphinx? Can you please elaborate a bit? Where do you get it? With apt list sphinxbase pocketsphinx I get pocketsphinx being in the default Raspbian repository. Why do you suggest to compile everything from source and not just install it from the repository?
    – Ingo
    Sep 23, 2019 at 9:57
  • Just a simple pip install pocketsphinx should be used for regular Windows,Linux, or Mac os. Sphinx-base is for other modules and Pocketsphinx to get it to work. Pocketsphinx is a lightweight speech-recognition engine for small devices.
    – Daniel
    Sep 23, 2019 at 13:29
  • 1
    Please edit your answer and add the information there. But you still not answered why not to use pocketsphinx from the repository. Just doing a sudo apt install pocketsphinx should do the thing and you have a configured installation out of the box.
    – Ingo
    Sep 23, 2019 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.