def fast_time_stretch(signals, constant=False, extreme=False): def overlap(tup): framed_signals, frame_step_out = tup new_wav = reconstruction_ops.overlap_and_add(framed_signals, frame_step_out) return tf_get_word(new_wav) if extreme: print("extreme time warp activated") speedx = tf.random_uniform([tf.shape(signals)[0]], 0.7, 1.3) else: speedx = tf.truncated_normal([tf.shape(signals)[0]], 1.0, 0.2) frame_length = 300 frame_step_in = int(300 * 0.25) frame_step_out = tf.cast(speedx * frame_step_in, tf.int32) hann_window = window_ops.hann_window(frame_length) framed_signals = shape_ops.frame(signals, frame_length, frame_step_in, pad_end=False) framed_signals *= hann_window return tf.map_fn(overlap, [framed_signals, frame_step_out], parallel_iterations=120, back_prop=False, dtype=tf.float32)
def test_inverse_stft_window_fn_special_case(self): """Test inverse_stft_window_fn in special overlap = 3/4 case.""" # Cases in which frame_length is an integer multiple of 4 * frame_step are # special because they allow exact reproduction of the waveform with a # squared Hann window (Hann window in both forward and reverse transforms). # In the case where frame_length = 4 * frame_step, that combination # produces a constant gain of 1.5, and so the corrected window will be the # Hann window / 1.5. # Tuples of (frame_length, frame_step). test_configs = [ (256, 64), (128, 32), ] for (frame_length, frame_step) in test_configs: hann_window = window_ops.hann_window(frame_length, dtype=dtypes.float32) inverse_window_fn = spectral_ops.inverse_stft_window_fn(frame_step) inverse_window = inverse_window_fn(frame_length, dtype=dtypes.float32) with self.test_session(use_gpu=True) as sess: hann_window, inverse_window = sess.run( [hann_window, inverse_window]) self.assertAllClose(hann_window, inverse_window * 1.5)
def test_inverse_stft_window_fn(self): """Test that inverse_stft_window_fn has unit gain at each window phase.""" # Tuples of (frame_length, frame_step). test_configs = [ (256, 32), (256, 64), (128, 25), (127, 32), (128, 64), ] for (frame_length, frame_step) in test_configs: hann_window = window_ops.hann_window(frame_length, dtype=dtypes.float32) inverse_window_fn = spectral_ops.inverse_stft_window_fn(frame_step) inverse_window = inverse_window_fn(frame_length, dtype=dtypes.float32) with self.test_session(use_gpu=True) as sess: hann_window, inverse_window = sess.run( [hann_window, inverse_window]) # Expect unit gain at each phase of the window. product_window = hann_window * inverse_window for i in range(frame_step): self.assertAllClose(1.0, np.sum(product_window[i::frame_step]))
def test_inverse_stft_window_fn(self): """Test that inverse_stft_window_fn has unit gain at each window phase.""" # Tuples of (frame_length, frame_step). test_configs = [ (256, 32), (256, 64), (128, 25), (127, 32), (128, 64), ] for (frame_length, frame_step) in test_configs: hann_window = window_ops.hann_window(frame_length, dtype=dtypes.float32) inverse_window_fn = spectral_ops.inverse_stft_window_fn(frame_step) inverse_window = inverse_window_fn(frame_length, dtype=dtypes.float32) with self.test_session(use_gpu=True) as sess: hann_window, inverse_window = sess.run([hann_window, inverse_window]) # Expect unit gain at each phase of the window. product_window = hann_window * inverse_window for i in range(frame_step): self.assertAllClose(1.0, np.sum(product_window[i::frame_step]))
def test_inverse_stft_window_fn_special_case(self): """Test inverse_stft_window_fn in special overlap = 3/4 case.""" # Cases in which frame_length is an integer multiple of 4 * frame_step are # special because they allow exact reproduction of the waveform with a # squared Hann window (Hann window in both forward and reverse transforms). # In the case where frame_length = 4 * frame_step, that combination # produces a constant gain of 1.5, and so the corrected window will be the # Hann window / 1.5. # Tuples of (frame_length, frame_step). test_configs = [ (256, 64), (128, 32), ] for (frame_length, frame_step) in test_configs: hann_window = window_ops.hann_window(frame_length, dtype=dtypes.float32) inverse_window_fn = spectral_ops.inverse_stft_window_fn(frame_step) inverse_window = inverse_window_fn(frame_length, dtype=dtypes.float32) with self.test_session(use_gpu=True) as sess: hann_window, inverse_window = sess.run([hann_window, inverse_window]) self.assertAllClose(hann_window, inverse_window * 1.5)