0
我想用創建numpy的sounddevice錄製音調並將其寫入wav文件。這裏是代碼:在python3中使用sounddevice和numpy編寫wav文件
import numpy
import sounddevice as sd
import soundfile as sf
import sys
duration = 3
amplitude = 0.3
sampling_frequency = 44100
time = numpy.arange(int(numpy.ceil(duration * sampling_frequency)))/ sampling_frequency
frequency1 = 500
tone1 = amplitude * numpy.sin(2* numpy.pi * frequency1 * time)
frequency2 = 700
tone2 = amplitude * numpy.sin(2* numpy.pi * frequency1 * time)
frequency3 = 1500
tone3 = amplitude * numpy.sin(3* numpy.pi * frequency1 * time)
frequency4 = 400
tone4 = amplitude * numpy.sin(4* numpy.pi * frequency1 * time)
result = tone1
result2 = tone2
result3 = tone3
result4 = tone4
sd.play(result + result2 + result3 + result4, sampling_frequency)
filename = 'output.wav'
mydata = sd.rec(int(result + result2 + result3 + result4),sampling_frequency,channels=2, blocking=True)
sf.write(filename, mydata, sampling_frequency)
我得到這個錯誤:只有長度爲1的陣列可以轉換到Python標量 有什麼不好的代碼?我與蟒蛇一個新手
如果添加了完整的錯誤消息,這將是有益的,因爲它規定了哪些生產線成品率錯誤。 – Coolness