You will of course need a USB microphone in order for the Pi to hear you speak. You can buy a USB adaptor for a standard 3.5mm mic but I went with the SunFounder USB 2.0 Mini Microphone for Raspberry Pi 3, 2 Module B & RPi 1 Model B+/B (figure 1).
Figure 1. SunFounder USB 2.0 Mini Microphone
This is where a Raspberry Pi 3 may be a better choice. With built in WiFi you have an extra free USB port.
Pi AUI Suite
For the voice recognition package our first test was using Steven Hickson's Pi AUI Suite. The thing we like best about this software is the ability to create your own word lists and associated actions. The suite is up to version 3 and you can read about it on Steve's blog. The one caveat is that it appears that the suite is no longer being developed or supported. In particular text to speech (i.e. when the Raspberry Pi responds to a command) appears to be problematic. We will develop an alternative approach to get around this.
A quick summary of Pi AUI Suite. The configuration is done in the commands.conf file (more on this later).
- The format is voice==command (where voice is the word which AUI Suite looks for)
- You can use any character except for newlines or ==
- If the voice starts with ~, the program looks for the keyword anywhere. Ex: ~weather would pick up on "weather" or "what's the weather"
- You can use ... at the end of the command to specify that everything after the given keyword should be options to the command. For example: play==playvideo ... This means that if you say "play Futurama", it will run the command playvideo Futurama
- You can use $# (where # is any number 1 to 9) to represent a variable. These should go in order from 1 to 9. For example: $1 season $2 episode $3==playvideo -s $2 -e $3 $1 This means if you say "game of thrones season 1 episode 2", it will run playvideo with the -s flag as 1, the -e flag as 2, and the main argument as game of thrones, i.e. playvideo -s 1 -e 2 game of thrones
- Because of these options, it is important that the arguments range from most strict to least strict.
- This means that ~ arguments should probably be at the end.
- You can also put comments if the line starts with # and special options if the line starts with a !
- Default options are shown as follows:
- !filler==FILLER FILL,
- !response==Yes Sir?,
- !improper==Received improper command:,
- Keyword, filler, and response accept strings. verify, continuous, quiet, and ignore except 1 or 0 (true or false respectively). thresh excepts a floating point number. These allow you to set some of the flags as permanent options (If these are set, you can overwrite them with the flag options).
- You can set a WolframAlpha API and maxResponse (the number of branches) like !api==XXXXXX-XXXXXXXXXX amd !maxResponse==3
- You can now customise the language support for speech recognition and some text to speech with the language flag. Look up your country code and use that. Ex. For US: !language==en_us, for Spain !language==es, for Germany !language==de.
Installing Pi AUI Suite
The install process is fairly straight forward. Start by installing the dependencies. Open up Terminal or connect via SSH and type the following (all on one line):
sudo apt-get install -y libboost-dev libboost-regex-dev youtube-dl axel curl xterm libcurl4-gnutls-dev mpg123 flac sox
Then download the install files:
git clone https://github.com/StevenHickson/PiAUISuite.git
Change to the install directory:
Run the install command:
Choose y to install any dependencies required and work your way through the installation wizard. If you encounter an error during this process (I did) then install the Boost C++ library:
sudo apt-get install libboost-regex1.49.0
After this library has installed, Run sudo ./InstallAUISuite.sh again.
Alternate Text to Speech Solution
After running the install wizard you can use the setup wizard to generate your command configuration file. To run the setup wizard:
sudo voicecommand -s
As part of this process you have the option to test text to speech (TTS). This appears to be no longer working. The Pi AUI Suite is using the Google TTS API and in early 2016 Google stopped letting automated scripts access the service. You can read about this issue on the Pi AUI Suite GitHub repository.
One workaround is to install the speech synthesis software called Festival:
sudo apt-get install festival
You can test that this is working by typing the following:
echo "Test message" | festival --tts
You will obviously need to have some speakers plugged into the 3.5mm audio out plug. You can adjust the volume using:
Then use the up and down arrows to adjust volume. ESC to save and exit.
Configuring Pi AUI Suite
You can run voicecommand using the default configuration options detailed above, but you will probably want to tweak the available commands. The first thing we need to do is move the configuration file because we are running the program as the root user. To do this type:
sudo mv /home/pi/.commands.conf /root/.commands.conf
To edit the configuration file:
sudo voicecommand -e
or if you prefer using your choice of text editor you can type something like:
sudo nano /root/.commands.conf
You can now change your keyword or add extra commands. For example, if you want the Raspberry Pi to tell you the current time, you could add:
time==echo "The time is " | festival --tts && date | festival --tts
CTRL X to exit, select y to save and then return.
Running Pi AUI Suite
To run voice command:
sudo voicecommand -c
The program will then listen out for your keyword and attempt to respond.
In the next post we will evaluate performance of Pi AUI Suite and look at alternatives.