本文介绍了我怎样才能生成的注释,或在Python弦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以点我在Python 2.7版产生音符和和弦一个好的图书馆?我已经看了看PythonInfoWiki没有很多的运气,PyAudio刚刚崩溃,没有别的似乎产生音调。

Can anybody point me to a good library for generating notes and chords in python 2.7? I have looked at the PythonInfoWiki without a lot of luck, PyAudio just crashes and nothing else seems to generate tones.

推荐答案

我不知道它是否会有所帮助,但这里的一些code,它synthetizes基础上给出了频率和幅度的复杂的声音:

I don't know if it will help, but here's some code that synthetizes a complex sound based on gives frequencies and 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=[]
    for x in range(datasize):
        samp = 0
        for 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))
    for 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")

这就是code我使用产生蟒蛇音符与和弦。你shold有一个频率列表为第一参数,振幅列表(相同大小作为第一),一个样本数和该文件的名称。它会生成具有给定组合的wav文件。

That's the code i'm using to generate notes and chords in python. You shold have a frequencies list for the first parameter, an amplitude list (same size as the first) , a number of samples and the name of the file. It will generate a wav file with the given combination.

这篇关于我怎样才能生成的注释,或在Python弦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 05:33