wav文件转成g722, g729编码的文件

语音系统中经常需要各种编码的音频原始文件(raw file),使用Asterisk 这个著名的IP-PBX软件附带的转码功能就可以实现。

它根据文件的后缀来确定编码格式。


如果asterisk已经在运行,使用asterisk -r 可以进入asterisk的命令行。

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

dev12*CLI> file convert
Usage: file convert
       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




你可能感兴趣的:(VoIP)