freeswitch使用mod_shout模块播放mp3

 

概述

freeswitch 在对VOIP语音通话中,可以通过playback命令播放IVR语音文件。

默认情况下,freeswitch支持wav文件,也可以直接播放VOIP中常见编解码的G711文件、G729文件等,但是对mp3是不支持的。

通过查询freeswitch的官方文档,发现mod_shout模块是可以支持MP3文件的播放。

mod_shout模块默认不安装,可以根据需求来决定是否编译安装。

环境

centos:CentOS  release 7.0 (Final)或以上版本

freeswitch:v1.6.19

GCC:4.8.5

依赖

mod_shout模块安装需要第三方库支持,centos的yum源设置方法参见文档“freeswitch自带yum源配置方式”。

sudo yum install libshout-devel lame-devel libmpg123-devel

安装

回到freeswitch源码根目录,重新生成makefile。

./bootstrap.sh -j

./configure

编译安装mod_shout模块

cd  src/mod/formats/mod_shout/

make

sudo make install

ll /usr/local/freeswitch/mod/mod_shout*

-rwxr-xr-x. 1 root root   1322 May 19 11:43 /usr/local/freeswitch/mod/mod_shout.la

-rwxr-xr-x. 1 root root 168560 May 19 11:43 /usr/local/freeswitch/mod/mod_shout.so

配置

mod_shout模块安装好后,修改fs的配置。

上传MP3放音文件。

ll /usr/local/freeswitch/sounds/101-baidu-mp3.mp3

-rw-r--r--. 1 root root 12096 May 17 17:55 /usr/local/freeswitch/sounds/101-baidu-mp3.mp3

修改 /usr/local/freeswitch/conf/autoload_configs/modules.conf.xml文件。

<load module="mod_shout"/>

修改 /usr/local/freeswitch/conf/dialplan/test.xml文件。

<include>

        <context name="default">

                <extension name="test" continue="false">

                        <condition field="destination_number" expression="^(\d+)$">

                                <action application="answer"/>

                                <action application="playback" data="/usr/local/freeswitch/sounds/101-baidu-mp3.mp3"/>

                                <action application="hangup" data="CALL_REJECTED"/>

                        </condition>

                </extension>

        </context>

</include>

配置好后,启动freeswitch,并确认mod_shout模块启动正常。

freeswitch@localhost.localdomain> module_exists  mod_shout

true

测试

使用eyebeam注册1001账号到fs,并发起呼叫到1002,1001可以听到fs的IVR放音。

当我们不加载mod_shout模块的时候,日志如下。

EXECUTE sofia/internal/1001@10.55.55.137 playback(/usr/local/freeswitch/sounds/101-baidu-mp3.mp3)

2022-05-19 13:49:55.573314 [ERR] switch_core_file.c:272 Invalid file format [mp3] for [/usr/local/freeswitch/sounds/101-baidu-mp3.mp3]!

EXECUTE sofia/internal/1001@10.55.55.137 hangup(CALL_REJECTED)

重新加载了mod_shout模块,并发起呼叫,查看日志如下。

EXECUTE sofia/internal/1001@10.55.55.137 playback(/usr/local/freeswitch/sounds/101-baidu-mp3.mp3)

2022-05-19 11:57:20.393239 [DEBUG] switch_ivr_play_say.c:1498 Codec Activated L16@8000hz 1 channels 20ms

2022-05-19 11:57:20.473273 [DEBUG] switch_rtp.c:7273 Correct audio ip/port confirmed.

2022-05-19 11:57:20.613239 [DEBUG] sofia.c:7084 Channel sofia/internal/1001@10.55.55.137 entering state [ready][200]

2022-05-19 11:57:26.433297 [DEBUG] switch_ivr_play_say.c:1942 done playing file /usr/local/freeswitch/sounds/101-baidu-mp3.mp3

EXECUTE sofia/internal/1001@10.55.55.137 hangup(CALL_REJECTED)

总结

MP3文件是压缩格式,比常见的wav(pcm)小8倍左右,在空间占用和传输带宽上有较大的优势。

我们应该多一些不同的工具,在不同的应用场景下选择最合适的方案。

空空如常

求真得真

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值