Ejemplo n.º 1
0
def synthesis(base, feature_dir='', output_dir='', fft_len=2048, nbins_mel=60, nbins_phase=45, fs=48000):

    m_mag_mel_log = lu.read_binfile(os.path.join(feature_dir, 'mag', base+'.mag'), dim=nbins_mel)
    m_real_mel = lu.read_binfile(os.path.join(feature_dir, 'real', base+'.real'), dim=nbins_phase)
    m_imag_mel = lu.read_binfile(os.path.join(feature_dir, 'imag', base+'.imag'), dim=nbins_phase)
    v_lf0 = lu.read_binfile(os.path.join(feature_dir, 'lf0', base+'.lf0'), dim=1)

    try:
        v_syn_sig = mp.synthesis_from_compressed(m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0, fs, fft_len)
        wav_file_syn = os.path.join(output_dir, base+'.wav')
        la.write_audio_file(wav_file_syn, v_syn_sig, fs)
        print 'written %s'%(wav_file_syn)
    except:
        print 'synth failed for %s'%(base)
Ejemplo n.º 2
0
    print("Analysing.....................................................")
    m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0_smth, v_shift, fs, fft_len = mp.analysis_compressed(
        wav_file_orig,
        mag_dim=mag_dim,
        phase_dim=phase_dim,
        b_const_rate=b_const_rate)

    # MODIFICATIONS:
    # You can modify the parameters here if wanted.

    # SYNTHESIS:
    print("Synthesising.................................................")
    v_syn_sig = mp.synthesis_from_compressed(m_mag_mel_log,
                                             m_real_mel,
                                             m_imag_mel,
                                             v_lf0_smth,
                                             fs,
                                             b_const_rate=b_const_rate,
                                             b_out_hpf=False)

    # SAVE WAV FILE:
    print("Saving wav file..............................................")
    wav_file_syn = out_dir + '/' + lu.get_filename(wav_file_orig) + (
        '_copy_syn_low_dim_mag_dim_%d_ph_dim_%d_const_rate_%d.wav' %
        (mag_dim, phase_dim, b_const_rate))
    la.write_audio_file(wav_file_syn, v_syn_sig, fs)

    # PLOTS:===============================================================================
    if b_plots:
        plots(m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0_smth)
        raw_input("Press Enter to close de figs and finish...")
    b_plots = True  # True if you want to plot the extracted parameters.

    # PROCESS:============================================================================
    lu.mkdir(out_dir)

    # ANALYSIS:
    print("Analysing.....................................................")
    m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0, v_shift, fs, fft_len = mp.analysis_compressed(
        wav_file_orig)

    # MODIFICATIONS:
    # You can modify the parameters here if wanted.

    # SYNTHESIS:
    print("Synthesising.................................................")
    v_syn_sig = mp.synthesis_from_compressed(m_mag_mel_log, m_real_mel,
                                             m_imag_mel, v_lf0, fs, fft_len)

    # SAVE WAV FILE:
    print("Saving wav file..............................................")
    wav_file_syn = out_dir + '/' + lu.get_filename(
        wav_file_orig) + '_copy_syn_low_dim.wav'
    la.write_audio_file(wav_file_syn, v_syn_sig, fs)

    # PLOTS:===============================================================================
    if b_plots:
        plots(m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0)
        raw_input("Press Enter to close de figs and finish...")
        lp.close('all')

    print('Done!')