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 ...
# 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
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
Offline 5,792 posts
since Oct 2004