import pyaudio,time,array,math p = pyaudio.PyAudio() sr=8000 nl=0.5 stream = p.open(format = pyaudio.paInt16, channels = 1, rate = sr, output = True) a=array.array("h") def s(n): if isinstance(n,tuple):return 440*2**(n[0]/12.0),n[1] return 440*2**(n/12.0) for h in map(s,[0,2,3,5,7,7,7,7,(12,0.5),(10,0.5),(12,0.5),(14,0.5),(15,0.5),(14,0.5),(12,0.5),(10,0.5),(7,4)]): if isinstance(h,tuple): h,lm = h else: lm=1 for x in xrange(sr*nl*lm): a.append(int(math.sin(x/float(sr)*h*2*3.141)*32000*(1-(x/float(sr*nl*lm))))) stream.write(a.tostring()) time.sleep(1) stream.close()