i need to cut audio files into small samples of even length. What i need is basically a batch processor for audio which does it, and names the slices numerically. i'm on os x and found Audio Splitter, the shortest possible sample length with it is 1 second though, too long for my purpose. Anyone know an alternative?

link|improve this question
feedback

1 Answer

up vote 3 down vote accepted

An excellent sound converter SoX (also named 'the Swiss Army knife of audio manipulation') works on OS X, so I hope this script will help you:

#!/bin/sh

N=0
START=0
LENGTH=8000
COUNT=100
INPUT=input.mp3
OUTPUT=output-X.wav

for i in `jot ${COUNT}`; do
    echo "Trimming ${START}+${LENGTH}"
    sox ${INPUT} `echo ${OUTPUT} | sed s/X/${N}/` trim ${START}s ${LENGTH}s
    N=`expr ${N} + 1`
    START=`expr ${START} + ${LENGTH}`
done

All lengths are in samples (you can also specify time in 'HH:MM:SS.ddd' format, check SoX manpage); it reads INPUT file and produces files named output-0.wav, output-1.wav and so on.

link|improve this answer
okay this sounds great, exactly what i need. i've installed SoX, however when i execute run the script i get "line 15: seq: command not found" (i'm a complete command line noob) – Jakob Jan 31 '10 at 3:20
nvm, it works now. thanks a lot! – Jakob Jan 31 '10 at 3:55
1  
"seq" is GNU. For OSX or BSD you want "jot". e.g. for i in `jot ${COUNT}`; do – Richard Hoskins Jan 31 '10 at 4:49
Fixed the script. – whitequark Jan 31 '10 at 15:12
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.