| | |
Sound in Python
![]() |
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 ...
python Syntax (Toggle Plain Text)
# some sound effects using PMIDI # NewNote(beat,duration,note,octave) from PMIDI import * from time import sleep def bird(): seq = Sequencer() song = seq.NewSong() voice = song.NewVoice(0) voice.SetInstrumentByName('Bird Tweet') m = voice.NewMeasure() m.NewNote(0, 8, 'A', 5) m.NewNote(8, 8, 'D', 5) m.NewNote(16, 8, 'A', 5) seq.Play() sleep(1.2) # enough seconds to play seq.Close() def gun(): seq = Sequencer() song = seq.NewSong() voice = song.NewVoice() voice.SetInstrumentByName('Gunshot') m = voice.NewMeasure() m.NewNote(0, 12, 'F', 4) seq.Play() sleep(0.8) # enough seconds to play seq.Close() def wood(): seq = Sequencer() song = seq.NewSong() voice = song.NewVoice() voice.SetInstrumentByName('Woodblock') m = voice.NewMeasure() m.NewNote(0, 24, 'G', 3) seq.Play() sleep(1) # enough seconds to play seq.Close() bird() # bird chirps sleep(1) # wait a second gun() # idiot shoots it sleep(1) 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!
![]() |
Similar Threads
- Beginning Python Book (Python)
- Sound and Python (Python)
- New program: Monty Python Madlibs! (Python)
- Sound in wxPython (Python)
Other Threads in the Python Forum
- Previous Thread: Running a 3rd party program from Python
- Next Thread: Python and BOO
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






