Mercurial > hg > smacpy
changeset 3:7a20cff05bd6
couple of bugfixes, almost runs
author | Dan Stowell <danstowell@users.sourceforge.net> |
---|---|
date | Wed, 14 Nov 2012 13:23:02 +0000 |
parents | 6159c3c0793c |
children | b1b9676f8791 |
files | MFCC.py smacpy.py |
diffstat | 2 files changed, 7 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/MFCC.py Wed Nov 14 13:16:14 2012 +0000 +++ b/MFCC.py Wed Nov 14 13:23:02 2012 +0000 @@ -82,7 +82,7 @@ dn = (filterEnd-numpy.array(xrange(filterCentre,filterEnd)))/k2 filt[filterStart:filterCentre] = up filt[filterCentre:filterEnd] = dn - + def warpSpectrum(self,magnitudeSpectrum): '''Compute the Mel scaled spectrum.''' return numpy.dot(magnitudeSpectrum,self.filterMatrix)
--- a/smacpy.py Wed Nov 14 13:16:14 2012 +0000 +++ b/smacpy.py Wed Nov 14 13:23:02 2012 +0000 @@ -111,6 +111,8 @@ if sf.samplerate != fs: raise ValueError("wanted sample rate %g - got %g." % (fs, sf.samplerate)) window = np.hamming(framelen) features = [] + mfccMaker = melScaling(int(fs), framelen/2, 40) + mfccMaker.update() while(True): try: chunk = sf.read_frames(framelen, dtype=np.float32) @@ -121,7 +123,6 @@ magspec = abs(framespectrum[:framelen/2]) # do the frequency warping and MFCC computation - mfccMaker = melScaling(int(fs), framelen/2, 40) melSpectrum = mfccMaker.warpSpectrum(magspec) melCepstrum = mfccMaker.getMFCCs(melSpectrum,cn=True) melCepstrum = melCepstrum[1:] # exclude zeroth coefficient @@ -147,15 +148,15 @@ trainingdata = {} pattern = os.path.join(foldername, '*.wav') for wavpath in glob(pattern): - label = os.path.basename(wavpath).split('-')[0] + label = os.path.basename(wavpath).split('_')[0] shortwavpath = os.path.relpath(wavpath, foldername) - trainingdata{shortwavpath} = label + trainingdata[shortwavpath] = label if len(trainingdata)==0: raise RuntimeError("Found no files using this pattern: %s" % pattern) if verbose: print "Class-labels and filenames to be used in training:" - for wavpath,label in trainingdata.iteritems(): - print " %s: %s" % (label, wavpath) + for wavpath,label in sorted(trainingdata.iteritems()): + print " %s: \t %s" % (label, wavpath) model = Smacpy(foldername, trainingdata)