How to use the librosa.istft function in librosa

To help you get started, we’ve selected a few librosa examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ghunkins / Voice-Denoising-AN / SEGAN_test / src / utils / data_utils.py View on Github external
c_phase = P_clean[i, :, :, 0]
        n_phase = P_noisy[i, :, :, 0]
        # re-compute the complex
        c_gen = gen * np.exp(n_phase * 1j)
        c_noisy = noisy * np.exp(n_phase * 1j)
        c_clean = clean * np.exp(c_phase * 1j)
        # transform from (256, 256) --> (257, 256)
        c_gen = np.append(np.zeros((1, 256)), c_gen, axis=0)
        c_noisy = np.append(np.zeros((1, 256)), c_noisy, axis=0)
        c_clean = np.append(np.zeros((1, 256)), c_clean, axis=0)
        # open files, compute ISTFT, and write WAV
        f_gen = open(dir_i + '/{}_{}_gen{}.wav'.format(X_str[i], suffix, str(i)), 'w')
        f_noisy = open(dir_i + '/{}_{}_noisy{}.wav'.format(X_str[i], suffix, str(i)), 'w')
        f_clean = open(dir_i + '/{}_{}_clean{}.wav'.format(X_str[i], suffix, str(i)), 'w')
        y_gen = librosa.istft(c_gen, hop_length=noverlap, win_length=nperseg, window="hamming")
        y_noisy = librosa.istft(c_noisy, hop_length=noverlap, win_length=nperseg, window="hamming")
        y_clean = librosa.istft(c_clean, hop_length=noverlap, win_length=nperseg, window="hamming")
        write(f_gen, 16000, y_gen)
        write(f_noisy, 16000, y_noisy)
        write(f_clean, 16000, y_clean)
        # save figures in log format
        plt.pcolormesh(np.log10(gen), cmap="gnuplot2")
        plt.colorbar()
        plt.savefig(dir_i + '/{}_{}_gen{}.png'.format(X_str[i], suffix, str(i)))
        plt.clf()
        plt.pcolormesh(np.log10(noisy), cmap="gnuplot2")
        plt.colorbar()
        plt.savefig(dir_i + '/{}_{}_noisy{}.png'.format(X_str[i], suffix, str(i)))
        plt.clf()
        plt.pcolormesh(np.log10(clean), cmap="gnuplot2")
        plt.colorbar()
        plt.savefig(dir_i + '/{}_{}_clean{}.png'.format(X_str[i], suffix, str(i)))
github leimao / Singing_Voice_Separation_RNN / evaluate.py View on Github external
print('Processing %s ...' % wav_filename_base)

        stft_mono_magnitude, stft_mono_phase = sperate_magnitude_phase(data = stft_mono_full)
        stft_mono_magnitude = np.array([stft_mono_magnitude])

        y1_pred, y2_pred = model.test(x = stft_mono_magnitude)

        # ISTFT with the phase from mono
        y1_stft_hat = combine_magnitdue_phase(magnitudes = y1_pred[0], phases = stft_mono_phase)
        y2_stft_hat = combine_magnitdue_phase(magnitudes = y2_pred[0], phases = stft_mono_phase)

        y1_stft_hat = y1_stft_hat.transpose()
        y2_stft_hat = y2_stft_hat.transpose()

        y1_hat = librosa.istft(y1_stft_hat, hop_length = hop_length)
        y2_hat = librosa.istft(y2_stft_hat, hop_length = hop_length)

        librosa.output.write_wav(wav_mono_filepath, wav_mono, mir1k_sr)
        librosa.output.write_wav(wav_src1_hat_filepath, y1_hat, mir1k_sr)
        librosa.output.write_wav(wav_src2_hat_filepath, y2_hat, mir1k_sr)
github jjery2243542 / adaptive_voice_conversion / preprocess / tacotron / utils.py View on Github external
def invert_spectrogram(spectrogram):
    '''
    spectrogram: [f, t]
    '''
    return librosa.istft(spectrogram, hp.hop_length, win_length=hp.win_length, window="hann")
