Advertisement
here2share

# sounds_of_animals.py

May 17th, 2015
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # sounds_of_animals.py
  2.  
  3. import appuifw, audio, os
  4.  
  5. animals = [u'dog', u'cat', u'cow']
  6.  
  7. def record_animal_sounds():
  8.     for animal in animals:
  9.         fullpath = 'e:\\' + animal + '.wav'
  10.         try: os.remove(fullpath)
  11.         except: pass
  12.         sounds = audio.Sound.open(fullpath)
  13.         if appuifw.query(u"Record sound of a " + animal, "query"):
  14.             sounds.record()
  15.             appuifw.query(u"Press OK to stop recording", "query")
  16.             sounds.stop()
  17.             sounds.close()
  18.  
  19. def select_sound():
  20.     global sounds
  21.     sounds = None
  22.     while True:
  23.         index = appuifw.popup_menu(animals, u"Select sound:")
  24.         if sounds:
  25.             sounds.stop()
  26.         if index == None:
  27.             break
  28.         else:
  29.             play_animal_sound(u'e:\\' + animals[index] + '.wav')
  30.  
  31. def play_animal_sound(soundfile):
  32.     global sounds
  33.     sounds = audio.Sound.open(soundfile)
  34.     sounds.play()
  35.  
  36. record_animal_sounds()
  37. select_sound()
  38.  
  39. for animal in animals:
  40.     fullpath = 'e:\\' + animal + '.wav'
  41.     try: os.remove(fullpath)
  42.     except: pass
  43.  
  44. print 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement