在Freeswitch呼叫建立后播放音频文件

我正在从WebRTC浏览器和SIP客户端发起呼叫,并想使用endless_playback播放.wav文件,在呼叫被桥接到PTSN的另一方后。我尝试了两件事,但都不起作用。

a)使用拨号计划

<action application="endless_playback" data="wav文件路径"/> //选项1
<action application="bridge" data="呼叫信息"/>
<action application="endless_playback" data="wav文件路径"/> //选项2

问题是,在选项1中,文件会播放,但呼叫从未桥接,在选项2中,文件在接收呼叫挂断后播放。

b)使用LUA脚本

local TheSound = "wav文件路径"

if(session:ready()== truethen

    session:execute(“playback”,TheSound)

end

这似乎更有可能起作用,但它并没有起作用,因为我需要在桥接发生后执行播放。

我认为我需要将LUA脚本行更改为以下伪代码

监听呼叫连接事件,然后

    session:execute(“playback”,TheSound)

我该如何做到这一点?

点赞
用户565968
用户565968

我找到了一个使用 uuid_broadcast 的解决方法

第一步:在拨号计划中,在桥接之前添加以下行

<action application="export" data="nolocal:execute_on_answer=lua somescript.lua"/>
<action application="bridge" data="the bridge info"/>

请注意,如果在桥接之前设置了变量的值,并且需要在桥接后从 lua 脚本中访问它,请确保还要添加此行:

<action application="export" data="thevariable=${thevariable}"/>

第二步:在 somescript.lua 文件中,您需要首先确定呼叫的 uuid,然后可以向该呼叫广播声音,甚至可以选择将文件播放到哪个腿:

local theuuid = session:getVariable('uuid')

api = freeswitch.API()

local thesoundcast = "uuid_broadcast "..theuuid.."pathofsoundfile.wav aleg"
api:executeString(thesoundcast)

完成。

2020-03-08 17:15:42