def transform_f0_from_list(speaker, f0rate, wav_fs, list_file, wav_dir): """Transform f0 from list Transform F0 of the waveforms based on `f0rate` and save into `wav_dir` with `speaker`_`$f0rate` label Parameters --------- speaker : str, Label of the source speaker f0rate : float, File path of the list file of the speaker wav_fs : int, Sampling frequency of the waveform listfile : str, path-like, File path of the list file of the speaker wav_dir : str, path-like, Directory path of the waveform """ # open list file with open(list_file, 'r') as fp: files = fp.readlines() # Construct Shifter class shifter = Shifter(wav_fs, f0rate=f0rate) # check output directory transformed_wavdir = os.path.join(wav_dir, speaker + '_' + str(f0rate)) if not os.path.exists(transformed_wavdir): os.makedirs(transformed_wavdir) for f in files: # open wave file f = f.rstrip() wavf = os.path.join(wav_dir, f + '.wav') # output file path transformed_wavpath = os.path.join(transformed_wavdir, os.path.basename(wavf)) # flag for completion of high frequency range if f0rate < 1.0: completion = True else: completion = False if not os.path.exists(transformed_wavpath): # transform F0 of waveform fs, x = wavfile.read(wavf) x = np.array(x, dtype=np.float) x = low_cut_filter(x, fs, cutoff=70) assert fs == wav_fs transformed_x = shifter.f0transform(x, completion=completion) wavfile.write(transformed_wavpath, fs, transformed_x.astype(np.int16)) print('F0 transformed wav file: ' + transformed_wavpath) else: print('F0 transformed wav file already exists: ' + transformed_wavpath)
def transform_f0_from_list(speaker, f0rate, wav_fs, list_file, wav_dir): """Transform f0 from list Transform F0 of the waveforms based on `f0rate` and save into `wav_dir` with `speaker`_`$f0rate` label Parameters --------- speaker : str, Label of the source speaker f0rate : float, File path of the list file of the speaker wav_fs : int, Sampling frequency of the waveform listfile : str, path-like, File path of the list file of the speaker wav_dir : str, path-like, Directory path of the waveform """ # open list file with open(list_file, 'r') as fp: files = fp.readlines() # Construct Shifter class shifter = Shifter(wav_fs, f0rate=f0rate) # check output directory transformed_wavdir = os.path.join(wav_dir, speaker + '_' + str(f0rate)) if not os.path.exists(transformed_wavdir): os.makedirs(transformed_wavdir) for f in files: # open wave file f = f.rstrip() wavf = os.path.join(wav_dir, f + '.wav') # output file path transformed_wavpath = os.path.join( transformed_wavdir, os.path.basename(wavf)) # flag for completion of high frequency range if f0rate < 1.0: completion = True else: completion = False if not os.path.exists(transformed_wavpath): # transform F0 of waveform fs, x = wavfile.read(wavf) x = np.array(x, dtype=np.float) x = low_cut_filter(x, fs, cutoff=70) assert fs == wav_fs transformed_x = shifter.f0transform(x, completion=completion) wavfile.write(transformed_wavpath, fs, transformed_x.astype(np.int16)) print('F0 transformed wav file: ' + transformed_wavpath) else: print('F0 transformed wav file already exists: ' + transformed_wavpath)
def test_shifter(self): path = dirpath + '/data/test16000.wav' fs, x = wavfile.read(path) for f0rate in (0.5, 0.75, 1.0, 1.5, 2.0): if f0rate < 1: completion = True else: completion = False shifter = Shifter(fs, f0rate=f0rate) transformed_x = shifter.f0transform(x, completion=completion) assert len(x) == len(transformed_x) if saveflag: fpath = path + str(f0rate) + '.wav' wavfile.write(fpath, fs, transformed_x.astype(np.int16))
def test_shifter(self): path = dirpath + '/data/test16000.wav' fs, x = wavfile.read(path) for f0rate in (0.5, 0.75, 1.0, 1.5, 2.0): if f0rate < 1: completion = True else: completion = False shifter = Shifter(fs, f0rate=f0rate, shiftms=10) transformed_x = shifter.f0transform(x, completion=completion) assert len(x) == len(transformed_x) if saveflag: fpath = path + str(f0rate) + '.wav' wavfile.write(fpath, fs, transformed_x.astype(np.int16))
def transform_f0_from_list(speaker, f0rate, wav_fs, list_file, wav_dir): # open list file with open(list_file, 'r') as fp: files = fp.readlines() # Construct Shifter class shifter = Shifter(wav_fs, f0rate=f0rate) # check output directory transformed_wavdir = os.path.join(wav_dir, speaker + '_' + str(f0rate)) if not os.path.exists(transformed_wavdir): os.makedirs(transformed_wavdir) for f in files: # open wave file f = f.rstrip() wavf = os.path.join(wav_dir, f + '.wav') # output file path transformed_wavpath = os.path.join(transformed_wavdir, os.path.basename(wavf)) # flag for completion of high frequency range if f0rate < 1.0: completion = True else: completion = False if not os.path.exists(transformed_wavpath): # transform F0 of waveform fs, x = wavfile.read(wavf) x = np.array(x, dtype=np.float) assert fs == wav_fs transformed_x = shifter.f0transform(x, completion=completion) wavfile.write(transformed_wavpath, fs, transformed_x.astype(np.int16)) print('F0 transformed wav file: ' + transformed_wavpath) else: print('F0 transformed wav file already exists: ' + transformed_wavpath)
def test_high_frequency_completion(self): path = dirpath + '/data/test16000.wav' fs, x = wavfile.read(path) f0rate = 0.5 shifter = Shifter(fs, f0rate=f0rate) mod_x = shifter.f0transform(x, completion=False) mod_xc = shifter.f0transform(x, completion=True) assert len(mod_x) == len(mod_xc) N = 512 fl = int(fs * 25 / 1000) win = np.hanning(fl) sts = [1000, 5000, 10000, 20000] for st in sts: # confirm w/o completion f_mod_x = fft(mod_x[st: st + fl] / 2**16 * win) amp_mod_x = 20.0 * np.log10(np.abs(f_mod_x)) # confirm w/ completion f_mod_xc = fft(mod_xc[st: st + fl] / 2**16 * win) amp_mod_xc = 20.0 * np.log10(np.abs(f_mod_xc)) assert np.mean(amp_mod_x[N // 4:] < np.mean(amp_mod_xc[N // 4:]))