# Copyright (c) 2007 Jurgen Scheible www.mobilenin.com # Sound file recording for 10 seconds only, always creating a new file (old gets removed beforehand) # setting the playhead to 5 sec, for playing only the last half import appuifw, e32, audio, os, time filename = 'e:\\Python\\sound\\boo.wav' if os.path.exists(filename): os.remove(filename) def recording(): global S S=audio.Sound.open(filename) print 'Recording!' print "Wait! Recording stops after 10 sec.!" S.record() time.sleep(10) print "Recoding over!" closing() def playing(): global S try: S=audio.Sound.open(filename) filelength = S.duration() print 'The length in microseconds: %d'%filelength S.play() print "Playing" except: print "Record first a sound!" def lasthalf(): global S try: S=audio.Sound.open(filename) filelength = S.duration() print 'The length in microseconds: %d'%filelength S.set_position(5000000) print 'Sarts from: %d'%5000000 S.play() print "Playing" except: print "Record first a sound!" def closing(): global S S.stop() play_position = S.current_position() print 'Play psoition in microseconds: %d'%play_position S.close() print "Stopped" def exit_key_handler(): script_lock.signal() appuifw.app.set_exit() script_lock = e32.Ao_lock() appuifw.app.title = u"Sound recorder" appuifw.app.menu = [(u"play", playing), (u"record for 10s", recording), (u"stop", closing), (u"play last half", lasthalf)] appuifw.app.exit_key_handler = exit_key_handler script_lock.wait()