def test_overlap_add_simple(self): """ Tests running the OverlapAdd method with default settings for everything. Does not check output. """ for i, method in enumerate(self.valid_methods): ola = nussl.OverlapAdd(self.signal, method) ola.run() bk, fg = ola.make_audio_signals()
def test_overlap_add_properties(self): """ Tests to make sure the properties are set correctly. """ assert sorted(nussl.OverlapAdd.valid_separation_methods()) == sorted(self.valid_methods) assert sorted(nussl.OverlapAdd.valid_separation_method_names()) == sorted(self.valid_method_names) for i, method in enumerate(self.valid_methods): ola = nussl.OverlapAdd(self.signal, method) assert ola.separation_method == method assert ola.separation_method_name == self.valid_method_names[i] assert type(ola.separation_instance) == method for i, method in enumerate(self.invalid_methods): ola = nussl.OverlapAdd(self.signal, nussl.Repet) with self.assertRaises(ValueError): ola.separation_method = method with self.assertRaises(ValueError): ola.separation_method = self.invalid_method_names[i]
def test_overlap_add_setup(self): """ Test setting up the OverlapAdd class in various different ways. """ # Test valid methods for method in self.valid_methods: ola1 = nussl.OverlapAdd(self.signal, method) ola2 = nussl.OverlapAdd(self.signal, method.__name__) assert ola1.separation_method == ola2.separation_method == method instance = method(self.signal) assert type(ola1.separation_instance) == type( ola2.separation_instance) == type(instance) # These special cases should work too ola = nussl.OverlapAdd(self.signal, 'r-e-p*-e-t!@#') assert ola.separation_method == nussl.Repet ola = nussl.OverlapAdd(self.signal, 'repet_sim') assert ola.separation_method == nussl.RepetSim # 'repet_sim' is misspelled --> raise error with self.assertRaises(ValueError): ola = nussl.OverlapAdd(self.signal, 'repe_sim') assert ola.separation_method == nussl.RepetSim # Test invalid methods for method in self.invalid_methods: with self.assertRaises(ValueError): ola = nussl.OverlapAdd(self.signal, method) # Test invalid method names for method in self.invalid_method_names: with self.assertRaises(ValueError): ola = nussl.OverlapAdd(self.signal, method) # Test that variables are stored correctly params = nussl.StftParams(nussl.DEFAULT_SAMPLE_RATE) params.window_length = 4096 params.hop_length = params.window_length // 4 self.signal.stft_params = params for method in self.valid_methods: ola = nussl.OverlapAdd(self.signal, method, use_librosa_stft=False) assert ola.separation_instance.stft_params == params assert ola.separation_instance.audio_signal == self.signal assert ola.separation_instance.audio_signal.path_to_input_file == self.signal.path_to_input_file
evaluate(evaluation, sources, 'REPET') repet_sim = nussl.RepetSim(mixture) repet_sim.run() sources = repet_sim.make_audio_signals() evaluate(evaluation, sources, 'REPET-SIM') ft2d = nussl.FT2D(mixture) ft2d.run() sources = ft2d.make_audio_signals() evaluate(evaluation, sources, 'FT2D') overlap_add = nussl.OverlapAdd(mixture, separation_method='REPET', hop_size=5, window_size=10) overlap_add.run() sources = overlap_add.make_audio_signals() evaluate(evaluation, sources, 'Overlap-Add: REPET') overlap_add.separation_method = 'FT2D' overlap_add.run() sources = overlap_add.make_audio_signals() evaluate(evaluation, sources, 'Overlap-Add: FT2D') evaluation.write_scores_to_file('output/evaluation.json')
pad_length = (audio.shape[-1] / 1024.0 % 1) * 1024 audio = np.pad(np.array(audio), (0, int(pad_length)), 'constant', constant_values=(0, 0)) audio_signal = nussl.AudioSignal(audio_data_array=audio, sample_rate=sr) audio_signal.stft_params.hop_length = 1024 audio_signal.stft_params.n_fft_bins = 4096 audio_signal.stft_params.window_length = 4096 return audio_signal mixture = load_audio('../input/mixture.wav') # mixture = load_audio('../Input/Sample1.wav') mixture = nussl.AudioSignal('../Input/Sample1.wav') overlap_add = nussl.OverlapAdd(mixture, separation_method='RepetSim', overlap_window_size=2) overlap_add.run() bg, fg = overlap_add.make_audio_signals() fg.write_audio_to_file('foreground_repet.wav') bg.write_audio_to_file('background_repet.wav') """ overlap_add = nussl.OverlapAdd(mixture, separation_method = 'REPET-SIM') overlap_add.run() bg, fg = overlap_add.make_audio_signals() fg.write_audio_to_file('foreground_repet_sim.wav') bg.write_audio_to_file('background_repet_sim.wav') repet_sim = nussl.RepetSim(mixture) repet_sim.run() bg, fg = repet_sim.make_audio_signals()