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

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.

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

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.

One Comment

  1. Hey there! I realize this is somewhat off-topic however I
    needed to ask. Does running a well-established blog such
    as yours require a large amount of work? I am completely new to writing a blog but I do write in my journal
    every day. I’d like to start a blog so I can share my experience and
    feelings online. Please let me know if you have any kind of recommendations
    or tips for brand new aspiring bloggers. Thankyou!


Time limit is exhausted. Please reload CAPTCHA.