概述

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

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

空空如常

求真得真

freeswitch使用mod_shout模块播放mp3的更多相关文章

  1. Python 用pygame模块播放MP3

    安装pygame(这个是python3,32位的) pip安装这个whl文件 装完就直接跑代码啦,很短的 import time import pygame file=r'C:\Users\chan\ ...

  2. 读取SD卡文件夹下的MP3文件和播放MP3文件

    首先获取SD卡path路径下的所有的MP3文件,并将文件名和文件大小存入List数组(此代码定义在FileUtils类中): /** * 读取目录中的Mp3文件的名字和大小 */ public Lis ...

  3. 遭遇flash播放mp3诡异问题

    在部分ie10+flash player 播放mp3,播放第二句话时,中断无法正常播放,(客户的机器上),自己公司的机器测试了几个,都没发现这个问题.其它浏览器(chrome,firefox)也没发现 ...

  4. Android命令行播放MP3音乐

    /*************************************************************************** * Android命令行播放MP3音乐 * 说 ...

  5. ios开发——实用技术篇Swift篇&播放MP3

    播放MP3 // MARK: - 播放MP3 /*----- mp3 ------*/ //定时器- func updateTime() { //获取音频播放器播放的进度,单位秒 var cuTime ...

  6. 在C语言控制台程序中播放MP3音乐

    游戏没有声音多单调. 这里做一个简单的范例,用 mciSendString 函数播放 MP3 格式的音乐,先看看代码吧: // 编译该范例前,请把 background.mp3 放在项目文件夹中 // ...

  7. ubuntu 13.10 Rhythmbox不能播放mp3 和中文乱码的问题

    1.ubuntu 13.10 Rhythmbox不能播放mp3的解决方法 软件中心搜索(ubuntu额外的版权受限软件)不带括号 2.中文乱码问题解决方法: 终端顺序操作 : 1.  sudo ged ...

  8. Ionic2 播放mp3功能实现

    在开发app的过程中有需要播放mp3的功能,一直想实现,但苦于具体的困难一直未能实现,经过一段时间的资料查询和测试,最终摸索出来,现记录如下: 1.最重要的是安装第三方插件ionic-audio,开源 ...

  9. VC播放mp3的方法

    1.使用msi库 #include <mmsystem.h> #pragma comment(lib,"winmm.lib") ....... //打开文件 MCI_O ...

随机推荐

  1. 前端面试题整理——手写flatern摊平数组

    // flatern 是摊平数组 function flat(arr) { const isDeep = arr.some(item => item instanceof Array) if(! ...

  2. .NET程序设计实验四

    实验四  文件操作 一.实验目的 1. 掌握窗口控件的使用方法: 2. 掌握文件系统的操作方法.File 类和 Directory类的使用. 二.实验要求 根据要求,编写 C#程序,并将程序代码和运行 ...

  3. 使用js实现复选框的全选、取消功能

    id为all的想设置全选的那个框的id,name为checkname[]的是每个小复选框: 第一种: <script> function checkAll() { var all=docu ...

  4. node安装和环境配置

    参考链接: https://www.cnblogs.com/zwjphp/p/14123746.html 一.安装环境 1.本机:Windows 10 (64位) 2.Node.js:v12.13.0 ...

  5. c语言实现循环单链表

    //初始化 Node*InitList() { Node*head=(Node*)malloc(sizeof(Node)); head->next=NULL; head->data=-1; ...

  6. Java中有关clone方法的用法

    一.clone在数组基本数据类型中的使用 public class Main { public static void main(String[] args) { int[] arr= {7,8,9} ...

  7. window升级Nginx1.10到1.12.2

    window升级Nginx较为简单,只需要修改配置文件,然后启动即可. 环境:window系统 服务器:10.123.98.92 Nginx目录:e:\hgeagle\nginx-1.10.1 旧版N ...

  8. CentOS7.x 离线安装和开机启动 supervisor 4.2.4

    CentOS7.x 服务器 离线安装 开机启动 supervisor 4.2.4

  9. 洛谷 P2392 kkksc03考前临时抱佛脚, dp / 深搜

    题目链接 P2392 kkksc03考前临时抱佛脚 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 题目 dp代码 #include <iostream> #includ ...

  10. 日常使用mobx的小技巧

    日常使用mobx的小技巧 由于自己开发的项目都是中小型项目,所以在技术选型上使用了mobx.但是使用过程中发现关于mobx的技术文章并不多.于是萌发出写这篇文章的想法.请轻喷. 更新控制store渲染 ...