def feat_extraction(in_wav_dir, file_name_token, out_feats_dir): # Display: print("\nAnalysing file: " + file_name_token + '.wav............................') # File setup: wav_file = os.path.join(in_wav_dir, file_name_token + '.wav') mp.analysis_compressed(wav_file, out_dir=out_feats_dir) return
def feat_extraction(wav_file, out_feats_dir): # Parsing path: file_name_token = os.path.basename(os.path.splitext(wav_file)[0]) # Display: print("Analysing file: " + file_name_token + '.wav' + '................................') # Files setup: est_file = os.path.join(out_feats_dir, file_name_token + '.est') # Epochs detection: la.reaper(wav_file, est_file) # Feature extraction: m_mag_mel_log, m_real_mel, m_imag_mel, v_lf0, v_shift, fs, fft_len = mp.analysis_compressed( wav_file) if fs != fs_expected: print( "The wavefile's sample rate (%dHz) does not match the expected sample rate (%dHz)." % (fs, fs_expected)) sys.exit(1) # Zeros for unvoiced segments in phase features: v_voi = (np.exp(v_lf0) > 5.0).astype(int) # 5.0: tolerance (just in case) m_real_mel_zeros = m_real_mel * v_voi[:, None] m_imag_mel_zeros = m_imag_mel * v_voi[:, None] # Saving features: lu.write_binfile(m_mag_mel_log, out_feats_dir + '/' + file_name_token + '.mag') lu.write_binfile(m_real_mel_zeros, out_feats_dir + '/' + file_name_token + '.real') lu.write_binfile(m_imag_mel_zeros, out_feats_dir + '/' + file_name_token + '.imag') lu.write_binfile(v_lf0, out_feats_dir + '/' + file_name_token + '.lf0') # Saving auxiliary feature shift (hop length). It is useful for posterior modifications of labels in Merlin. lu.write_binfile(v_shift, out_feats_dir + '/' + file_name_token + '.shift') return
b_plots = True # True if you want to plot the extracted parameters. # INPUT:============================================================================== wav_file_orig = 'data_48k/wavs_nat/hvd_593.wav' # Original natural wave file. You can choose anyone provided in the /wavs_nat directory. b_const_rate = False mag_dim = 100 phase_dim = 45 # PROCESS:============================================================================ lu.mkdir(out_dir) # ANALYSIS: 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)
return if __name__ == '__main__': # INPUT:============================================================================== wav_file_orig = 'data_48k/wavs_nat/hvd_593.wav' # Original natural wave file. You can choose anyone provided in the /wavs_nat directory. out_dir = 'data_48k/wavs_syn' # Where the synthesised waveform will be stored. 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)