Sound in Python

Reply

Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 137
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Sound in Python

 
0
  #1
Nov 19th, 2005
I did find the Python code snippet on PMIDI module here. It works fine and I have made some interesting sounds with it. Is there way to save this as sound file?
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,972
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 920
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Sound in Python

 
0
  #2
Nov 20th, 2005
The beauty of the PMIDI module is that you can produce sound, be it music or soundeffects, within your program with a few lines of code. This way you don't have to load a number of wave files (.wav) that are typically between 5k and 250k in size. Here is an example ...
  1. # some sound effects using PMIDI
  2. # NewNote(beat,duration,note,octave)
  3.  
  4. from PMIDI import *
  5. from time import sleep
  6.  
  7. def bird():
  8. seq = Sequencer()
  9. song = seq.NewSong()
  10. voice = song.NewVoice(0)
  11. voice.SetInstrumentByName('Bird Tweet')
  12. m = voice.NewMeasure()
  13. m.NewNote(0, 8, 'A', 5)
  14. m.NewNote(8, 8, 'D', 5)
  15. m.NewNote(16, 8, 'A', 5)
  16. seq.Play()
  17. sleep(1.2) # enough seconds to play
  18. seq.Close()
  19.  
  20. def gun():
  21. seq = Sequencer()
  22. song = seq.NewSong()
  23. voice = song.NewVoice()
  24. voice.SetInstrumentByName('Gunshot')
  25. m = voice.NewMeasure()
  26. m.NewNote(0, 12, 'F', 4)
  27. seq.Play()
  28. sleep(0.8) # enough seconds to play
  29. seq.Close()
  30.  
  31. def wood():
  32. seq = Sequencer()
  33. song = seq.NewSong()
  34. voice = song.NewVoice()
  35. voice.SetInstrumentByName('Woodblock')
  36. m = voice.NewMeasure()
  37. m.NewNote(0, 24, 'G', 3)
  38. seq.Play()
  39. sleep(1) # enough seconds to play
  40. seq.Close()
  41.  
  42.  
  43. bird() # bird chirps
  44. sleep(1) # wait a second
  45. gun() # idiot shoots it
  46. sleep(1)
  47. wood() # bird hits ground
Last edited by vegaseat; Aug 12th, 2009 at 5:35 pm. Reason: changed the old php tags
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC