找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 7656|回复: 0

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

[复制链接]
发表于 2012-11-3 13:04:27 | 显示全部楼层 |阅读模式
语音系统中经常需要各种编码的音频原始文件(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/vi ... for+use+in+Asterisk
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|第一站论坛 ( 蜀ICP备06004864号-6 )

GMT+8, 2025-4-12 15:52 , Processed in 0.061688 second(s), 19 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表