我正在嘗試使用440hz到600hz的音調編寫音頻文件。該文件應該從440hz開始,然後播放每個頻率(按遞增順序)1秒,結束於600hz。我已經提出了python的wave模塊,但是我在這裏做了一些錯誤,因爲我最終沒有聲音的文件。 (如果有人有更好的建議,我真的不在乎它是否在Python中,我使用的是Linux,任何能在該平臺上工作的東西都可以,我只需要創建一個具有上述規格的音頻文件。 !THX)如何編寫多頻音頻文件?
frequencies = range(440,600)
data_size = len(frequencies)
fname = "WaveTest.wav"
frate = 11025.0 # framerate as a float
amp = 64000.0 # multiplier for amplitude
sine_list_x = []
for f in frequencies:
for x in range(data_size):
sine_list_x.append(math.sin(2*math.pi*f*(x/frate)))
wav_file = wave.open(fname, "w")
nchannels = 1
sampwidth = 2
framerate = int(frate)
nframes = data_size
comptype = "NONE"
compname = "not compressed"
wav_file.setparams((nchannels, sampwidth, framerate, nframes,
comptype, compname))
for s in sine_list_x:
# write the audio frames to file
wav_file.writeframes(struct.pack('h', int(s*amp/2)))
wav_file.close()