Jasper Modules, Part 1: Camera

Writing Jasper modules isn’t exactly fun. Jasper is an open-source interface for many speech-to-text and text-to-speech engines. It also provides a conversation interface. Jasper modules can be standard – which wait for the user to initiate contact – or notification – meaning they monitor a stream and report back every now and then. For instance, I just wrote a module for capturing photos on request, which means a standard module.

When I started, I wasn’t exactly fresh on my Python, but the past 8 hours have more than re-educated me.

After poking around on the internet, I found that taking a still image from a USB webcam and saving it to a file isn’t too difficult. In bash, all you have to do is

fswebcam <file>

And Python can run shell scripts with subprocess.call. The method I found for screenshots was just as easy:

scrot <file>

Those capture methods make video capture look like a walk in the park by comparison. First, you need to know when to start and stop the video recording. Second, you need to know what command to run. After several false starts I found

avconv <file>

I decided to run that command in a separate thread, and when the user says something like “STOP RECORDING”,

killall avconv

Which will force the avconv process to close. However, before closing, avconv saves the recorded file. Then I found a problem: when parallel-threading avconv and Jasper, the TTS audio becomes spottily modulated.

While writing this, I encountered a number of errors–mostly with finding the right libraries–but I had a bit of help:

Image credit Bruce Sterling

The folks over at StackExchange are life-savers.

The Jasper modules will be available on the Download page.

Leave a Reply