Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@Memoize
def do_fbank(fname):
try:
with open(fname[:-3] + 'npy', 'rb') as rfb:
fb = np.load(rfb)
except IOError:
srate, sound = wavfile.read(fname)
fbanks = Spectral(nfilt=N_FBANKS, # nb of filters in mel bank
alpha=0.97, # pre-emphasis
do_dct=False, # we do not want MFCCs
fs=srate, # sampling rate
frate=FBANKS_RATE, # frame rate
wlen=FBANKS_WINDOW, # window length
nfft=1024, # length of dft
do_deltas=False, # speed
do_deltasdeltas=False # acceleration
)
fb = np.array(fbanks.transform(sound), dtype='float32')
#with open(fname.split('.')[0] + '.npy', 'wb') as wfb:
# np.save(wfb, fb)
print "did:", fname
#print fb.shape
return fb
gammatonefname = bdir+'/'+fname[:-4]+'_gamma.npy'
tmp_snd = loadsound(wavfname)
gamma_cf = erbspace(20*Hz, 20*kHz, N_GAMMATONES_FILTERS)
gamma_fb = Gammatone(tmp_snd, gamma_cf)
with open(gammatonefname, 'w') as o_f:
npsave(o_f, gamma_fb.process())
if spectrograms:
powerspec, _, _, _ = specgram(sound, NFFT=int(srate
* SPECGRAM_WINDOW), Fs=srate, noverlap=int(srate
* SPECGRAM_OVERLAP)) # TODO
specgramfname = bdir+'/'+fname[:-4]+'_specgram.npy'
with open(specgramfname, 'w') as o_f:
npsave(o_f, powerspec.T)
if filterbanks:
# convert to Mel filterbanks
fbanks = Spectral(nfilt=N_FBANKS, # nb of filters in mel bank
alpha=0.97, # pre-emphasis
do_dct=False, # we do not want MFCCs
compression='log',
fs=srate, # sampling rate
#lowerf=50, # lower frequency
frate=FBANKS_RATE, # frame rate
wlen=FBANKS_WINDOW, # window length
nfft=1024, # length of dft
do_deltas=False, # speed
do_deltasdeltas=False # acceleration
)
fbank = fbanks.transform(sound)
fbanksfname = bdir+'/'+fname[:-4]+'_fbanks.npy'
with open(fbanksfname, 'w') as o_f:
npsave(o_f, fbank)
# TODO wavelets scattergrams / scalograms
tmp_snd = loadsound(wavfname)
gamma_cf = erbspace(20*Hz, 20*kHz, N_GAMMATONES_FILTERS)
gamma_fb = Gammatone(tmp_snd, gamma_cf)
with open(gammatonefname, 'w') as o_f:
npsave(o_f, gamma_fb.process())
if spectrograms:
powerspec, _, _, _ = specgram(sound, NFFT=int(srate
* SPECGRAM_WINDOW), Fs=srate, noverlap=int(srate
* SPECGRAM_OVERLAP)) # TODO
specgramfname = bdir+'/'+fname[:-4]+'_specgram.npy'
with open(specgramfname, 'w') as o_f:
npsave(o_f, powerspec.T)
if filterbanks:
# convert to Mel filterbanks
if fbanks == None: # assume parameters are fixed
fbanks = Spectral(nfilt=N_FBANKS, # nb of filters in mel bank
alpha=0.97, # pre-emphasis
do_dct=False, # we do not want MFCCs
fs=srate, # sampling rate
frate=FBANKS_RATE, # frame rate
wlen=FBANKS_WINDOW, # window length
nfft=1024, # length of dft
do_deltas=False, # speed
do_deltasdeltas=False # acceleration
)
fbank = fbanks.transform(sound)[0] # first dimension is for
# deltas & deltasdeltas
fbanksfname = bdir+'/'+fname[:-4]+'_fbanks.npy'
with open(fbanksfname, 'w') as o_f:
npsave(o_f, fbank)
# TODO wavelets scattergrams / scalograms
print "dealt with file", wavfname
@Memoize
def do_fbank(fname):
fn = bdir + fname + '.wav'
try:
with open(fn[:-3] + 'npy', 'rb') as rfb:
fb = np.load(rfb)
except IOError:
srate, sound = wavfile.read(fn)
fbanks = Spectral(nfilt=N_FBANKS, # nb of filters in mel bank
alpha=0.97, # pre-emphasis
do_dct=False, # we do not want MFCCs
fs=srate, # sampling rate
frate=FBANKS_RATE, # frame rate
wlen=FBANKS_WINDOW, # window length
nfft=1024, # length of dft
do_deltas=False, # speed
do_deltasdeltas=False # acceleration
)
fb = np.array(fbanks.transform(sound), dtype='float32')
print "did:", fn
#print fb.shape
return fb