Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 4 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:



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}`

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.

share|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
"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

Here is my solution.



LENGTH=0.05 # length in ms (to use samples you should add s suffix to commandline trim Xs Ys and s flag for soxi)

while [ $(echo "$START < $TOTAL_LENGTH"|bc) -eq 1 ]; do
    echo "Trimming from ${START} of ${TOTAL_LENGTH}"
    sox ${INPUT} `echo ${OUTPUT} | sed s/X/${N}/` trim ${START} ${LENGTH}
    START=`echo "$START + $LENGTH"|bc`

The difference is:

  • Script works with ms rather than with samples
  • The amount of output files is automatically detected by INPUT length
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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