SoX: Difference between revisions
No edit summary |
|||
Line 13: | Line 13: | ||
In case they're not installed, you can also check out the man pages online: | In case they're not installed, you can also check out the man pages online: | ||
[http://manpages.ubuntu.com/manpages/jaunty/en/man1/sox.1.html sox][http://manpages.ubuntu.com/manpages/intrepid/en/man7/soxexam.7.html soxexam] | [http://manpages.ubuntu.com/manpages/jaunty/en/man1/sox.1.html sox] [http://manpages.ubuntu.com/manpages/intrepid/en/man7/soxexam.7.html soxexam] | ||
== Displaying information about an audio file == | == Displaying information about an audio file == |
Revision as of 19:26, 4 October 2009
sox (Sound Exchange) is a handy command line tool for generating, manipulating, and applying simple filters to audio.
Getting help about sox
Actually, there's quite a bit of help available from sox itself, it's just a little spread out, try one or all of the following:
man sox
man soxexam
sox
sox --help-effect all
In case they're not installed, you can also check out the man pages online: sox soxexam
Displaying information about an audio file
sox -V clap.wav -n
displays in my case...
sox: SoX v14.0.1
Input File : 'clap.wav'
Sample Size : 16-bit (2 bytes)
Sample Encoding: signed (2's complement)
Channels : 1
Sample Rate : 44100
Duration : 00:00.50 = 22050 samples = 37.5 CDDA sectors
Endian Type : little
Reverse Nibbles: no
Reverse Bits : no
Or use the "stat" effect:
sox clap.wav -e stat
displays
Samples read: 22050
Length (seconds): 0.500000
Scaled by: 2147483647.0
Maximum amplitude: 0.999969
Minimum amplitude: -0.999878
Midline amplitude: 0.000046
Mean norm: 0.015108
Mean amplitude: 0.000009
RMS amplitude: 0.047986
Maximum delta: 0.552368
Minimum delta: 0.000000
Mean delta: 0.005487
RMS delta: 0.017184
Rough frequency: 2513
Volume adjustment: 1.000
Generating tones or noise
sox -c1 -r8000 -n -t wav - synth 0.25 sine 220 vol 0.7 > beep.wav sox -c1 -r8000 -n -t wav - synth 0.25 sine 220-440 vol 0.7 > sweep_up.wav sox -c1 -r8000 -n -t wav - synth 0.25 sine 440-220 vol 0.7 > sweep_down.wav sox -c1 -r8000 -n -t wav - synth 0.25 noise vol 0.7 > ch.wav sox -c1 -r8000 -n -t wav - synth 2.0 sine 220-1000 vol 0.7 > sweep_up_long.wav sox -c1 -r8000 -n -t wav - synth 2.0 sine 1000-220 vol 0.7 > sweep_down_long.wav sox -c1 -r8000 -n -t wav - synth 0.5 square 330 vol 0.7 > bleep.wav
"Drum" hits in various colors, 0.2 secs with a quick decay
sox -c2 -r44100 -n -t wav - synth 0.2 pinknoise vol 1.0 fade l 0 0.2 0.19 > pink.wav
sox -c2 -r44100 -n -t wav - synth 0.2 brownnoise vol 1.0 fade l 0 0.2 0.19 > brown.wav
sox -c2 -r44100 -n -t wav - synth 0.2 noise vol 1.0 fade l 0 0.2 0.19 > white.wav
Silence using a noise generator at zero volume (must be other ways to achieve the same), nb the use of raw format.
sox -c2 -r44100 -n -t raw - synth 0.2 noise vol 0.0 > silence.raw
Working with "raw audio"
Working with raw files allows audio to get appended together; here sox is used to take a bunch of wavs, make them raw, send them all to stdout, the repackage them as a wav file.
Turning raw audio in to a wav file
sox -t raw -r 44100 -s -2 -c 2 input.raw output.wav
Batch processing
(for file in *; do sox "$file" -t .raw -r 44100 -sw -c 2 -; done) | \
sox -t .raw -r 44100 -sw -c 2 - -t .wav newfile.wav
source: [1]
Script to cat two wavs together using sox/raw format
#!/bin/sh
sox $1 -r 44100 -c 2 -s -2 /tmp/$$-1.raw
sox $2 -r 44100 -c 2 -s -2 /tmp/$$-2.raw
cat /tmp/$$-1.raw /tmp/$$-2.raw > /tmp/$$.raw
sox -r 44100 -c 2 -s -2 /tmp/$$.raw $3
rm /tmp/$$*.raw
(changed -w to -2 to work on mac, new version of sox?!)