python语音信号处理

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

 

posted on 2017-11-15 15:29  vyouman  阅读(367)  评论(0)    收藏  举报