import wave
from scikits.talkbox import segment_axis
import numpy as np
def readwav(fn):
f = wave.open(fn, 'rb')
params = f.getparams()
nchannels, sampwidth, fs, nframes = params[:4]
# print nchannels, sampwidth, fs, nframes
strData = f.readframes(nframes)
waveData = np.fromstring(strData, dtype = np.int16)
waveData = waveData * 1.0 / max(abs(waveData))# Normalize the amplitude
waveData = np.reshape(waveData, [nframes,nchannels])# One column per channel
f.close()
return waveData, nchannels, sampwidth, fs, nframes
# Load the signal
fn = 'lullaby.wav'
data, nchannels, sampwidth, fs, nframes = readwav(fn)
frame_len = 160
overlap = 50
y = segment_axis(data, frame_len, overlap = overlap, end = 'pad')
y = np.hanning(frame_len) * y