Skip to content

Speech Recognition

David Salek edited this page Dec 11, 2017 · 22 revisions

There are many options to add speech recognition to your Raspberry Pi project. The list below represents a few options that I found using API's requiring an internet connection.

From privacy concerns, I prefer solutions that run on a Raspberry Pi directly. I tried using Jasper, a modular open source platform that I did not find optimal for this project, and Judy which I prefer for its simplicity.


Jasper

Jasper is an open source platform for developing always-on, voice-controlled applications.

http://jasperproject.github.io/

Jasper is modular and supports a wide range of speech-to-text and text-to-speech engines.

The installation of Jasper requires a lot of time and I describe it in a separate wiki here: https://github.com/salekd/rpizero_relay/wiki/Install-Jasper

I used Jasper in the following way:

  • Copy Light.py into the client/modules/ directory in jasper-client.
  • You will likely get frequent errors like this: IOError: [Errno Input overflowed] -9981. The easiest way to solve this is to try-except blocks everywhere around data = stream.read(CHUNK) in client/mic.py
  • Start listening: python jasper.py --debug

In the end, I do not think Jasper is the right choice for this project. There is simply no need for the flexibility that Jasper offers. Before finding an optimal configuration and modifying its code further in order to get satisfactory results, I moved to a simpler solution using Judy.


Judy

Judy is a simplified sister of Jasper, with a focus on education.

https://github.com/nickoala/judy

Unlike Jasper, Judy does not try to be cross-platform, does not allow you to pick your favourite speech-to-text engine or text-to-speech engine, does not come with an API for pluggable modules. Judy tries to keep things simple, lets you experience the joy of voice control with as little hassle as possible.

Judy uses PocketSphinx as the speech-to-text engine and Pico as the text-to-speech engine.

Judy requires PocketSphinx to be installed and can be obtained with pip.

sudo apt-get install pocketsphinx
sudo pip install jasper-judy

The git repository mentioned above comes with a lexical and language modelling files that are not suitable for a home automation project. The website below can be used to generate such files directly tailored to your project.

http://www.speech.cs.cmu.edu/tools/lmtool-new.html

I uploaded a text file containing the following words:

Judy
light
on
off

and got these corresponding lexical and language modelling files: https://github.com/salekd/rpizero_relay/blob/master/TAR7369.tgz

Extract the files into your working directory and let Judy listen to what you say. Remember, you have to call "Judy" to get her attention. After that try saying "light on" or "light off", it works well!

python judy_light.py

You can also run this automatically on startup. Add the following line in /etc/rc.local before exit 0

python /home/pi/rpizero_relay/judy_light.py &

The standard output can be viewed like this, where pid corresponds to the pocketsphinx_continuous process:

tail -f /proc/<pid>/fd/1

Beep

The way to use Judy is the following:

  • call Judy by name
  • wait for a beep sound
  • say what you want
  • wait for a beep sound
  • see the result

This assumes that your device has a sound output because Judy uses aplay to play the beep sound. However, Raspberry Pi Zero cannot play any sound directly. I solved this by connecting a buzzer to one of the GPIO pins and writing a simple python script to make a beep sound through controlling the GPIO pin. This script is called in my local copy of Judy, see the modification in judy.py below.

@@ -63,7 +63,8 @@ class VoiceOut(object):

     def beep(self, high):
         f = self._resources['beep_hi' if high else 'beep_lo']
-        self.play(f)
+        #self.play(f)
+        subprocess.call(['/usr/bin/python2.7', '/home/pi/rpizero_relay/beep.py'])

In case you prefer quiet signals, an LED can be connected instead. The python script remains the same.

Make sure the local copy of Judy is known in /etc/rc.local

export PYTHONPATH=/home/pi/judy
/usr/bin/python /home/pi/rpizero_relay/judy_light.py &
Clone this wiki locally