Introduction to pysptk

  • windowing
  • mel-generalized cepstrum analysis
  • visualize spectral envelope estimates

Extra requires

  • matplotlib
  • scipy
In [2]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [3]:
import matplotlib
matplotlib.style .use("ggplot")

rcParams['figure.figsize'] = 16, 7
In [4]:
import numpy as np
from scipy.io import wavfile
import pysptk
In [5]:
fs, x = wavfile.read("test16k.wav")
assert fs == 16000
In [6]:
plot(x)
xlim(0, len(x))
title("raw waveform of test16k.wav")
Out[6]:
<matplotlib.text.Text at 0x7f9ca7cf1210>

Windowing

In [7]:
# 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")
Out[7]:
<matplotlib.text.Text at 0x7f9ca7bf4650>
In [8]:
# 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})
In [9]:
# Compute spectrum 20log|X(w)| for a windowed signal
sp = 20*np.log10(np.abs(np.fft.rfft(xw)))
In [10]:
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")
In [11]:
mgc = pysptk.mcep(xw, 20, 0.41)
pplot(sp, pysptk.mgc2sp(mgc, 0.41, 0.0, frame_length).real, title="Mel-cepstrum based envelope")
In [12]:
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")
In [13]:
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")
In [14]:
mgc = pysptk.gcep(xw, 20, -0.35)
pplot(sp, pysptk.mgc2sp(mgc, 0.0, -0.35, frame_length).real, title="Generalized cepstrum based envelope")
In [15]:
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")