这是我的工作。
import matplotlib.pyplot as plot
import numpy as num
def xr(start, stop, step):
while start < stop:
yield start
start = start + step
wavef = lambda x: num.sin(x)/x
t0 = [wavef(x) for x in xr(5.0,200.0,0.1) if x is not 0]
plot.plot(t0)
plot.show()
最佳答案
Python 有一个 波模块 wave — Read and write WAV files .
这里给出了如何使用它将函数数据写入 wav 文件的示例,
Create a synthetic 'sine wave' wave file和 How to make a simple .wav file with Python .
您也可以使用 Audiolab .
由于您已经在使用 numpy,您可以使用 numpy.linspace或 numpy.arange而不是你的 xr 函数。就像是,
x = num.arange( 5.0, 200.0, 0.1 )
wavef = num.sin(x)/x
关于python - 我需要转换成波形文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6556192/