DURATION = 5 # 秒 def generate_sine_wave(freq, sample_rate, duration): x = np.linspace(0, duration, sample_rate * duration, endpoint=False) frequencies = x * freq y = np.sin((2 * np.pi) * frequencies) return x, y # 产生持续5秒的2赫兹正弦波 x, y = generate_sine_wave(2, S...
# generate the sine wave new_wave = [np.sin(2 * np.pi * frequency * x/sampling_rate) + np.sin(2 * np.pi * frequency1 * x/sampling_rate) for x in range(num_samples * play_time)] writeWave(new_wave) def createWave(frequency, frequency1, wave_type, play_time): if wave_type...
1 正玄波信号函数: def createSine(frequency, play_time): # generate the sine wave new_wave = [np.sin(2 * np.pi * frequency * x/sampling_rate) for x in range(num_samples * play_time)] writeWave(new_wave) 2方波信号函数: def createSquare(frequency, play_time): new_wave = [signal...
如果没有安装,可以通过以下命令安装:## ```bash# pip install numpy matplotlib# ```## ### Python代码示例## ```pythonimportnumpy as npimportmatplotlib.pyplot as plt# 生成一个简单的正弦波信号def generate_sine_wave(frequency, duration, sampling_rate): t=np.linspace(0, duration, int(sampling_ra...
num_samples= 48000sampling_rate= 48000.0amplitude= 16000comptype='NONE'compname='not compressed'nchannels= 1sampwidth= 2FILE_NAME=''defcreateSine(frequency,frequency1,play_time):#generate the sine wavenew_wave = [np.sin(2 * np.pi * frequency * x/sampling_rate) + np.sin(2 * np.pi *...
num_samples=48000sampling_rate=48000.0amplitude=16000comptype='NONE'compname='not compressed'nchannels=1sampwidth=2FILE_NAME=''defcreateSine(frequency,frequency1,play_time):# generate the sine wave new_wave=[np.sin(2*np.pi*frequency*x/sampling_rate)+np.sin(2*np.pi*frequency1*x/sampling_rat...
x, y = generate_sine_wave(2, SAMPLE_RATE, DURATION) plt.plot(x, y) plt.show() x轴以秒为单位表示时间,并且由于每秒钟的时间都有两个峰值,因此可以看到正弦波每秒振荡两次。 混合音频 下面将两个正弦波,混合音频信号仅包括两个步骤: 将正弦波加在一起,然后进行归一化的操作。
import wave,math from winsound import PlaySound,SND_FILENAME def generate(T,total,volume,sine=False):# T: 周期, total 总长度, 都以帧为单位ifnot sine:h= T /2foriinrange(total):ifi % T >=h: yield volumeelse: yield0else:# 计算方法: sin 的 T = 2*pi / ww =2* math.pi / T...
if __name__ == "__main__":print('简易波形⽣成器')filename = input('请输⼊⽤于保存波形的⽂件名: ')frequency = int(input('正弦波的声⾳频率(单位:赫兹):'))duration = float(input('持续时间()单位:秒: '))generateSineWaveFile(filename, 48000, frequency, duration)
# Generate wave form forxinrange(-90,90): y=math.sin(math.radians(x)) t.goto(x,y) 输出: 注:本文由VeryToolz翻译自Draw a Sine wave using Turtle in Python,非经特殊声明,文中代码和图片版权归原作者sivapriyanka4560所有,本译文的传播和使用请遵循“署名-相同方式共享 4.0 国际 (CC BY-SA 4.0...