Search code examples
soxlibsox

SOX and fade in and fade out


I'm trying to create a fade in and fade out for several wave files that I won't know the total time duration in seconds of. I read the manual but the example I see all looks like I need to know the full length of the file. Can someone post an example of fading in 5 seconds and fading out 7 seconds without knowing the full length of the wav file?


Solution

  • You can use a simple bash script, as this:

    #! /bin/bash
    
    WAV_IN=$1
    WAV_OUT=$2
    
    FADE_IN_L="0:5"
    FADE_OUT_L="0:7"
    
    LENGTH=`soxi -d $WAV_IN`
    
    sox $WAV_IN $WAV_OUT fade $FADE_IN_L $LENGTH $FADE_OUT_L
    

    soxi -d returns the length of the wav file. See sox documentation for more on soxi.

    You can run this bash script as follows:

    ./fadeWav test.wav faded.wav