Padding an audio file with silence using sox

From ActiveArchives
Jump to: navigation, search

Sox can generate silence and combine different audio files. When combining files with sox it's important to match the number of channels (mono or stereo). Encoding an mp3 is best done with lame.

Contents

Generate 3 seconds of (stereo) silence

sox -n -r 44100 -c 2 silence.wav trim 0.0 3.0

Combining the files

sox silence.wav filetopad.mp3 silence.wav output.wav
lame output.wav output.mp3

Putting the steps together as a script

~/bin/padmp3

#!/bin/bash
 
duration=1.0
 
for i
do
sox -n -r 44100 -c 2 /tmp/silence.wav trim 0.0 $duration
sox $i -r 44100 -c 2 /tmp/output1.wav
sox /tmp/silence.wav /tmp/output1.wav /tmp/silence.wav /tmp/output.wav 
lame /tmp/output.wav $i
 
done

Resources: http://billposer.org/Linguistics/Computation/SoxTutorial.html

Run the script with sshfs

- make sure you have following packages installed

sudo apt-get install

sox

libsox-fmt-all

lame

sshfs

tree: shows content of your folders in nicely coloured tree architecture

- ssh

connect to your server using ssh

copy the files you want the script to treat in back_up folder: cp -r name_folder name_backup

exit ssh

- create a bin-folder in your home directory (ubuntu recognizes ~/home/bin as executable command folder)

mkdir bin

chmod +x padmp3.sh

copy script here (without extension), f.ex. padmp3.sh -> padmp3

log out

log in

-> the script is now executable as a command

- sshfs

create folder for mirroring the files: mkdir mnt

connect to your server using sshfs: sshfs login@servername:path_from_home_on_server mnt

- execute script

find . -iname "*.mp3" -exec padmp3 {} \;

- exit sshfs:

sudo unmount mnt

What links here

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox