Tested on:Raspberry Pi 2, Raspbian pre Jessie, Python 2.7
Prerequisites:Ultrasonic range detection with the Raspberry Pi
Jasper: manual installation on Raspbian Wheezy
0

Raspberry Pi and Jasper : a custom voice command for measuring the distance

This tutorial shows how to build a voice controlled ultrasonic range detection based on Jasper running on a Raspberry Pi and is meant to be a demonstration of building custom Jasper voice commands after having completed the Jasper installation, for example with the manual installation tutorial. The voice recognition with the default engine PocketSphinx from the manual installation is pretty weak, so this tutorial just shows how to setup a pretty simple voice command.

Installation
First, follow the Jasper and ultrasonic detection installation instructions from the prerequisites and then these short instructions on how to install PiGPIO for sudoless GPIO access.
Download the example script with

All voice commands have to be stored in ~/jasper/client/modules/. Now, start Jasper as usual with

When Jasper welcomed you, say Jasper, wait for the beep and then say What. Jasper will read out the distance to an object measured with the ultrasonic sensor.

A custom Jasper voice recognition module
The module What.py uses Speech-To-Text (STT) recognition as well as Text-To-Speech (TTS) translation and has to have the following constants and functions defined for being a working jasper voice recognition module.
Pretty much at the top of What.py, the word to recognize is defined:

Add more words seperated by a comma and in quotation marks. Before, make sure Jasper understands all words in the list.
In this function, the transcribed text (STT) is searched for the word:

The function handle is the action which is triggered by the recognition of the voice command:

distance is measured with the ultrasonic sensor (see tutorial in prerequisites) in the function measure_distance(). Jasper then outputs the result (TTS) with mic.say().

The complete script
Click on Full Script to show all of the code.

Jasper in Action

Links
voice control with Jasper: http://www.knight-of-pi.org/jasper-manual-installation-on-a-raspberry-pi-2-and-raspbian-jessie
PiGPIO installation and usage: http://www.knight-of-pi.org/pigpio-for-sudo-less-gpio-before-raspbian-jessie/

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.

Comment

Time limit is exhausted. Please reload CAPTCHA.