Home » Asterisk PBX » Asterisk Sounds Transcode WAV to g729 Codec

Asterisk Sounds Transcode WAV to g729 Codec

December 31st, 2014 Leave a comment Go to comments

I was sooo surprised I couldn’t find anything decent on google to transcode asterisk sounds from WAV to g729 codec that I decided to post what I’ve done.

Asterisk already has a “file convert” cli command, which does exactly that… convert files from one codec to another.  All one needs to do is write a little shell script to be able to do it in bulk for multiple files.  So here is the shell script that will do it for you.  Just put that into a .sh file, chmod it to 755 and run it with the appropriate arguments.

#!/bin/bash

echo ""
echo "ASTERISK TRANSCODER"
echo ""

if [ $# -ne 3 ]
then
        echo "Usage:"
        echo "$0 FROM_FORMAT TO_FORMAT FILE_PATH"
        echo ""
        echo "FROM_FORMAT - The format from which to make the coversion e.g. wav, ulaw, gsm, g729, etc."
        echo "TO_FORMAT - The format to which to make the conversion e.g. wav, ulaw, gsm, g729, etc."
        echo "FILE_PATH - The location where the file are located and where the new files will be created."
        echo ""
        echo "NOTE: The FROM_FORMAT and TO_FORMAT codecs must be installed and working in Asterisk."
        echo "Use 'core show translation recalc 10' in Asterisk CLI to confirm which codecs are installed."
        echo ""
        exit 1
fi

from_format=($1)
to_format=($2)
file_path=($3)

read -p "Transcode all files in $file_path from $from_format to $to_format? Press  to proceed or  to cancel."

echo ""

for file in $file_path/*.$from_format;
do
        asterisk -rx "file convert $file ${file%.$from_format}.$to_format"
done
Share
Categories: Asterisk PBX Tags:
  1. No comments yet.
  1. No trackbacks yet.


5 − = one