freeswitch使用mod_shout模块播放mp3

boyanx3个月前技术教程10



概述

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

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



空空如常

求真得真

相关文章

一、自动装配基础 - @Component、@ComponentScan、@Enable 模块

目录前言1、起源2、Spring 模式注解 2.1、装配方式context:component-scan 方式@ComponentScan 方式 2.2、派生性3、Spring @Enable 模块驱...

Thymeleaf_thymeleaf属于前端吗

一、Thymeleaf简介Thymeleaf是用来开发Web和独立环境项目的服务器端的Java模版引擎Spring官方支持的服务的渲染模板中,并不包含jsp。而是Thymeleaf和Freemarke...

技术干货 | Flutter在线编程实践总结

1.Flutter架构Flutter的架构主要分成三层:Framework,Engine,Embedder。1.Framework使用dart实现,包括Material Design风格的Widget...

dubbo3.0 服务导入导出原理_dubbo服务引入

不管是服务导出还是服务引入,都发生在应用启动过程中,比如:在启动类上加上 @EnableDubbo 时,该注解上有一个 @DubboComponentScan 注解,@DubboComponentSc...

「项目实战」.待办事项之WebSocket Web客户端(二)

界面功能实现。界面编写采用第三方CSS库bootstrap 4.6.1版本,整个界面功能分为3部分:1.顶部显示应用的标题。其效果为文字居中对齐,并加入适当间隔的外边距,代码如下图1所示:2.左侧栏为...

中兴设备日常维护命令大全,网络工程师收藏!

设备基本信息检查查看设备配置命令:display current-configuration设备的配置文件是网络设备运行的核心,通过此命令可以查看设备当前运行的所有配置项。此命令的输出包含了设备的接口...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。