def setUp(self): """ Generate one (short) frame of a 1 kHz sinusoid at a sampling rate of 16 kHz. It doesn't matter too much what it is, just that it is representative of some natural signal. """ self.pcm = ssp.PulseCodeModulation(16000) self.seq = np.zeros(64) p = self.pcm.seconds_to_period(1.0/1000); for s in range(len(self.seq)): self.seq[s] = np.sin(2*np.pi * s/p) w = ssp.nuttall(len(self.seq)+1) w = np.delete(w, -1) self.seq = ssp.Window(self.seq, w)
def get_pitch(gen_path, basefilename): (Fs, x) = io_wav.read(gen_path + basefilename + '.wav') assert Fs == 16000 pcm = ssp.PulseCodeModulation(Fs) frameSize = pcm.seconds_to_period(0.025, 'atleast') # 25ms Frame size pitchSize = pcm.seconds_to_period(0.1, 'atmost') # 100ms Pitch size pf = ssp.Frame(x, size=pitchSize, period=framePeriod) pitch, ac = ssp.ACPitch(pf, pcm, loPitch, hiPitch) # Initially pitch estimated # Pre-emphasis pre = ssp.parameter("Pre", None) if pre is not None: x = ssp.PoleFilter(x, pre) / 5 # Frame Splitting f = ssp.Frame(x, size=frameSize, period=framePeriod) # Windowing aw = ssp.nuttall(frameSize + 1) aw = np.delete(aw, -1) w = ssp.Window(f, aw) # Autocorrelation ac = ssp.Autocorrelation(w) if (len(ac) > len(pitch)): d = len(ac) - len(pitch) addon = np.ones(d) * pitch[-1] pitch = np.hstack((pitch, addon)) # Save pitch as binary lf0 = np.log(pitch) lf0.astype('float32').tofile(gen_path + basefilename + '.lf0') return pitch
# Timer ti = time.clock() def lap(func): global ti now = time.clock() elapsed = now-ti ti = now print(func, elapsed) import ssp import numpy as np import matplotlib.pyplot as plt lap("Import") # Load and do basic AR to reconstruct the spectrum pcm = ssp.PulseCodeModulation() wav = pcm.WavSource(file) print("File:", file, "rate:", pcm.rate, "size:", wav.size) if ssp.parameter("ZF", 0) == 1: wav = ssp.ZeroFilter(wav) f = ssp.Frame(wav, size=256, period=128) f = ssp.Window(f, np.hanning(256)) print("frame:", f.shape[0], "x", f.shape[1]) lap("Frame") e = ssp.Energy(f) p = ssp.Periodogram(f) lap("Periodogram") order = pcm.speech_ar_order() a = ssp.Autocorrelation(f) a, g = ssp.ARLevinson(a, order) lap("Levinson")