# HG changeset patch # User Dan Stowell # Date 1352899382 0 # Node ID 7a20cff05bd6793070b2697b3ad2b0d0593e5afd # Parent 6159c3c0793ca32e8a972b17ae61cc7ef9b738bf couple of bugfixes, almost runs diff -r 6159c3c0793c -r 7a20cff05bd6 MFCC.py --- 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) diff -r 6159c3c0793c -r 7a20cff05bd6 smacpy.py --- 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)