Linux: Automatically convert created .WAV Files to .mp3 Files (320kbit/s)

This article will describe how new .WAV Tracks can automatically be converted to mp3 Files.

You need

1. The following packages installed

 apt install lame incron 

2. The Convert Script

Create the script with vim:

vim /home/user/scripts/convert-mp3.sh

Add the following content:

#!/bin/bash
sleep 5
FILE=$1
DESTINATIONFOLDER=${FILE%/*}/mp3/
DESTINATIONFILE=${FILE%.WAV}.mp3
DESTINATIONFILE=`echo $DESTINATIONFILE | rev | cut -d '/' -f 1 | rev`
DESTINATION=$DESTINATIONFOLDER$DESTINATIONFILE

echo -e "We will convert \n\"$FILE\" to \n\"$DESTINATION\" \n"

if [ ${FILE: -4} == ".WAV" ] && [ -r ${FILE} ] ; then

lame -b 320 -h $FILE $DESTINATION
else
echo ERROR: The File \"$FILE\" is not a .WAV or not readable
exit 1
fi

3. The Incrontab Entry

This will add the automatismen:

Open incrontab to add the job:

incrontab -e

Add this content to the file:

/home/user/Music/REC/2018/ IN_CLOSE_WRITE /home/user/scripts/convert-mp3.sh $@/$#

Finished! 🙂

CS

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert