def load_data(basename, filterer=None, pitchdir=None): """ Load data from wav and plg files. If filterer is not None, filters pitch trace. """ from ewave import wavfile from chirp.common import plg fp = wavfile(basename + ".wav") signal, Fs = fp.read(), fp.sampling_rate if isinstance(pitchdir, basestring): plgfile = os.path.join(pitchdir, os.path.split(basename)[1] + '.plg') else: plgfile = basename + '.plg' if not os.path.exists(plgfile): return signal, Fs / 1000., None, None pitch = plg.read(plgfile) if filterer is not None: ind = postfilter.ind_endpoints(filterer(pitch)) if ind is None: return signal, Fs / 1000., None, None pitch = pitch[ind[0]:ind[1] + 1] t = pitch['time'] if 'p.map' in pitch.dtype.names: p = pitch['p.map'] else: p = pitch['p.mmse'] return signal, Fs / 1000., t, p
def _load_plg(locator, filt, estimator): """ Load a pitch trace and filters it. If no points are reliable, returns None. """ from chirp.common import plg pest = plg.read(locator) ind = filt(pest) if not any(ind): return None else: ind = postfilter.ind_endpoints(ind) return pest[estimator][ind[0]:ind[1] + 1]