%pylab inline
Populating the interactive namespace from numpy and matplotlib
import matplotlib
matplotlib.style .use("ggplot")
rcParams['figure.figsize'] = 16, 7
import numpy as np
from scipy.io import wavfile
import pysptk
fs, x = wavfile.read("test16k.wav")
assert fs == 16000
plot(x)
xlim(0, len(x))
title("raw waveform of test16k.wav")
<matplotlib.text.Text at 0x7f9ca7cf1210>
# Pick a short segment
pos = 3000
frame_length = 1024
xw = x[pos:pos+frame_length] * pysptk.blackman(frame_length)
plot(xw, linewidth=3.0)
xlim(0, frame_length)
title("a windowed time frame")
<matplotlib.text.Text at 0x7f9ca7bf4650>
# plotting utility
def pplot(sp, envelope, title="no title"):
plot(sp, "b-", linewidth=2.0, label="Original log spectrum 20log|X(w)|")
plot(20.0/np.log(10)*envelope, "r-", linewidth=3.0, label=title)
xlim(0, len(sp))
xlabel("frequency bin")
ylabel("log amplitude")
legend(prop={'size': 20})
# Compute spectrum 20log|X(w)| for a windowed signal
sp = 20*np.log10(np.abs(np.fft.rfft(xw)))
mgc = pysptk.mgcep(xw, 20, 0.0, 0.0)
pplot(sp, pysptk.mgc2sp(mgc, 0.0, 0.0, frame_length).real, title="Lineaer frequency cepstrum based envelope")
mgc = pysptk.mcep(xw, 20, 0.41)
pplot(sp, pysptk.mgc2sp(mgc, 0.41, 0.0, frame_length).real, title="Mel-cepstrum based envelope")
mgc = pysptk.mgcep(xw, 20, 0.0, -1.0)
pplot(sp, pysptk.mgc2sp(mgc, 0.0, -1.0, frame_length).real, title="LPC cepstrum based envelope")
mgc = pysptk.mgcep(xw, 20, 0.41, -1.0)
pplot(sp, pysptk.mgc2sp(mgc, 0.41, -1.0, frame_length).real, title="Warped LPC cepstrum based envelope")
mgc = pysptk.gcep(xw, 20, -0.35)
pplot(sp, pysptk.mgc2sp(mgc, 0.0, -0.35, frame_length).real, title="Generalized cepstrum based envelope")
mgc = pysptk.mgcep(xw, 20, 0.41, -0.35)
pplot(sp, pysptk.mgc2sp(mgc, 0.41, -0.35, frame_length).real, title="Mel-generalized cepstrum based envelope")