Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOX and fade in and fade out

Tags:

sox

libsox

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?

like image 417
Rick T Avatar asked Jun 19 '14 12:06

Rick T


2 Answers

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
like image 141
lCapp Avatar answered Nov 19 '22 14:11

lCapp


From the sox manpage:

fade [type] fade-in-length [stop-position(=) [fade-out-length]]

...

If the audio length can be determined from the input file header and any previous effects, then -0 (or, for historical reasons, 0) may be specified for stop-position to indicate the usual case of a fade-out that ends at the end of the input audio stream.

So to fade in 5 seconds, and fade out 7 seconds:

sox input.waw output.waw fade 5 -0 7
like image 36
WASDi Avatar answered Nov 19 '22 15:11

WASDi