编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

freeswitch使用mod_shout模块播放mp3

wxchong 2024-08-16 06:04:29 开源技术 20 ℃ 0 评论



概述

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+)#34;>
<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倍左右,在空间占用和传输带宽上有较大的优势。

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



空空如常

求真得真

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表