I would like to do on-board speech processing (Matching of a pre-recorded voice sample [1/2 secs] with a continuously playing sound) with a Pi 3.

The Pi should give a real-time response to the trigger word, performing a certain task.

I am here for some suggestions as to whether I would require to port an RTOS onto the Pi. (If yes, which would be the most suitable RTOS for this). Or what methodology can be employed to enable such a triggering mechanism?

1 Answer 1


You are going to need an internet connection, an OS, (I suggest Raspbian) and a microphone.

The first step is to get the microphone set-up. Start by opening a terminal window and running lusb. This lists all of the USB devices connected to the Pi and the microphone should show up.

Next the volume for the mic needs to be set to high, so run alsamixer. You will see a GUI interface pop-up, select your mic by pressing F6 and choosing it from the list. Use the up arrow key to increase the volume. (You can always go back and change the volume at a later date by following this set of insturctions again).

With the mic set-up we are going to need some voice recognition software, I'm going to outline the steps to install some software that uses Google's API. So, it should be fairly accurate.

wget --no-check-certificate “https://doc-0c-2o-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/icp2b3rhg6kd6a8prrnb26rt0nk03vme/1496138400000/08464976839983055227/*/0B0nujpNS8bIxUFJpWXIzd19CXzg?e=download” -O PiAUISuite.tar.gz
tar -xvzf PiAUISuite.tar.gz
cd PiAUISuite/Install/
sudo ./InstallAUISuite.sh

The commands above need to run one after the other in that order. (Don't start the next one running until the one before it has finished).

There are lots of different options during the installation process. For more information on those see here.

The software is set continuously running, if the following command is executed:

sudo voicecommand -c

The keyword for activating it is Pi, I suggest changing it to something more distinct as Pi sounds very similar to hi. To fix this run:

voicecommand -e

You will see an option in there for changing the keyword.

There are some voice commands in the file by default, you can however add your own:

Check internet==ping google.com

The section of code before the == is the voice command, the section of code after the == is the action the Pi will perform upon hearing the voice command. In the example above saying check internet will cause the Pi to ping google.com.

This is the bit where you can get really creative and setup different commands for various voice commands.

Edit 1:

Running voicecommand -e or sudo voicecommand -e might give an empty file. In which case edit the file so it contains the following:

#This is the default config file
#These are the special options you can set (remove the #)
#!response==Yes Sir?
#Here are the commands:
Check internet==ping google.com

Below #here are the commands: I have included an example voice command, you can add your own voice commands below the example one.

Edit 2:

The method I listed above is just one way of implementing voice control. For Python there is the SpeakPython library. The person who created has confirmed that it works well on the Pi.

Alternatively there is the SpeechRecognition library which was developed by Python. You can find lots of example pieces of code and tutorials on the site I have linked above. However, I'll post one of the example pieces of code here just to give you an idea:

#!/usr/bin/env python3

# NOTE: this example requires PyAudio because it uses the Microphone class

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

# recognize speech using Sphinx
    print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

# recognize speech using Google Speech Recognition
    # for testing purposes, we're just using the default API key
    # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
    # instead of `r.recognize_google(audio)`
    print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
except sr.UnknownValueError:
    print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
    print("Could not request results from Google Speech Recognition service; {0}".format(e))
  • Is should point out the hyperlink: "doc-0c-2o-docs.googleusercontent.com/docs/securesc/…*/0B0nujpNS8bIxUFJpWXIzd19CXzg?e=download" . Is exactly the same as this shortened hyperlink: goo.gl/KrwrBa . I couldn't post the shortened hyperlink in my answer as the system does not permit it. I've checked and both links work, so feel free to use the shorter one when running the command its used in.
    – Darth Vader
    May 30, 2017 at 11:35
  • thanks for such an elaborative reply to my question. I just wanted to know that why didn't you go for a RTOS, I mean there are other background tasks that would be going on whilst anytime the trigger keyword can be heard which may have to pre-empt the currently running task. Is Raspbian capable of such quick processing? Second, I cannot change the .commands.conf as it says I have no privileges and when I open it using sudo, the file is empty. Did you face any such situation?
    – Ashish K
    May 30, 2017 at 12:09
  • Raspbian should be ok for the task, the main thing is the OS is heavily supported and a lot of tutorials for various things are based around it. Background tasks can always be disabled, and you can remove unnecessary software anyway. I'm not sure what you mean by the .commands.conf file as this doesn't feature anywhere in the instructions. Could you clarify what stage in the process you have got to?
    – Darth Vader
    May 30, 2017 at 12:36
  • .commands.conf is the config file for the Software which keeps a track of the voice commands, keywords, etc. And I have overcome with the "privilege error" I asked you about. But the thing is I would like to know whether I can go through some reading that involve developing own scripts doing the same?
    – Ashish K
    May 30, 2017 at 13:03
  • I'm assuming you have followed the instructions in my answer above in which case I can edit a basic configuration of the file into my answer for you.
    – Darth Vader
    May 30, 2017 at 13:08

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.