国际足联世界排名搜索引擎优化免费
一、概述
本节我们使用python代码模拟啸叫的产生。
二、数据仿真
2.1 仿真流程图
2.2 仿真代码
#!/usr/bin/python
from __future__ import division
# importimport numpy as np
import matplotlib.pyplot as plt
import soundfile as sfdef simulate_howling_env():input_file = "test/LDC93S6A.wav"howling_file = "test/added_howling.wav"# load clean speech filex, Srate = sf.read(input_file)# pre design a room impulse responserir = np.loadtxt('test/path.txt', delimiter='\t')# G : gain from mic to speakerG = 0.2# ====== set parameters ========interval = 0.02 # frame interval = 0.02sSlen = int(np.floor(interval * Srate))if Slen % 2 == 1:Slen = Slen + 1PERC = 50 # window overlap in percent of frame sizelen1 = int(np.floor(Slen * PERC / 100))len2 = int(Slen - len1)nFFT = 2 * SlenN = min(2000, len(rir)) # limit room impulse response lengthx2 = np.zeros(N) # buffer N samples of speaker output to generate acoustic feedbacky = np.zeros(len(x)) # save speaker output to yy1 = 0.0 # init as 0for i in range(len(x)):x1 = x[i] + y1y[i] = G * x1y[i] = min(2, y[i]) # amplitude clippingy[i] = max(-2, y[i])x2[1:] = x2[:N - 1]x2[0] = y[i]y1 = np.dot(x2, rir[:N])sf.write(howling_file, y, Srate)plt.figure()plt.subplot(2, 1, 1)plt.plot(y)plt.xlim((0, len(y)))plt.subplot(2, 1, 2)plt.specgram(y, NFFT=nFFT, Fs=Srate, noverlap=len2, cmap='jet')plt.ylim((0, 5000))plt.ylabel("Frquency (Hz)")plt.xlabel("Time (s)")plt.show()simulate_howling_env()
2.3 原始数据
2.4 生成的啸叫数据
三、总结
本节我们使用代码对啸叫的产生进行了仿真,以方便对算法进行验证。