PyS60 DTMF Detector

Download DTMFdetector.py

I made this so I could do DTMF detection with Python on a Nokia Series 60 phone. I made it as quickly as I could, so that’s all it really does. Since this is all it really does it only works for WAV files that were recorded in the format that PyS60 records audio, which is one channel sampled at 8000hz in 16 bits. This is my first attempt at making a general, reusable library for PyS60.

IMPORTANT:
for this to work with PyS60 1.3.17 I had to install the wave.py and chunk.py files from my python 2.2 installation onto the phone as libraries.
Usage example:
Assume we have a single channel 16 bit, 8000hz file “audioFile.wav” that was recorded on a phone when someone pressed 8,3,3,4,5

    	from DTMFdetector import DTMFdetector
	dtmf = DTMFdetector()
	data = dtmf.getDTMFfromWAV("audioFile.wav")
	print data

OUTPUT:

	"83345"
It’s that simple
16khz samples:
To make the detector work with files that sample at 16khz instead of 8khz make the following changes:
self.GOERTZEL_N = 210
self.SAMPLING_RATE = 16000
License Stuff:
This code is released to the public for any use. I wish I knew which license that is but I don’t know. I should probably find out. This is code is offered as is with out any warranty. If it breaks and does something bad, don’t sue me. I have tested it to the best of my ability, but I have no doubt that it has numerous faults. The Goertzel algorithm used in this script was shamelessly stolen from this wikipedia entry: http://en.wikipedia.org/wiki/Goertzel_algorithm All the code not given in that entry I wrote myself.

Please email me with any comments about DTMFdetector.

11 Responses to PyS60 DTMF Detector

  1. Nikhil Das says:

    Can u plz mail me the entire folder as zip comprising code,wav file, your obtained results,
    and report if any!!!
    Do u hv C/C++ code for this as I m unfamiliar with python?? if possible mail that 2!!
    :)
    Awaiting your mail!!!! Thanks a lot!!!

  2. sachin jain says:

    sir made dtmf based project but i have no idia of dtmf decoder plz tell me work of dtmf decoder\encoder

  3. Charles says:

    Please can you make the wav files available also?

    • etherton says:

      I’m afraid I haven’t worked on this in a long time, but I’m sure if you google “DTMF wav file” you’ll find some wave files that will work.

  4. Bharat Goyal says:

    I have been trying this for a while. Is it necessary to have the audio samples at 8/16 KHz.. I have testing it for a file having an audio sample at 11025 Hz, also I get errors with the variable ‘raw’ -

    line 324, in getDTMFfromWAV
    (sample,) = struct.unpack(“h”, raw)
    error: unpack requires a string argument of length 2

    • etherton says:

      So I honestly don’t understand the math in the Goertzel algorithm well enough to know exactly what you should do, so I’d start by setting self.SAMPLING_RATE to 11025 and then try playing with the self.GOERTZEL_N between 92 and 210 until it works.

      For the error regarding unpack. Do you know what raw contains when it’s passed into struct.unpack()? I suspect you’re using a newer version of python than when I wrote the library, and maybe file.readframes(1) is returning something different.

  5. Vishal says:

    Hi,

    Sorry to post a question on old chain.

    Can I please know, what item corresponds to “GOERTZEL_N” in Goertzel algorithm? Is it normalizedfreq?

    Also, if we want to calculate in “normalizedfreq = freq / SAMPLEFREQUENCY;” for Goertzel algorithm, I assume “freq” is nAvgBytesPerSec and “SAMPLEFREQUENCY” is nSamplesPerSec in FMT chunk wav file. Please correct if I am wrong.

    Using this I am trying to understand what should be the correct value for GOERTZEL_N to be used in your python script.

    Thanks.

  6. Hai, iam from india.Iam a plus two student.Now iam learning python.Can you give me a simple dtmf app.If i can controll another s60 via my phone

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>