You Are Here:

Community: Developer Discussion Boards

#1 Old DTMF detection on phone - 2007-01-23, 16:47

Join Date: Oct 2006
Posts: 10
jetherton
Offline
Registered User
When a third party calls a phone I'd like to be able to detect what buttons they press. I figure I could record the voice downstream and then after the call run some algorithm to figure out what keys where pressed durring the call.

So I was wondering if anyone had done this kind of thing before or had any advice.

I've really liked using Python and would like to keep on using python but if there's no other way than to use C or something then I'm fine with that. I'm developing for a N80 and 6682

Thanks a lot,

John
Reply With Quote

#2 Old Re: DTMF detection on phone - 2007-01-23, 19:48

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by jetherton
When a third party calls a phone I'd like to be able to detect what buttons they press. I figure I could record the voice downstream and then after the call run some algorithm to figure out what keys where pressed durring the call.
What you want is the Goertzel algorithm:

You might be able to make it run acceptably even in pure Python. A pure C implementation would probably work in real time.
Reply With Quote

#3 Old Re: DTMF detection on phone - 2007-01-24, 04:49

Join Date: Oct 2006
Posts: 10
jetherton
Offline
Registered User
thanks jethro.fn. Do you know how I could tap straight into the voice stream or how to decode a .wav file recorded from the voice stream so I can take samples from the audio?
Reply With Quote

#4 Old Re: DTMF detection on phone - 2007-01-24, 11:32

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Reading WAV files from Python is typically done using the "wave" module, which in turn uses the "chunk" module to do the reading. Neither "wave" or "chunk" are included in PyS60. Unfortunately the wave module relies on the "array" module, which is implemented in C and also not included in PyS60.

Checking out wave.py from Python 2.2, it seems that "array" is only used when bits per sample is greater than 8 and when running on big-endian architecture. So possibly "wave" can be used in PyS60.

PyS60-specific module "audio" can be used to record a phone call. By saving the audio file in RAM disk (D: ) it is then possible to read it back and analyze it.
Reply With Quote

#5 Old Re: DTMF detection on phone - 2007-01-24, 14:53

Join Date: Feb 2006
Posts: 168
Location: Helsinki, Finland
RICH?
Offline
Regular Contributor
This sounds interesting... We could controll remote phones without gprs etc. and it would only cost for the controller phone.


Nokia E66
PyS60 1.4.4 final
Reply With Quote

#6 Old Re: DTMF detection on phone - 2007-01-24, 17:16

Join Date: Oct 2006
Posts: 10
jetherton
Offline
Registered User
How hard would it be for me to just read in the raw bytes from the file on the RAM disk, and use them as samples? Would I need to perform any kind of decompression or normalization? How could I find out where each sample starts and ends.

I understand that .WAVs are uncompressed so it seems to me that it would be rather straight forward to get samples from a .WAV file.
Reply With Quote

#7 Old Re: DTMF detection on phone - 2007-01-25, 10:01

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by jetherton
How hard would it be for me to just read in the raw bytes from the file on the RAM disk, and use them as samples?
Not very. The Python modules wave.py and chunk.py are about 650 lines, combined (Python v2.2). And that includes plenty of comment lines. Easiest way is probably to study those two modules and implement something based on that.
Reply With Quote

#8 Old Re: DTMF detection on phone - 2008-10-16, 11:32

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Quote:
Originally Posted by jethro.fn View Post
What you want is the Goertzel algorithm:

You might be able to make it run acceptably even in pure Python. A pure C implementation would probably work in real time.
I need a little help in understanding this algorithm.

Q0 = coeff * Q1 - Q2 + sample (link)

Does this mean I must add the amplitude of the sample N times, and I'll new if TARGET_FREQ is present in the chunk of signal?
Reply With Quote

#9 Old Re: DTMF detection on phone - 2008-10-18, 19:24

Join Date: Mar 2003
Posts: 564
cassioli's Avatar
cassioli
Offline
Super Contributor
Never mind... here it is the solution:

Code:
def Goertzel(target_freq,N):
    global rawdata, SampleRate
    pi = 3.141592654
    k=int(0.5 + (N*target_freq/SampleRate)) 
    w = (2*pi*k)/N    
    cosine = cos(w)    
    sine = sin(w)
    coeff = 2 * cosine        
    
    q0=0.0
    q1=0.0
    q2=0.0
    for sample in range(0,N):
        q0 = coeff * q1 - q2 + rawdata[sample]
        q2 = q1
        q1 = q0        
         

    realPart = q1 - q2 * cosine
    imgPart = q2 * sine
    
    
    magnitudeSquared = realPart*realPart + imgPart*imgPart
    magnitude = sqrt(magnitudeSquared)
    
    return magnitude


def recording():
    global StringNum,Samples, SampleRate
    print "Testing string: ",7-(StringNum+1)," (=", stringsnames[StringNum], ",", strings[StringNum], ") with ", Samples/SampleRate, " seconds sample (",Samples, " samples, SampleRate=", SampleRate,")"
    # open the sound file to be ready for recording and set an instance (S) of it
    if os.path.exists(filename):
      os.remove(filename)
    S=audio.Sound.open(filename)

    # do the recording 
    S.record()
    print "Recording..."
    time.sleep(2)
    S.stop()
    S.close()
    
    print "Loading into memory..."        
    ExamineWav(Samples) # Load samples just recorded.
    print "File loaded."
    os.remove(filename)
    


def Process():   
    global Samples,NumBars,Span,G
    global StringNum    
    print "Processing data..."
    G=[]
    Freq=strings[StringNum] # Assign central frequency depending as per menu choice.
    # Analyze samples and store results:
    index = 1
    for f in range(Freq-Span,Freq+Span,2):
        G.append(int(Goertzel(f,Samples)))
        index = index + 1
    NumBars = index-1
    print "Finished. Now plotting..."
this will result in having in G[] results of Goertzel algorithm for various frequencies.
http://discussion.forum.nokia.com/fo...d.php?t=121691
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Not Every phone receive SMS from WMA youngboyguy Mobile Java General 3 2007-04-18 12:56
Emulated Nokia phone can not connect to bluegiga WT12 module hwan122 Bluetooth Technology 0 2007-01-09 02:05
7610 Contacts - Formatted Phone Numbers padlon General Discussion 2 2004-11-12 19:02
Detecting call status of the phone jkekoni Symbian Networking & Messaging 6 2004-10-11 09:07
Nokia Image Converter davidpurdie General Discussion 0 2004-02-18 16:31

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia