def synth_audio(audiofile, impfile, chns, angle, nsfile=None, snrlevel=None, outname=None, outsplit=False):
FreqSamp, audio = wavfile.read(audiofile)
audio = audio.astype(np.float32)/np.amax(np.absolute(audio.astype(np.float32)))
gen_audio = np.zeros((audio.shape[0], chns), dtype=np.float32)
for ch in range(1,chns+1):
impulse = np.fromfile('{}D{:03d}_ch{}.flt'.format(impfile, angle, ch), dtype=np.float32)
gen_audio[:,ch-1] = np.convolve(audio, impulse, mode='same')
gen_audio = add_noise(gen_audio, nsfile=nsfile, snrlevel=snrlevel)
if outname is None:
return FreqSamp, np.transpose(gen_audio)
if outsplit:
for ch in range(chns):
play_data = audiolab.wavwrite(gen_audio[:,ch],'{}_ch{:02d}.wav'.format(outname,ch), fs=FreqSamp, enc='pcm16')
return
else:
play_data = audiolab.wavwrite(gen_audio,'{}.wav'.format(outname), fs=FreqSamp, enc='pcm16')
return
评论列表
文章目录