def convolve(infile, ir_name, level = 0.5):
""" Apply convolution to infile using impulse response given
Args:
infile (str): Filename
ir_name can be 'smartphone_mic' or 'classroom'
level (float) : can be between 0 and 1, default value = 0.5
"""
fs1, x = monoWavRead(filename=infile)
x = np.copy(x)
#Change the path below for the sounds folder
ir_path = './sounds/ir_{0}.wav'.format(ir_name)
fs2, ir = monoWavRead(filename=ir_path)
y = np.convolve(x, ir, 'full')[0:x.shape[0]] * level + x * (1 - level)
#Change the output file name to suit your requirements here
outfile_name = os.path.basename(infile).split(".")[0] + ("{0}_convolved{1}.wav".format(ir_name, level))
outfile = os.path.join(outfile_path, outfile_name)
write(filename = outfile, rate = fs1, data = y)
if (FILE_DELETION):
extractFeaturesAndDelete(outfile)
评论列表
文章目录