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)
def synthesis(in_feats_dir, filename_token, out_syn_dir, nbins_mel, nbins_phase, mvf, fs, fft_len, b_postfilter): print('\nGenerating wavefile: ' + filename_token + '................................') # Reading parameter files: m_mag_mel_log = lu.read_binfile(in_feats_dir + '/' + filename_token + '.mag' , dim=nbins_mel) m_real_mel = lu.read_binfile(in_feats_dir + '/' + filename_token + '.real', dim=nbins_phase) m_imag_mel = lu.read_binfile(in_feats_dir + '/' + filename_token + '.imag', dim=nbins_phase) v_lf0 = lu.read_binfile(in_feats_dir + '/' + filename_token + '.lf0' , dim=1) if b_postfilter: m_mag_mel_log = mp.post_filter(m_mag_mel_log) # Waveform generation: v_syn_sig = mp.synthesis_with_del_comp_and_ph_encoding5(m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0, fft_len, fs, mvf, f0_type='lf0') la.write_audio_file(out_syn_dir + '/' + filename_token + '.wav', v_syn_sig, fs) return
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!')
#nx_a = 30 #nx_b = 30 #sp_weight = 0.5 nx_strt_a = 50 # length: 338 nx_strt_b = 50 # length: 289 nframes = 200 # PROCESS:==================================================================================================== v_sig_interp, fs = speech_interp(wavfile_a, wavfile_b, nx_strt_a, nx_strt_b, nframes, fft_len) # Write wavfile: la.write_audio_file(wavfile_out, v_sig_interp, fs, norm=0.98) if False: plt.figure(); plt.plot(v_mag_db_a); plt.plot(5 + v_lpc_mag_db_a); plt.plot(v_sp_env_db_targ); plt.grid(); plt.show() plt.figure(); plt.plot(v_mag_db_a); plt.plot(6.0 + v_lpc_mag_db_a); plt.grid(); plt.show() plt.figure(); plt.plot(v_mag_db_a); plt.plot(v_mag_db_a - v_lpc_mag_db_a); plt.grid(); plt.show() plt.figure(); plt.plot(v_mag_db_a); plt.plot(v_true_env_db_a); plt.grid(); plt.show() plt.figure(); plt.plot(v_mag_db_a); plt.plot(v_mag_db_a - v_true_env_db_a); plt.grid(); plt.show() plt.figure(); plt.plot(v_mag_db_a); plt.plot(v_mag_db_a - v_true_env_db_a); plt.plot(v_mag_db_a - v_lpc_mag_db_a); plt.grid(); plt.show() plt.figure(); plt.plot(v_frm_short_a_ext); plt.plot(v_frm_short_a_ext_filt); plt.grid(); plt.show()
# 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!')
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)