github eigenfoo / modo-de-ambar / mini_canne / mini_canne.py View on Github external
(np.power(len_window, 2) / np.log(relative_height))
    scale_constant_6 = (hop_length_ * M_freqs) / (-2 * freq_time_ratio)

    # This is Equation 6 from the paper, which requires no look-ahead frames
    for ii in range(1, M_freqs - 1):
        recon_phase_der[ii,
                        :] = scale_constant_6 * (log_mag[ii + 1,
                                                         :] - log_mag[ii - 1,
                                                                      :]) + (pie * hop_length_ * ii / (M_freqs))
    for jj in range(1, N_frames - 1):
        bins_to_randomize = mag[:, jj] == threshold
        recon_phase_output[:, jj] = recon_phase_output[:, jj - 1] + \
            0.5 * (recon_phase_der[:, jj - 1] + recon_phase_der[:, jj])
        #recon_phase_output[bins_to_randomize,jj] = np.random.uniform(low=0,high=2*pie,size=np.shape(log_mag[mag[:,jj]==threshold,jj]))
    E = mag * np.exp(1j * recon_phase_output)
    return librosa.istft(E, hop_length=hop_length_)
github CorentinJ / Real-Time-Voice-Cloning / synthesizer / audio.py View on Github external
def _istft(y, hparams):
    return librosa.istft(y, hop_length=get_hop_size(hparams), win_length=hparams.win_size)
github tsurumeso / vocal-remover / lib / spec_utils.py View on Github external
def spec_to_wav(mag, phase, hop_length):
    spec = mag * phase
    spec_left = np.asfortranarray(spec[0])
    spec_right = np.asfortranarray(spec[1])
    wav_left = librosa.istft(spec_left, hop_length=hop_length)
    wav_right = librosa.istft(spec_right, hop_length=hop_length)
    wav = np.asfortranarray([wav_left, wav_right])

    return wav
github diggerdu / Mendelssohn / rnn / validate_rnn.py View on Github external
saver.restore(sess, './checkpoint/mlp_model_0')

low_band = input_data[::,:n_input]                                            
print low_band.shape
low_band_input = np.asarray([low_band[i-n_step:i] for i in range(n_step, low_band.shape[0]+1)])
print low_band_input.shape
high_band = sess.run(logits, feed_dict = {x:low_band_input})                                    
a = np.hstack((np.expm1(low_band[n_step-1:]*12.0), np.expm1(high_band*8.0))).T                             
print np.max(a)                                                                                 
p = 2 * np.pi * np.random.random_sample(a.shape) - np.pi                                        
#print p.shape    
import librosa
import scipy.io.wavfile as wave
for i in range(500):                                                                            
    S = a * np.exp(1j*p)                                                                        
    X = librosa.istft(S)                                                                        
    print np.max(X)                                                                             
    p = np.angle(librosa.stft(X, 1024))                                                         
                                                                                                
    OUTPUT_PATH = './data/spring_16k_recon.wav'                                                     
np.save('fallback.npy',X)                                                                       
wave.write(OUTPUT_PATH, 16000, X.T.astype(np.int16))
github andabi / parallel-wavenet-vocoder / audio.py View on Github external
phase : np.ndarray [shape=(1 + n_fft/2, t)]
        Initial phase spectrogram.

    Returns
    -------
    wav : np.ndarray [shape=(n,)]
        The real-valued waveform.

    """
    assert (num_iters > 0)
    if phase is None:
        phase = np.pi * np.random.rand(*mag.shape)
    stft = mag * np.exp(1.j * phase)
    wav = None
    for i in range(num_iters):
        wav = librosa.istft(stft, win_length=win_length, hop_length=hop_length)
        if i != num_iters - 1:
            stft = librosa.stft(wav, n_fft=n_fft, win_length=win_length, hop_length=hop_length)
            _, phase = librosa.magphase(stft)
            phase = np.angle(phase)
            stft = mag * np.exp(1.j * phase)
    return wav
github IMLHF / Real-Time-Voice-Cloning / synthesizer / audio.py View on Github external
def _istft(y, hparams):
    return librosa.istft(y, hop_length=get_hop_size(hparams), win_length=hparams.win_size)