Re: Looking For Simple mp3 Audio Editor?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Yes Laurenzo, that script may be helpful--and-thanks in advance
Hart

Ok.. here it is. As I said it's especially non-refined so all the filenames are hard-coded to audio.wav (the input file), cue (the cue file), concat.wav (the output file). Also I only used it in the same dir as the input audio file. The 'cue' file is in the format start_time end_time both in hh:mm:ss format separated by a space, one per line, so in the attached example one two chunks of the input wave file from 00:10:05 to 00:10:35 and from 00:20:30 to 00:21:07, then these chunks will simply be concatenated into a single file.
I made this on ubuntu 9.10 with the shipped version of sox.

All the best,
Lorenzo
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.'
00:10:05 00:10:35
00:20:30 00:21:07
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@xxxxxxxxxxxxxxxxxxxx
http://lists.linuxaudio.org/listinfo/linux-audio-user

[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux