def run(self): # Initialize signals self.percentDoneSignal.emit(0) percent_scale = 1000.0 / 5 self.doneSignal.emit(0) self.statusSignal.emit("") # Load in audio data self.statusSignal.emit("Loading {}".format( os.path.split(self.mix_file)[1])) mix, self.fs = librosa.load(self.mix_file, sr=None) self.percentDoneSignal.emit(1 * percent_scale) self.statusSignal.emit("Loading {}".format( os.path.split(self.source_file)[1])) source, self.fs = librosa.load(self.source_file, sr=self.fs) self.percentDoneSignal.emit(2 * percent_scale) # Fix any gross timing offset self.statusSignal.emit("Aligning...") mix, source = estimate.align(mix, source, self.fs) self.percentDoneSignal.emit(3 * percent_scale) self.statusSignal.emit("Subtracting...") source = estimate.reverse_channel(mix, source) mix, source = estimate.pad(mix, source) self.percentDoneSignal.emit(4 * percent_scale) self.statusSignal.emit("Enhancing...") self.subtracted = estimate.wiener_enhance(mix - source, source, self.wiener_threshold) self.percentDoneSignal.emit(5 * percent_scale) self.doneSignal.emit(1)
def run(self): # Initialize signals self.percentDoneSignal.emit(0) percent_scale = 1000.0 / 5 self.doneSignal.emit(0) self.statusSignal.emit("") # Load in audio data self.statusSignal.emit("Loading {}".format(os.path.split(self.mix_file)[1])) mix, self.fs = librosa.load(self.mix_file, sr=None) self.percentDoneSignal.emit(1 * percent_scale) self.statusSignal.emit("Loading {}".format(os.path.split(self.source_file)[1])) source, self.fs = librosa.load(self.source_file, sr=self.fs) self.percentDoneSignal.emit(2 * percent_scale) # Fix any gross timing offset self.statusSignal.emit("Aligning...") mix, source = estimate.align(mix, source, self.fs) self.percentDoneSignal.emit(3 * percent_scale) self.statusSignal.emit("Subtracting...") source = estimate.reverse_channel(mix, source) mix, source = estimate.pad(mix, source) self.percentDoneSignal.emit(4 * percent_scale) self.statusSignal.emit("Enhancing...") self.subtracted = estimate.wiener_enhance(mix - source, source, self.wiener_threshold) self.percentDoneSignal.emit(5 * percent_scale) self.doneSignal.emit(1)
1) * np.random.randn(n_fft - 1) # Store the errors in the computed fs ratio ratio_errors = np.zeros(len(timit_files)) # Store the RMS of the residual, before and after correction residual_rms = np.zeros(len(timit_files)) original_rms = np.zeros(len(timit_files)) # Process each TIMIT file once for n, filename in enumerate(timit_files): a, fs = librosa.load(timit_files[n], sr=None) # First, filter it a_corrupted = np.convolve(a, random_filters[n]) # Then, skew it a_corrupted = librosa.resample(a_corrupted, 1, fs_ratio_true[n], 'sinc_best') # Zero pad so we can compute the residual RMS now... a, a_corrupted = estimate.pad(a, a_corrupted) original_rms[n] = np.sqrt(np.mean((a - a_corrupted)**2)) # Estimate the skew factor estimated_ratio = estimate.get_best_fs_ratio(a_corrupted, a, .02, 400, int(.05 * a.shape[0]), int(.1 * a.shape[0])) # Compute the relative error of this estimate ratio_errors[n] = np.abs(fs_ratio_true[n] - estimated_ratio) / .04 # Reverse the skew a_corrupted = librosa.resample(a_corrupted, 1, 1.0 / estimated_ratio) a, a_corrupted = estimate.pad(a, a_corrupted) # Compute STFTs A_corrupted = librosa.stft(a_corrupted, n_fft=n_fft, hop_length=n_fft / 4) A = librosa.stft(a, n_fft=256, hop_length=n_fft / 4) A = np.array(A, dtype=np.complex128) A_corrupted = np.array(A_corrupted, dtype=np.complex128)
# Then set h[n] = exp[n]*Normal(0, 1) for n > 0 random_filters[n, 1:] += np.exp( -np.arange( n_fft - 1 ) + 1 )*np.random.randn(n_fft - 1) # Store the errors in the computed fs ratio ratio_errors = np.zeros( len( timit_files ) ) # Store the RMS of the residual, before and after correction residual_rms = np.zeros( len( timit_files ) ) original_rms = np.zeros( len( timit_files ) ) # Process each TIMIT file once for n, filename in enumerate( timit_files ): a, fs = librosa.load( timit_files[n], sr=None ) # First, filter it a_corrupted = np.convolve( a, random_filters[n] ) # Then, skew it a_corrupted = librosa.resample( a_corrupted, 1, fs_ratio_true[n], 'sinc_best' ) # Zero pad so we can compute the residual RMS now... a, a_corrupted = estimate.pad( a, a_corrupted ) original_rms[n] = np.sqrt( np.mean( (a - a_corrupted)**2 ) ) # Estimate the skew factor estimated_ratio = estimate.get_best_fs_ratio(a_corrupted, a, .02, 400, int(.05*a.shape[0]), int(.1*a.shape[0])) # Compute the relative error of this estimate ratio_errors[n] = np.abs( fs_ratio_true[n] - estimated_ratio)/.04 # Reverse the skew a_corrupted = librosa.resample( a_corrupted, 1, 1.0/estimated_ratio ) a, a_corrupted = estimate.pad( a, a_corrupted ) # Compute STFTs A_corrupted = librosa.stft( a_corrupted, n_fft=n_fft, hop_length=n_fft/4 ) A = librosa.stft( a, n_fft=256, hop_length=n_fft/4 ) A = np.array(A, dtype=np.complex128) A_corrupted = np.array(A_corrupted, dtype=np.complex128) # Estimate reverse filter H = estimate.best_filter_coefficients( A, A_corrupted )