User Tools

Site Tools


voip:create_moh_files

Quick script I wrote to convert .mp3 files to .wav

Example: “ArtistGuy - SongTitle.mp3” will be converted to:
8000_ArtistGuy_-_SongTitle.wav
16000_ArtistGuy_-_SongTitle.wav
32000_ArtistGuy_-_SongTitle.wav
48000_ArtistGuy_-_SongTitle.wav

So, HZ is added and space is converted to underscore.

convertsongs.sh
#!/bin/bash
IFSORG=$IFS
BITRATES="8000 16000 32000 48000"
IFS=$'\n';
for x in `ls *.mp3`; do
# Convert the name to something FS can use
	SONGNAME=`echo $x | tr " " _ | sed 's/\.mp3/\.wav/'`

# Now convert 'em songs!
	echo "Converting $x:";
	IFS=$IFSORG;
	for y in $BITRATES; do
		echo -n "$y Hz.. ";
		mpg123 -q -s -f 8192 --mono -r $y -w "${y}_$SONGNAME" "$x"
	done
	echo "";
	IFS=$'\n';
done
IFS=$IFSORG

echo "Done converting."
voip/create_moh_files.txt · Last modified: 2015/08/15 20:56 (external edit)