The audio Module

(This Website is created and managed by Pankaj Nathani) 

Home   Installation   Phase 1    Phase2   Phase4   Module-Wise Examples    Modules 

 Extensions    C++Py60 Extensions    Forum Nokia(Python)   Google Group   Contact Me   

Audio Module examples 

Sound Recorder Example

 
import appuifw, e32
# import the audio module
import audio


#This defines a name of the file to be the sound file, incl. its full path
filename = 'e:\\chime.wav'

#This defines the recording part:
def recording():
 global S
 # open the sound file to be ready for recording and set an instance (S) of it
 S=audio.Sound.open(filename)
 # do the recording (has to be stopped by closing() function below)
 S.record()
 print "Recording .Select Stop to end"

# define the playing part:
def playing():
 global S
 try:
 # open the sound file to be ready for playing by setting an instance (S) of it
 S=audio.Sound.open(filename)
 # play the sound file
 S.play()
 print "Playing"
 except:
 print "Record a sound first!"

# stopping of recording / playing and closing of the sound file
def closing():
 global S
 S.stop()
 S.close()
 print "Stopped"

def quit():
 script_lock.signal()
 appuifw.app.set_exit()

# define the application menu
appuifw.app.menu = [(u"play", playing),
 (u"record", recording),
 (u"stop", closing)]

appuifw.app.title = u"Sound recorder"

appuifw.app.exit_key_handler = quit
script_lock = e32.Ao_lock()
script_lock.wait()

Midi Player Example

 
import appuifw
import e32
import audio


def playsound1():
 S = audio.Sound.open("E:\\sound1.mid")
 S.play()
 menu()
 
def playsound2():
 S = audio.Sound.open("E:\\sound2.mid")
 S.play()
 menu()


def exit_key_handler():
 appuifw.app.set_exit()
 
def quit():
 appuifw.app.set_exit()

L = [u"sound 1", u"sound 2", u"exit"]

def menu():
 index = appuifw.popup_menu(L,u'select')
 if index == 0:
 playsound1()
 if index == 1:
 playsound2()
 if index == 2:
 quit()
 
appuifw.app.title = u"Midi player"

appuifw.app.exit_key_handler = exit_key_handler
menu()