TwoToneDetect on a Raspberry Pi


This page describes how to get a special version of TwoToneDetect up  and running on a $35 Raspberry Pi single board computer.  Along with a $5 USB sound card and a cheap receiver ($50 Wouxon or similar), you can have a full TTD setup running 24/7 that consumes very little power for under $100.  This page describes what I  did to get it running on my Pi.  Your mileage may vary.


The instructions below were developed on a Raspberry Pi Model B, and may not be 100% correct for a Model B+.  For an SD card image that works on the B and B+ and already has TTD running using the Raspbian operating system, click here.

For instructions on running TTD on the Ubuntu MATE operating system on a Pi3 (rather than Raspbian), see this forum post.

What you’ll need

  • A Raspberry Pi
  • An SD card (4 GB or greater)
  • 5V Power supply with a micro-USB cord to power the Pi
  • A USB sound card (I use this one)
  • A radio receiver (radio, scanner, pager, etc.)
  • A network connection (I used wired ethernet.  You should be able to get this running on WiFi but I haven’t attempted that yet)

Getting Started

First, follow the instructions here to get the latest Raspbian operating system installed on your SD card.  Then take a look at this tutorial to get the Pi configured during the initial boot up.  You’ll want to configure the keyboard, locale, and timezone, as well as expand the root partition so that you can use your entire SD card.  Finally, make sure you enable SSH server on your Pi.  This will save you later if you find (like I did) that your keyboard and mouse don’t work with USB 1.1 if you have to disable USB 2.0 to get your sound card to work properly.

After you’ve done your initial configuring, get yourself familiar with the Pi.  You can type:


to start a graphical interface similar to Windows, or just work with the command line, whichever you prefer.  Most of  the TTD setup will be done at the command line, although configuring the audio input is done with a GUI for simplicity.

Installing Prerequisites for TwoToneDetect

Because Pyinstaller doesn’t work with the ARM platform that the Pi uses, I can’t build an executable for the Pi that will automatically incorporate all of the required prerequisite packages for running TwoToneDetect.  Instead, we’ll have to install them manually.  If you follow the instructions here you should get everything you need.  Make sure your Pi is connected to the web before proceeding.

First, we need to install Python’s setuptools so that we can install a few Python packages. We do this by entering the following at the command prompt:

sudo apt-get install python-setuptools

Then do this, which gets the python.h header file required to compile other modules using PIP:

sudo apt-get install python-dev

Then download PIP and install it by doing this:

cd ..
mkdir pip
cd pip
curl –O
tar zxf pip-1.3.1.tar.gz
cd pip-1.3.1
sudo python install

Once we have PIP installed we can use it to grab and install a couple more required Python modules:

sudo pip install Pycrypto
sudo pip install Iniparse

Installing Pyaudio requires a few more steps:

sudo apt-get install git
git clone
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo pip install pyaudio

We also need to install ffmpeg with an amr codec:

sudo apt-get install ffmpeg libavcodec-extra-53
Note:  ffmpeg has been deprecated on newer versions of the Raspbian operating system.  Until a fix is created for TTD, you can use the following steps to install it if the instructions above fail:
mkdir ffmpegtemp
cd ffmpegtemp
sudo su

dpkg -i ffmpeg_2.8.3.git325b593-1_armhf.deb
apt-get install libdc1394-22 libxvidcore-dev libav-tools libopencore-amrwb-dev libopencore-amrnb-dev

And we’ll install pulse audio and the pulse audio control GUI for setting our audio levels:

sudo apt-get install pulseaudio
sudo apt-get install pavucontrol

Finally, we’ll need to change the resampling method for pulseaudio, since TwoToneDetect uses a lower sampling rate than the default of most sound cards.  Use this to start open the required file in the “nano” text editor:

sudo nano /etc/pulse/daemon.conf

then find the line that says:


and change it to:


note that you need to remove the semicolon at the beginning of the line!

Then reboot to cause changes to take effect.

Setting up pulseaudio

Unlike under Windows, we won’t be able to specify our USB sound card as the audio input to TwoToneDetect.  This is because the Pi’s audio driver system doesn’t support different sampling rates for the sound card.  It will only allow us to sample at the default rate.  Instead, we’ll use pulseaudio as the input to TwoToneDetect, since pulseaudio will perform resampling from the USB sound card to TwoToneDetect.  To set our audio input levels, we can use the pulse audio control GUI under XWindows.  From a terminal window in the XWindows GUI, type pavucontrol to bring up the GUI.  Click on the “Input” tab and set the volume of your USB sound card appropriately, using your radio with open squelch or tuned to a weather broadcast channel to get the levels correct.  Set any other inputs to zero volume. Note:  If you are running a GUI-less version of Raspbian (like Jessie Lite), you can use an environment variable to set the sound input device that you want to use with TTD.  See the section below on “Running Multiple TwoToneDetect Instances” for instructions on how to do this.

Installing and configuring TwoToneDetect

To install TwoToneDetect, do the following:
mkdir TTD
cd TTD

sudo reboot

The Raspberry Pi version of TwoToneDetect does not include any GUI (to reduce CPU load), which makes configuration a little more difficult.  To edit the tones.cfg file, there are a few options:

  1. Edit manually from the command line using the nano text editor (see below)
  2. Edit manually using the text editor in the Leafpad text editor in the XWindows GUI (see below)
  3. Edit the tones.cfg file using the TonesEditor GUI on a Windows PC and transfer the file to the Pi using WinSCP
  4. Edit the tones.cfg file using the TonesEditor GUI in XWindows by navigating to the TwoToneDetect directory and typing python TonesEditor3.pyc

To edit the config.cfg file, you’ll need to manually edit it using  either nano (from the command line) or Leafpad (in the XWindows GUI).  Before editing the config.cfg file, you’ll need to determine the index of the pulseaudio input and output so that you can set the input_device_index and output_device_index parameters accordingly.  You’ll also need to determine what level to set the audio_threshold parameter to.  To help with these tasks, I’ve include a LevelMeter utility.  To start it, navigate to your TwoToneDetect directory and type:

python LevelMeter.pyc

The utility will list all of your input and output sound devices.  You want to find the input and output named pulse.  Make note of the index (number) of these, as this is what you’ll want to specify for the input_device_index and output_device_index in your config.cfg file.

Enter in the index corresponding to pulse for the input and output, and the utility will start taking audio samples and printing the audio level to the console window.  Make note of what the audio levels are with no audio input present, and also with audio present.  You’ll want to set your audio_threshold parameter to be somewhat above the levels you see with no audio present, but not so high as to be above the levels when audio is present.  You can adjust the audio of your scanner or radio using this utility as needed.  To stop the audio sampling and terminate the LevelMeter utility, hit CTRL-C.

Now that you now what the input_device_index, output_device_index, and audio_threshold parameters should be set to, you can edit the config.cfg file.  Note that the email password must be base64 encoded in the config.cfg file.  There are a number of websites that can do this encoding for you, or you can copy this parameter over from a Windows computer that you have running TwoToneDetect.

Once you have the tones.cfg and config.cfg files set up correctly, you can start TwoToneDetect by typing:

python TwoToneDetect68Pi.pyc


USB Audio Input Issues

The USB audio support on the Raspberry Pi still has some issues.  See this forum thread for more information.  To solve this, I had to add this statement to the beginning of /boot/cmdline.txt file:


After modification, /boot/cmdline.txt should look something like this:

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

After doing this my USB mouse and keyboard stopped working, so I had to access my Pi via PuTTY using SSH.  However, this fixed my audio issues and made TwoToneDetect work well.

Running Multiple TwoToneDetect Instances

Run this command to list the input devices available to pulseaudio:

LANG=C pactl list | grep -A2 'Source #' | grep 'Name: ' | cut -d" " -f2

In my case this returned something like this:


Next, when you start TTD, set the PULSE_SOURCE environment variable to whichever input you want to use from the step above (don’t use the ones that end in “monitor”). Here is an example:

PULSE_SOURCE=alsa_input.usb-0d8c_C-Media_USB_Headphone_Set-00-Set.analog-mono python

So, to run two instances of TTD, you’d have two TTD folders set up, and use a different PULSE_SOURCE when starting each instance. You can use the same strategy with the PULSE_SOURCE environment variable to run different instances of darkice for streaming. Of course this can all be scripted for automation. I haven’t tried more than two instances/sound cards, but it does work with two, even with simultaneous detection of pages on each card. I’m not sure what the upper limit is.

Manually editing the tones.cfg file

To manually edit the tones.cfg file without using the GUI, open the file using a text editor.  Each tone set is specified by a [Tone] or [Longtone] delimiter.  For two-tone (A-B format) pages, use [Tone], for long tone pages (long A or long B format), use [Longtone].  See below for a simple example.

Atone = 389
Btone = 539
Btonelength = 3
Description = Station 5
mp3_Emails =

Longtone = 457.9
Description = Long Tone Page
Longtonelength = 7
mp3_Emails =

Additional tone sets can be added by simply adding more [Tone] or [Longtone] sets to the text file.  However, be sure to use different numbers in the heading.  For example, use [Tone1] and [Tone2].  Using [Tone1] twice, even with a different Description field, will not work.  When you have the tones.cfg file set up the way you want it, be sure to save it before closing.  See above for information on each of the parameters in the tones.cfg file.

Example using all mandatory and optional parameters:

Atone = 707.3
Btone = 746.8
Atonelength = .6
Btonelength = 1
Description = Fire Department 1
mp3_Emails =,,
amr_Emails =,
ignore_after = 60                    ;
alert_command = c:\test.bat
post_email_command = c:\test2.bat
radio_frequency = 154.475
exclude_from = 13:25
exclude_to = 13:35
exclude_emails =,

playback_during_record = 1

record_delay = 2.5