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.
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!!!
sir made dtmf based project but i have no idia of dtmf decoder plz tell me work of dtmf decoder\encoder
Please can you make the wav files available also?
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.
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
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.
What version of python you ran it onto?
It’s in the blog post. I was using 2.2.
I had the same problem. The only audio samples I could get to work were 16 bit 8k sampling mono.
Once I used the correct format, this error went away.
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.
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
I have tried to decode a number with 2 same digits one after another one and the program doesn’t decode the second digit. On this website there is a link to a good dtfm
detector : http://aluigi.org/mytoolz.htm
Hai Conatic whr ru frm.I like python.Can you help me.I need a app to controll a phone via phone call.If i pressed 1,2 respectively a app will run.Can you help me to make this
Abilash ov-fb iam on fb pls help me
ImportError: No module named chunk
If it’s not on your phone then find the chunk.py file on your desktop install of Python and copy it over to your phone in the same directory as your other project files. It looks like chunk is part of 2.7.3 http://docs.python.org/library/chunk.html
Hay. I need a help.i want to controll my phone via another phone.if i pressed 1 in my n73 my another phone can detect that press.can this dtmf is able to do this
You could use the DTMF detector code I have posted to detect the button press, but the rest will be up to you.
i nee 1 more help.how can i get bass and trouble in a mp3.i means ineed to make graphical visualisation spectrum
I don’t know how to do that. I’ve never tried before.
helo thanks for your replay i think that you never see what i am writted.iam very happy now.becos your watching the my words. Iam not fluent in english. I know only malayalam,tamil,hindi
do you hear about kerala.
how many keys we can detect.i mean if iam using e90.can i detect all key pressing.like camera,red key,pen
No, it just detects the standard phone keys: 0-9, #, and *
thanks etherton. Great work.very usefull module