def segment_audio_files(filepath, segment_length, result_dir=RESULT_DIR): ''' From an input audio file, segments the file into segments of length segment_length, and outputs them as individual files to result_dir Parameters: filepath - the path to the input file segment_length - the length of the segment to return, in seconds result_dir - output path to write to ''' filename = os.path.split(filepath)[1] afm = audiofile_manager(filepath, segment_length) checkdir(RESULT_DIR) cleandir(RESULT_DIR) print "File in 5-minute chunks" while afm.HasMoreData(): segment, index = afm.GetNextSegment() outFile = "%s/%s-%d.wav" % (RESULT_DIR, filename[:-4], index) print "%d %.3f%%" % (index, (index * afm.seg_length_samps / np.float(afm.afReader.numsamples()))*100 ) print "Writing %s..." % (outFile), M.wavwrite(segment, outFile, afm.afReader.samplerate()) print "...done."
def segment_audio_files(filepath, segment_length, result_dir=RESULT_DIR): ''' From an input audio file, segments the file into segments of length segment_length, and outputs them as individual files to result_dir Parameters: filepath - the path to the input file segment_length - the length of the segment to return, in seconds result_dir - output path to write to ''' filename = os.path.split(filepath)[1] afm = audiofile_manager(filepath, segment_length) checkdir(RESULT_DIR) cleandir(RESULT_DIR) print "File in 5-minute chunks" while afm.HasMoreData(): segment, index = afm.GetNextSegment() outFile = "%s/%s-%d.wav" % (RESULT_DIR, filename[:-4], index) print "%d %.3f%%" % (index, (index * afm.seg_length_samps / np.float(afm.afReader.numsamples())) * 100) print "Writing %s..." % (outFile), M.wavwrite(segment, outFile, afm.afReader.samplerate()) print "...done."
import mirlib.feature_extraction.eventDetect as ed import mirlib.FFTParams as fftparams from matplotlib.pylab import * #inputfile = '../audio_files/GV02_A_Format4min.wav' inputfile = '../audio_files/wburgShort.wav' if not os.path.exists(inputfile): raise Exception("FILE DOES NOT EXIST, TRY AGAIN") [x, fs] = M.wavread(inputfile) # FFT Parameters N = 2048 hopDenom = 2 zp = 0 winfunc=np.hamming fftParams = fftparams.FFTParams(fs, N, hopDenom, zp, winfunc) #peaks = z.envelopeFollowEnergy(winLen,hopSize) # the old way z = ed.onsetDetect(fftParams) events = z.findEventLocations(x) xConcat = x[(events)] M.wavwrite(xConcat, "segs.wav", fs)
import os import numpy as np import marlib.matlab as M import mirlib.feature_extraction.eventDetect as ed import mirlib.FFTParams as fftparams from matplotlib.pylab import * #inputfile = '../audio_files/GV02_A_Format4min.wav' inputfile = '../audio_files/wburgShort.wav' if not os.path.exists(inputfile): raise Exception("FILE DOES NOT EXIST, TRY AGAIN") [x, fs] = M.wavread(inputfile) # FFT Parameters N = 2048 hopDenom = 2 zp = 0 winfunc = np.hamming fftParams = fftparams.FFTParams(fs, N, hopDenom, zp, winfunc) #peaks = z.envelopeFollowEnergy(winLen,hopSize) # the old way z = ed.onsetDetect(fftParams) events = z.findEventLocations(x) xConcat = x[(events)] M.wavwrite(xConcat, "segs.wav", fs)