Close

Does this project spark your interest?

Become a member to follow this project and don't miss any updates

Demolition Man Verbal Morality Statute Monitor

Project to build a working swear detector to enforce the verbal morality statute from the movie Demolition Man.

19 71 86
Enjoy this project?
Share on twitter   Share on Facebook

This project was created on 03/18/2014 and last updated 3 months ago.

Description
See this compilation of scenes with the 'verbal morality statute monitor' from Demolition Man: https://www.youtube.com/watch?v=LE3oczJ1zgM

The goal of this project is to replicate the functionality of the Demolition Man device as much as possible using continuous speech recognition and keyword spotting algorithms running on a small embedded platform (Raspberry Pi or Beaglebone Black).
Details

This project is inspired by the movie Demolition Man and the future society it envisions.  The movie is set in the 2030's when crime has been completely eradicated inside a tightly controlled society.  Swearing is a violation of the 'verbal morality statues' and its enforcement is done through monitoring devices mounted in each room.  These verbal morality statute monitors are a running joke in the movie as characters use profanity and trigger violations.  This project is an attempt to recreate the verbal morality statute monitor from Demolition Man.

For hardware, this project uses a Raspberry Pi model B running the latest version of the Raspbian OS.  The model B Pi is preferred because it has multiple USB ports (good for connecting both a wifi chip, and USB microphone), however the project will likely also work on a model A Pi.  Connected to the Raspberry Pi are a USB microphone, amplifier and speaker, thermal printer, a SPST toggle switch, and some red LEDs.

For software, the project source code is available on github here.  Make sure to install the following dependencies using apt-get by executing:

sudo apt-get install build-essential autoconf libtool automake bison swig python-dev libasound2-dev gcc-4.7 g++-4.7 libasound2-dev

The swear detection is done using the PocketSphinx library, an excellent open source speech recognition engine.  The in development next version of PocketSphinx has support for keyword spotting, which is the detection of certain keywords being uttered in everyday speech.  You will need to download the subversion trunk of the library, compile, and install the SphinxBase and PocketSphinx subprojects on the Pi.  You will also need to install the wiringPi library which is used to access GPIO pins on the Pi.

To compile the project, invoke 'make DemoManMonitor'.  You can also invoke 'make runtests' to run a few unit tests for the code.  Once the code is compiled you will need to make sure you have some speech model data available in the project directory.  Create a folder called 'models' and copy in the appropriate models for your language from PocketSphinx's pocketsphinx\model directory.  I copied in the hmm/en_US/hub4wsj_sc_8k folder,  lm/en_US/cmu07a.dic, and lm/en_US/wsj0vp.5000.DMP files.  Note that right now the project expects to find a speech model named hub4wsj_sc_8k_adapted.  You can adjust the run_main.sh shell script to send the appropriate model as a parameter when it runs DemoManMonitor (the parameters are exactly the same as the pocketsphinx_continuous tool that ships with PocketSphinx, you can see more details here).  You might later want to adapt the models to your voice and microphone for better accuracy--I had good, but not amazing results from adaptation.

To get the microphone to work you will need to enable USB audio with ALSA on the Pi, follow these instructions to change the snd-usb-audio option from -2 to 0.  Once done, if you execute 'cat /proc/asound/cards' you should see two devices, one for the microphone (for the PS3 eye cam look for 'OmniVision Technologies') and one for PCM audio output.

To connect the printer, connect the red and black power pins from the printer to power supply positive and ground respectively (do not try to power the printer from the Pi!).  Connect the printer serial RX pin (yellow) to the TX pin on the Pi (GPIO 14).  Leave the printer TX pin unconnected as it outputs 5V which is unsafe for the Pi RX pin to receive (and data doesn't need to be read from the printer in this application).  Note when you power on the Pi the printer might start printing garbage so disconnect the RX pin on boot and connect it before running the software.

Connect the quiet mode switch to any GPIO pin on the Pi, I used wiring Pi pin 0 (which is Pi BCM pin 17).  If using an SPST toggle switch, the middle pin goes to the GPIO pin, while one outer pin goes to 3.3V po

Components
  • 1 × Raspberry Pi Model B is best because of multiple USB ports. Memory usage is not super high so it would probably still work on a model A.
  • 1 × Playstation 3 Eye Camera Any USB microphone will work, but this one has a nice microphone built to capture audio in a room.
  • 1 × Mini Thermal Printer Adafruit has a good one: http://www.adafruit.com/products/597
  • 1 × Small Amplifier & Speaker I used this amp and speaker: http://www.adafruit.com/products/1552 and http://www.adafruit.com/products/1313
  • 1 × 5 volt power supply with 2+ amps of current Adafruit has some good options: http://www.adafruit.com/products/658 or http://www.adafruit.com/products/1466
  • 1 × SPST toggle switch This is used to put the device into 'quiet mode' where no alarms are raised.
  • 2 × Red LEDs I used a couple high power red LEDs to light up the front of the enclosure.
  • 1 × NPN transistor Used to switch the LEDs on and off without pulling too much current from the Pi.

Project logs
  • Final Project

    3 months ago • 4 comments

    Finished a few small things like adding red LEDs that light when the alarm goes off, take a look:

    The project is basically done at this point.  I'll fill in a few more details on the project page this weekend and then consider it complete.

  • Shiny!

    4 months ago • 0 comments

    Finished the enclosure by covering it in metallic paper.  Take a look at the results here: 

    At a craft store I found 12"x12" sheets of metallic paper on thick cardstock that ended up working great.  The thicker size of the material helped to smooth out imperfections in the cardboard.  For attaching the paper I used Super 77 spray glue so it's a smooth, permanent finish.  The only difficulty was working with the glue.  You get one shot to line things up and that's it!  Also cutting the curved shapes and edges was a little challenging--a very sharp knife is required.  The edges aren't perfect but I'm still very happy with how things turned out.

  • Enclosure Progress

    4 months ago • 0 comments

    Here's an update on the progress I've made building an enclosure for the device: 

    The enclosure is made out of a couple oatmeal containers attached to a frame of foam board.  The front is a piece of mat board (roughly the same thickness as the oatmeal containers) bent and glued to the frame in the tear drop shape.  I plan to finish the enclosure by covering everything in metallic tape which should give a nice metallic finish without a lot of prep work.

    Once the enclosure is finished I'll mount the hardware inside and the project will be finished! :)

View all 10 project logs

Build instructions

Discussions

= Sienar = wrote 25 days ago null point

this is so nice! wish i could give doubleskull!

Are you sure? [yes] / [no]

paul wrote 2 months ago null point

call me when you've figured out the three shells.

Are you sure? [yes] / [no]

blarbles wrote 3 months ago null point

Following the instructions in the "Enable Software Access to Serial Port" section of https://learn.adafruit.com/pi-thermal-printer/pi-setup-part-2 eliminated the printer garbage at boot for me. Here are the instructions (written by Adafruit):

The serial port on the Raspberry Pi’s GPIO header is normally configured for console cable use. But now we want to use this port for the thermal printer instead, so we’ll need to disable this default behavior.

sudo nano /boot/cmdline.txt

Change:

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

to:

dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait

And:

sudo nano /etc/inittab

Comment out or delete the last line. i.e. change this:

T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

to:

# T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

Are you sure? [yes] / [no]

tdicola wrote 2 months ago null point

Awesome, thanks for pointing out how to stop the spam of junk from the printer!

Are you sure? [yes] / [no]

Antonio Scolari wrote 3 months ago null point

Hi tdicola,
Question,: How are you sending to print from the raspberry ?
I'm starting a project that includes ticket printing,

Are you sure? [yes] / [no]

tdicola wrote 3 months ago null point

The printer talks over a serial connection to the Raspberry Pi. I ported Adafruit's Arduino library to run on linux--check out Adafruit_Thermal.cpp and .h in the source code on github. You can also see a simple example of using it in tests/AdafruitThermalTest.cpp. If you're using Python in your project, check out Adafruit's own python library: https://github.com/adafruit/Python-Thermal-Printer In general they have some good tutorials on setting up the printer too: https://learn.adafruit.com/mini-thermal-receipt-printer/overview

Are you sure? [yes] / [no]

Mike Szczys wrote 3 months ago null point

I'm just getting down to the last few entries in the Sci-Fi contest. Several have made me laugh and your finished project video made me laugh perhaps the hardest.

I hope you have a hackerspace full of foul-mouthed members where this can be installed!

Are you sure? [yes] / [no]

blarbles wrote 3 months ago null point

Just in case others are interested in this project: To get everything to compile without errors (including sphinxbase, pocketsphinx, and DemoManMonitor) I had to install the following pacakages: autoconf, libtool, automake, bison, swig, python-dev, gcc-4.7, g++-4.7, libasound2-dev (do "apt-get install "). Also the DemoManMonitor will compile and run but will have an exception if you don't rename the "hub4wsj_sc_8k" to "hub4wsj_sc_8k _adapted" (took me forever to figure that one out, but I am new to this stuff). I found doing apt-get upgrade broke quite a few things so I stuck with the original RASPBIAN Jan release (plus the packages I listed above). Also if your "make" command has an error you have to do "make clean" to clean up any files it created before trying "make" again. Thanks for this great project!

Are you sure? [yes] / [no]

tdicola wrote 3 months ago null point

Oh wow, thanks for writing up the details on the dependencies and sorry for the pain of figuring them out. I was hoping once pocketsphinx has an official release with the keyword spotting stuff I could just package up the project as a binary and release it so it's easier to install. I'll update the description to note the dependencies like you call out--the packages build-essential, gcc-4.7, libasound2-dev should be the major ones + compiling and installing sphinxbase, pocketsphinx, and wiringPi. Great point about the speech model name too--the command line parameters in run_main.sh choose the model so you can change the name there too. If your speech recognition results aren't great you might look into adapting the model by following this guide too: http://cmusphinx.sourceforge.net/wiki/tutorialadapt And yeah the makefile is not my finest hour--I really only know enough about make to be dangerous. :)

Are you sure? [yes] / [no]

pierrep wrote 3 months ago null point

Sweet movie and really nice project, maybe you could add cable tidies to clean the view around the Rasberry Pi.

Are you sure? [yes] / [no]

tdicola wrote 3 months ago null point

Great point, I could definitely do some cleanup with the cables.

Are you sure? [yes] / [no]

x3n0x wrote 3 months ago null point

NICE! Coming along great man!

Are you sure? [yes] / [no]

Lewis Callaway wrote 3 months ago null point

Awesome Project! I saw that on Show and Tell! If they would have that at my school, everyone would be broke.

Are you sure? [yes] / [no]

tdicola wrote 3 months ago null point

Haha, thanks for the feedback.

Are you sure? [yes] / [no]

Steven Hickson wrote 4 months ago null point

Hey guys, saw you were using pocketsphinx as your speech recognition. I tried it and found Google's to work much better. If you have an internet connection it is pretty fast and reliable. I have code to use it available for the Raspberry Pi.
http://hackaday.io/project/87-Voice-Controlled-Raspberry-Pi

Are you sure? [yes] / [no]

tdicola wrote 4 months ago null point

Thanks for the feedback. I've looked into other speech recognition options like Google's API but was a little concerned that they wouldn't handle continuous speech recognition and keyword spotting very well. With your program do you have the mic constantly listening and sending data to Google's API, or do you only record audio when something happens like a button is pressed? In my case I want to continuously record audio in the background, so I'm concerned it would be too much load and bandwidth to be constantly sending audio to Google's API.

Are you sure? [yes] / [no]

OneShot Willie wrote 4 months ago null point

I think i found your test file... ; )

George Carlin's monologue at issue in the Supreme Court case of FCC v. Pacifica Foundation

http://law2.umkc.edu/faculty/projects/ftrials/conlaw/filthywords.html

Are you sure? [yes] / [no]

tdicola wrote 4 months ago null point

Haha, great idea.

Are you sure? [yes] / [no]