Beispiel #1
0
    def concatenateMagPhaseEpoch(self, path, fname, fzero=np.zeros(0)):

        print path
        print fzero
        print '------'
        mag = self.mp_mag[path,:] 
        imag = self.mp_imag[path,:] 
        real = self.mp_real[path,:] 
        fz = self.mp_fz[path,:].reshape((-1,1))

        if fzero.size > 0:
            fz = fzero

        # import pylab
        # pylab.plot(mag)
        # pylab.show()
        # sys.exit('aevsdb0000s')

        syn_wave = magphase.synthesis_from_lossless(mag, real, imag, fz, 48000)
        la.write_audio_file(fname, syn_wave, 48000)
    b_plots = True  # True if you want to plot the extracted parameters.

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

    # ANALYSIS:
    print("Analysing.....................................................")
    m_mag, m_real, m_imag, v_f0, fs, v_shift = mp.analysis_lossless(
        wav_file_orig)

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

    # SYNTHESIS:
    print("Synthesising.................................................")
    v_syn_sig = mp.synthesis_from_lossless(m_mag, m_real, m_imag, v_f0, fs)

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

    # PLOTS:===============================================================================
    if b_plots:
        plots(m_mag, m_real, m_imag, v_f0)
        raw_input("Press Enter to close de figs and finish...")
        lp.close('all')

    print('Done!')
    b_plots       = True # True if you want to plot the extracted parameters.

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

    # ANALYSIS:
    print("Analysing.....................................................")
    m_mag, m_real, m_imag, v_f0, fs, v_shift = mp.analysis_lossless(wav_file_orig)

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

    # SYNTHESIS:
    print("Synthesising.................................................")
    v_syn_sig = mp.synthesis_from_lossless(m_mag, m_real, m_imag, v_f0, fs)

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

    # PLOTS:===============================================================================
    if b_plots:
        plots(m_mag, m_real, m_imag, v_f0)
        raw_input("Press Enter to close de figs and finish...")
        lp.close('all')

    print('Done!')

Beispiel #4
0
    def concatenateMagPhaseEpoch_sep_files(self, path, fname, fzero=np.zeros(0), overlap=0):
        assert overlap % 2 == 0, 'frame overlap should be even number'

        multiepoch = self.config.get('multiepoch', 1)
        nframes = len(path) * multiepoch
        nframes += overlap ## beginning and ending fade in and out -- can trim these after

        mag = np.zeros((nframes, FFTHALFLEN))
        real = np.zeros((nframes, FFTHALFLEN))
        imag = np.zeros((nframes, FFTHALFLEN))
        fz = np.zeros((nframes, 1))
        vuv = np.zeros((nframes, 1))

        write_start = 0
        OFFSET = 0
        for ix in path:

            write_end = write_start + multiepoch + overlap
            (mag_frag, real_frag, imag_frag, fz_frag, vuv_frag) = self.retrieve_magphase_frag(ix, extra_frames=overlap/2)
            mag[write_start:write_end, :] += mag_frag
            real[write_start:write_end, :] += real_frag
            imag[write_start:write_end, :] += imag_frag
            #fz[write_start+(overlap/2):write_end-(overlap/2), :] += fz_frag[(overlap/2):-(overlap/2),:]
            fz[write_start:write_end, :] += fz_frag

            if 0:
                import pylab
                this_fz = np.zeros((nframes, 1))
                this_fz[write_start:write_end, :] += fz_frag
                pylab.plot(this_fz + OFFSET)
                OFFSET += 100

            vuv[write_start:write_end, :] += vuv_frag

            write_start += multiepoch

        if 0:
            pylab.show()
            sys.exit('sdcn89v9egvb')

        ## trim beginning fade in and end fade out:
        if overlap > 0:
            taper = overlap / 2
            mag = mag[taper:-taper, :]
            real = real[taper:-taper, :]
            imag = imag[taper:-taper, :]
            fz = fz[taper:-taper, :]
            vuv = vuv[taper:-taper, :]

        if fzero.size > 0:
            fz = fzero
        else:
            unvoiced = np.where(vuv < 0.5)[0]
            fz[unvoiced, :] = 0.0

        if 0:
            import pylab
            pylab.imshow( mag)
            pylab.show()



        if 0:
            import pylab
            pylab.plot(fz)
            pylab.show()
            sys.exit('evevwev9999')

        sample_rate = self.config.get('sample_rate', 48000)
        syn_wave = magphase.synthesis_from_lossless(mag, real, imag, fz, sample_rate)
        la.write_audio_file(fname, syn_wave, sample_rate)