adrift in the sea of experience

Friday, January 25, 2008

Recording phone calls on a S60 phone. Part 2: working prototype

<voice type="farnsworth">Good news everyone!</voice>

I messed around with the PyS60 python interpreter for my S60 phone, and managed to record phone calls! The first step is to install PyS60 as described on the PyS60 wiki. No further tools are needed, the python runtime and shell on your phone are sufficient. Next, we need a script which listens for phone calls being connected, either incoming or outgoing, and which starts and stops recording those calls:

import appuifw
import e32
import telephone
import audio
import time

# Must be either None, or a sound file which is recording.
sound_file = None

# Directory used to save call recordings. Must exist.
# Filename will be appended to this path.
recordings_folder = "e:\\CallRecordings\\"

def cb_calling(args):

global sound_file
state = args[0]

# if transition to connected state and not recording, start recording
if (state == telephone.EStatusConnected) and (sound_file == None):
number = args[1]
if number == None:
number = "None"
filename = recordings_folder + time.strftime("%Y%m%d_%H%M_%S_") + number + '.wav'
#filename = recordings_folder + 'test.wav'
print filename
sound_file = audio.Sound.open(filename)
sound_file.record()

# if transition to non-connected state and recording, stop recording
elif (state != telephone.EStatusConnected) and (sound_file != None):
sound_file.stop()
sound_file.close()
sound_file = None


def quit():
app_lock.signal()

appuifw.app.exit_key_handler= quit
app_lock=e32.Ao_lock()

telephone.call_state(cb_calling)
telephone.incoming_call()

app_lock.wait()

The body of the script only sets the exit key handler, registers a callback function for detecting telephone call state changes, and starts waiting for a signal on a lock object. After that, the main thread will not do any more work. It was surprising to discover that real multi-threading is central to developing in Pys60. I was expecting to see a "message queue with single threaded message pump" kind of model, like most PC application frameworks.

Copying this python script to a \Python directory enables you to run it on the phone with the python shell application. Once running, it will listen for phone calls and record them to the recordings_folder.

Unfortunately, there is an annoyance: apparently nokia feels obligated to insert a beeping sound into the call every 5 seconds if it is being recorded. The beeping is not present in the recording though. I did not find any more information on this "feature", other than that it appears to be built into the phone. I guess nokia is trying to legally cover their ass here. I researched Belgian law regulating phone call recording, but did not find any obligation to inform participants that you are recording them. If you are not recording with intent to deceive or harm and are participating in the call yourself, then it's OK to record without warning. (Disclaimer: I am not a lawyer)

Can we get rid of these annoying beeps? Is there a way to automatically start the call recorder code on phone boot? Questions, questions...

To be continued!

Wednesday, January 23, 2008

Recording phone calls on a S60 phone.

I love gmail. I haven't needed to delete email since I started using it. And the search feature is awesome. I wish my entire life could be archived and searched just as easily. And why not? For example, everything I hear could in principle be recorded to files and archived. Add a dash of speech-to-text and I could have a searchable history of all my conversations.

Right now however, I only archive email and the occasional cameraphone snapshot or video (and chat logs and text messages, but I should archive them better). In pursuit of the goal "log everything", I'm going to try and add something to that list: phone conversations.

My nokia smartphone is build on the S60v3 symbian platform. There exists a python interpreter for that platform, and it comes with modules for doing a lot of stuff. According to the documentation, you can run code in response to incoming calls. You can also record audio. This should be all I need to start logging my phone calls.

Yay, we've got ourselves a project :)