1. 程式人生 > >wav檔案轉成g722, g729編碼的檔案

wav檔案轉成g722, g729編碼的檔案

語音系統中經常需要各種編碼的音訊原始檔案(raw file),使用Asterisk 這個著名的IP-PBX軟體附帶的轉碼功能就可以實現。

它根據檔案的字尾來確定編碼格式。

如果asterisk已經在執行,使用asterisk -r 可以進入asterisk的命令列。

"file convert "命令的使用方法:

dev12*CLI> file convert
Usage: file convert <file_in> <file_out>
       Convert from file_in to file_out. If an absolute path
       is not given, the default Asterisk sounds directory
       will be used.

       Example:
           file convert tt-weasels.gsm tt-weasels.ulaw

如果是在腳本里面執行,可以使用rasterisk工具,例如:

rasterisk -x "file convert /tmp/file_in.alaw /tmp/file_out.ulaw"

批量轉換的例子:

To ilbc
    for a in *.wav; do rasterisk -x "file convert /var/lib/asterisk/sounds/custom/$a /var/lib/asterisk/sounds/custom/`echo $a|sed "s/.wav/.ilbc/"`"; done;

To g729
     for a in *.wav; do rasterisk -x "file convert /var/lib/asterisk/sounds/custom/$a /var/lib/asterisk/sounds/custom/`echo $a|sed "s/.wav/.g729/"`"; done;

注意:

Asterisk only accepts .wav files with 8kHz sampling rate. 16kHz sampled .wav files are not acceptable. But you CAN convert from sln16 (signed linear 16kHz sampling rate, 16bit resolution) to g.722.
The trick then is getting your audio file to be an sln16 file in the first place.

This is simply a raw PCM file, as opposed to .wav. In Cool Edit Pro (I guess you can do the same with Audacity but haven't tried myself) simply save your 16kHz sample rate file as "PCM Raw Data" instead of .wav, which gives it the extension .pcm. You can then just change the file extension from pcm to sln16 before copying the file into Asterisk (with WinSCP or whatever). You then have your own wideband custom promt。

另外一個工具是sox, 它可以轉換取樣率,儲存為不同的格式。

參考:

http://www.voip-info.org/wiki/view/Convert+WAV+audio+files+for+use+in+Asterisk