| Reply | « Previous Thread | Next Thread » |
|
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 |
|
Quote:
You might be able to make it run acceptably even in pure Python. A pure C implementation would probably work in real time. |
|
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?
|
|
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. |
|
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 |
|
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. |
|
Quote:
|
|
Quote:
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? |
|
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..."
http://discussion.forum.nokia.com/fo...d.php?t=121691 |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| 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 |