Esempio n. 1
0
    def test_dither(self):
        test_filepath = common_utils.get_asset_path(
            'steam-train-whistle-daniel_simon.wav')
        waveform, _ = torchaudio.load(test_filepath)

        waveform_dithered = F.dither(waveform)
        waveform_dithered_noiseshaped = F.dither(waveform, noise_shaping=True)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(test_filepath)
        E.append_effect_to_chain("dither", [])
        sox_dither_waveform = E.sox_build_flow_effects()[0]

        torch.testing.assert_allclose(waveform_dithered,
                                      sox_dither_waveform,
                                      atol=1e-04,
                                      rtol=1e-5)
        E.clear_chain()

        E.append_effect_to_chain("dither", ["-s"])
        sox_dither_waveform_ns = E.sox_build_flow_effects()[0]

        torch.testing.assert_allclose(waveform_dithered_noiseshaped,
                                      sox_dither_waveform_ns,
                                      atol=1e-02,
                                      rtol=1e-5)
Esempio n. 2
0
    def test_vctk_transform_pipeline(self):
        test_filepath_vctk = os.path.join(self.test_dirpath,
                                          "assets/VCTK-Corpus/wav48/p224/",
                                          "p224_002.wav")
        wf_vctk, sr_vctk = torchaudio.load(test_filepath_vctk)

        # rate
        sample = T.Resample(sr_vctk,
                            16000,
                            resampling_method='sinc_interpolation')
        wf_vctk = sample(wf_vctk)
        # dither
        wf_vctk = F.dither(wf_vctk, noise_shaping=True)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(test_filepath_vctk)
        E.append_effect_to_chain("gain", ["-h"])
        E.append_effect_to_chain("channels", [1])
        E.append_effect_to_chain("rate", [16000])
        E.append_effect_to_chain("gain", ["-rh"])
        E.append_effect_to_chain("dither", ["-s"])
        wf_vctk_sox = E.sox_build_flow_effects()[0]

        self.assertTrue(
            torch.allclose(wf_vctk, wf_vctk_sox, rtol=1e-03, atol=1e-03))
Esempio n. 3
0
    def test_vctk_transform_pipeline(self):
        test_filepath_vctk = common_utils.get_asset_path(
            'VCTK-Corpus', 'wav48', 'p224', 'p224_002.wav')
        wf_vctk, sr_vctk = torchaudio.load(test_filepath_vctk)

        # rate
        sample = T.Resample(sr_vctk,
                            16000,
                            resampling_method='sinc_interpolation')
        wf_vctk = sample(wf_vctk)
        # dither
        wf_vctk = F.dither(wf_vctk, noise_shaping=True)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(test_filepath_vctk)
        E.append_effect_to_chain("gain", ["-h"])
        E.append_effect_to_chain("channels", [1])
        E.append_effect_to_chain("rate", [16000])
        E.append_effect_to_chain("gain", ["-rh"])
        E.append_effect_to_chain("dither", ["-s"])
        wf_vctk_sox = E.sox_build_flow_effects()[0]

        torch.testing.assert_allclose(wf_vctk,
                                      wf_vctk_sox,
                                      rtol=1e-03,
                                      atol=1e-03)
Esempio n. 4
0
    def test_dither(self):
        waveform_dithered = F.dither(self.waveform_train)
        waveform_dithered_noiseshaped = F.dither(self.waveform_train, noise_shaping=True)

        E = torchaudio.sox_effects.SoxEffectsChain()
        E.set_input_file(self.test_filepath)
        E.append_effect_to_chain("dither", [])
        sox_dither_waveform = E.sox_build_flow_effects()[0]

        self.assertTrue(torch.allclose(waveform_dithered, sox_dither_waveform, atol=1e-04))
        E.clear_chain()

        E.append_effect_to_chain("dither", ["-s"])
        sox_dither_waveform_ns = E.sox_build_flow_effects()[0]

        self.assertTrue(torch.allclose(waveform_dithered_noiseshaped, sox_dither_waveform_ns, atol=1e-02))
 def func(tensor):
     return F.dither(tensor, noise_shaping=True)
 def func(tensor):
     return F.dither(tensor, 'GPDF')
Esempio n. 7
0
 def test_dither_noise(self):
     path = get_asset_path('steam-train-whistle-daniel_simon.wav')
     data, _ = load_wav(path)
     result = F.dither(data, noise_shaping=True)
     self.assert_sox_effect(result, path, ['dither', '-s'], atol=1.5e-4)
Esempio n. 8
0
 def test_dither(self):
     path = get_asset_path('steam-train-whistle-daniel_simon.wav')
     data, _ = load_wav(path)
     result = F.dither(data)
     self.assert_sox_effect(result, path, ['dither'])
Esempio n. 9
0
plt.figure()

#The image is blank?? Probably matplotlib issue
plt.imshow(computed.log2()[0,:,:].detach().numpy(), cmap='gray')
# %%

#Applying gain and dithering

gain_waveform = F.gain(waveform, gain_db=5.0)
print(f'''
Min of gain_waveform: {gain_waveform.min()}
Max of gain_waveform: {gain_waveform.max()}
Mean of gain_waveform: {gain_waveform.mean()}
''')

dither_waveform = F.dither(waveform)
print(f'''
Min of dither_waveform: {dither_waveform.min()}
Max of dither_waveform: {dither_waveform.max()}
Mean of dither_waveform: {dither_waveform.mean()}
''')
# %%

#Applying filters

lowpass_waveform = F.lowpass_biquad(waveform, sample_rate, cutoff_freq=3000)

print(f'''
Min of lowpass_waveform: {lowpass_waveform.min()}
Max of lowpass_waveform: {lowpass_waveform.max()}
Mean of lowpass_waveform: {lowpass_waveform.mean()}