生成简单的复调和旋律
tones的Python项目详细描述
音调
一个纯python模块,用于生成简单的音调作为音频样本,它可以 可以选择直接写入.wav音频文件。支持节距弯曲, 振动,复调,几种波形类型(正弦,正方形,三角形, 锯齿),以及其他一些波形成形选项。
安装
从pypi存储库安装:
pip install tones
示例
fromtonesimportSINE_WAVE,SAWTOOTH_WAVEfromtones.mixerimportMixer# Create mixer, set sample rate and amplitudemixer=Mixer(44100,0.5)# Create two monophonic tracks that will play simultaneously, and set# initial values for note attack, decay and vibrato frequency (these can# be changed again at any time, see documentation for tones.Mixermixer.create_track(0,SAWTOOTH_WAVE,vibrato_frequency=7.0,vibrato_variance=30.0,attack=0.01,decay=0.1)mixer.create_track(1,SINE_WAVE,attack=0.01,decay=0.1)# Add a 1-second tone on track 0, slide pitch from c# to f#)mixer.add_note(0,note='c#',octave=5,duration=1.0,endnote='f#')# Add a 1-second tone on track 1, slide pitch from f# to g#)mixer.add_note(1,note='f#',octave=5,duration=1.0,endnote='g#')# Mix all tracks into a single list of samples and write to .wav filemixer.write_wav('tones.wav')# Mix all tracks into a single list of samples scaled from 0.0 to 1.0, and# return the sample listsamples=mixer.mix()
文档
完整的api文档在这里:https://tones.readthedocs.io