import os # these should really be provided from command lin inFile = 'audio.wav' cueFile = 'cue' outFile = 'concat.wav' f = open (cueFile,'r') times = [] for l in f: times.append (l.replace ('\n','')) f.close () timeargs = [] counter = 0 for t in times: couple = t.split (' ') startCut = couple[0].split (':') startCutSecs = int (startCut[0]) * 3600 + int (startCut[1]) * 60 + int (startCut[2]) endCut = couple[1].split (':') endCutSecs = int (endCut[0]) * 3600 + int (endCut[1]) * 60 + int (endCut[2]) totalCutSecs = str (endCutSecs - startCutSecs) if totalCutSecs < 0: print 'WARNING: negative cut!' d = {'start' : couple[0]} d['cut'] = totalCutSecs d['tempfile'] = 'chunk'+str (counter)+'.wav' d['commandline'] = 'sox ' + inFile + ' ' + d['tempfile']+ ' trim ' + d['start'] + ' ' + d['cut'] timeargs.append (d) counter += 1 print 'Processing file:',inFile print 'Using cuelist in file',cueFile,'\n' concatFiles = '' for t in timeargs: print 'Extracting from',t['start'],'for',t['cut'],'seconds' print '-- saving to file',t['tempfile'] os.system (t['commandline']) concatFiles += t['tempfile']+' ' print 'OK' print 'Concatenating files and saving to:',outFile os.system ('sox '+concatFiles+' '+outFile) print 'OK' print 'Cleaning up temp files...' for t in timeargs: os.remove (t['tempfile']) print ' done.'