audio - How can I generate a note or chord in python? -
can point me library generating notes , chords in python 2.7? have looked @ pythoninfowiki without lot of luck, pyaudio crashes , nothing else seems generate tones.
i don't know if help, here's code synthetizes complex sound based on gives frequencies , amplitudes:
import math import wave import struct def synthcomplex(freq=[440],coef=[1], datasize=10000, fname="test.wav"): frate = 44100.00 amp=8000.0 sine_list=[] x in range(datasize): samp = 0 k in range(len(freq)): samp = samp + coef[k] * math.sin(2*math.pi*freq[k]*(x/frate)) sine_list.append(samp) wav_file=wave.open(fname,"w") nchannels = 1 sampwidth = 2 framerate = int(frate) nframes=datasize comptype= "none" compname= "not compressed" wav_file.setparams((nchannels, sampwidth, framerate, nframes, comptype, compname)) s in sine_list: wav_file.writeframes(struct.pack('h', int(s*amp/2))) wav_file.close() synthcomplex([440,880,1200], [0.4,0.3,0.1], 30000, "tone.wav")
that's code i'm using generate notes , chords in python. shold have frequencies list first parameter, amplitude list (same size first) , number of samples , name of file. generate wav file given combination.
Comments
Post a Comment