Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sounds_of_animals.py
- import appuifw, audio, os
- animals = [u'dog', u'cat', u'cow']
- def record_animal_sounds():
- for animal in animals:
- fullpath = 'e:\\' + animal + '.wav'
- try: os.remove(fullpath)
- except: pass
- sounds = audio.Sound.open(fullpath)
- if appuifw.query(u"Record sound of a " + animal, "query"):
- sounds.record()
- appuifw.query(u"Press OK to stop recording", "query")
- sounds.stop()
- sounds.close()
- def select_sound():
- global sounds
- sounds = None
- while True:
- index = appuifw.popup_menu(animals, u"Select sound:")
- if sounds:
- sounds.stop()
- if index == None:
- break
- else:
- play_animal_sound(u'e:\\' + animals[index] + '.wav')
- def play_animal_sound(soundfile):
- global sounds
- sounds = audio.Sound.open(soundfile)
- sounds.play()
- record_animal_sounds()
- select_sound()
- for animal in animals:
- fullpath = 'e:\\' + animal + '.wav'
- try: os.remove(fullpath)
- except: pass
- print 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement