def test_highpass(self): cutoff_freq = 2000 sample_rate = 8000 data, path = self.get_whitenoise(sample_rate) result = F.highpass_biquad(data, sample_rate, cutoff_freq) self.assert_sox_effect(result, path, ['highpass', cutoff_freq], atol=1.5e-4)
def digital_filter(waveform, filter_type, sample_rate, cutoff_freq): if filter_type == 'bandpass': waveform = lowpass_biquad(waveform=waveform, sample_rate=sample_rate, cutoff_freq=max(cutoff_freq), Q=1) waveform = highpass_biquad(waveform=waveform, sample_rate=sample_rate, cutoff_freq=min(cutoff_freq), Q=1) elif filter_type == 'lowpass': waveform = lowpass_biquad(waveform=waveform, sample_rate=sample_rate, cutoff_freq=max(cutoff_freq), Q=1) elif filter_type == 'highpass': waveform = highpass_biquad(waveform=waveform, sample_rate=sample_rate, cutoff_freq=min(cutoff_freq), Q=1) return waveform
def test_highpass(self): """ Test biquad highpass filter, compare to SoX implementation """ cutoff_freq = 2000 noise_filepath = common_utils.get_asset_path('whitenoise.wav') E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(noise_filepath) E.append_effect_to_chain("highpass", [cutoff_freq]) sox_output_waveform, sr = E.sox_build_flow_effects() waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True) output_waveform = F.highpass_biquad(waveform, sample_rate, cutoff_freq) # TBD - this fails at the 1e-4 level, debug why self.assertEqual(output_waveform, sox_output_waveform, atol=1e-3, rtol=1e-5)
def test_highpass(self): """ Test biquad highpass filter, compare to SoX implementation """ CUTOFF_FREQ = 2000 noise_filepath = os.path.join(self.test_dirpath, "assets", "whitenoise.mp3") E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(noise_filepath) E.append_effect_to_chain("highpass", [CUTOFF_FREQ]) sox_output_waveform, sr = E.sox_build_flow_effects() waveform, sample_rate = torchaudio.load(noise_filepath, normalization=True) output_waveform = F.highpass_biquad(waveform, sample_rate, CUTOFF_FREQ) # TBD - this fails at the 1e-4 level, debug why assert torch.allclose(sox_output_waveform, output_waveform, atol=1e-3)
def test_highpass(self): """ Test biquad highpass filter, compare to SoX implementation """ cutoff_freq = 2000 E = torchaudio.sox_effects.SoxEffectsChain() E.set_input_file(self.noise_filepath) E.append_effect_to_chain("highpass", [cutoff_freq]) sox_output_waveform, sr = E.sox_build_flow_effects() output_waveform = F.highpass_biquad(self.noise_waveform, self.NOISE_SAMPLE_RATE, cutoff_freq) self.assertEqual(output_waveform, sox_output_waveform, atol=1.5e-3, rtol=1e-5)
def func(tensor): sample_rate = 44100 cutoff_freq = 2000. return F.highpass_biquad(tensor, sample_rate, cutoff_freq)
print( f"Min of lowpass_waveform: {lowpass_waveform.min()}\nMax of lowpass_waveform: " f"{lowpass_waveform.max()}\nMean of lowpass_waveform: {lowpass_waveform.mean()}") pyplot.figure() pyplot.plot(lowpass_waveform.t().numpy()) # %% md ''' We can also visualize a waveform with the highpass biquad filter. ''' # %% highpass_waveform = highpass_biquad(waveform, sample_rate, cutoff_freq=2000) print( f"Min of highpass_waveform: {highpass_waveform.min()}\nMax of highpass_waveform: " f"{highpass_waveform.max()}\nMean of highpass_waveform: {highpass_waveform.mean()}") pyplot.figure() pyplot.plot(highpass_waveform.t().numpy()) # %% md ''' Migrating to torchaudio from Kaldi ---------------------------------- Users may be familiar with `Kaldi <http://github.com/kaldi-asr/kaldi>`_, a toolkit for speech