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?

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
commented: Very helpful! +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.