import os import soundfile as sf import pyworld as pw import numpy as np import scipy.io as spio from expe_options import expe_options from expe_build_conditions import expe_build_conditions def preprocess(language): options = {} options["language"] = language options["subject_name"] = '' options = expe_options(options) _, options = expe_build_conditions(options) for i in range(len(options["syllables"])): syll = options["syllables"][i] print "%02d/%02d - %s\n" % (i, len(options["syllables"]), syll) wavIn = os.path.join(options["sound_path"], syll + ".wav") mat = os.path.join(options["sound_path_store"], syll + '.pyworld.mat') if not os.path.exists(mat): x, fs = sf.read(wavIn) _f0, t = pw.dio(x, fs) f0 = pw.stonemask(x, _f0, t, fs) sp = pw.cheaptrick(x, f0, t, fs) ap = pw.d4c(x, f0, t, fs) freq = np.arange(0, np.size(sp, axis=1), dtype='float64') / (np.size(sp)) * fs/2 temp_pos = t x_rms = np.sqrt(np.mean(x**2)) duration = len(x/fs) spio.savemat(mat, mdict={'fs': fs, 'f0': f0, 'sp': sp, 'ap': ap, 'x_rms': x_rms, 'frequencies': freq, 'temporal_positions': t, 'duration': duration })