桥接呼叫后从Freeswitch播放音频文件



我正在从WebRTC浏览器和SIP客户端发起呼叫,并希望在通过PTSN将呼叫桥接到另一方后使用endless_playback播放.wav文件。我试了两件事,都不管用。

a( 使用拨号计划

<action application="endless_playback" data="the path of wav file"/> //option 1
<action application="bridge" data="the call info"/>
<action application="endless_playback" data="the path of wav file"/> //option 2

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

b( 使用LUA脚本

local TheSound = "the path of the wav file"
if (session:ready() == true) then
session:execute("playback", TheSound)
end

这似乎更有可能奏效,但没有,因为我需要在桥接发生后执行回放。

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

listen for call connected event and then
session:execute("playback", TheSound)

我怎么能这么做?

我使用uuid_broadcast找到了一个有效的解决方案

步骤1:在拨号计划中,在网桥之前添加此行

<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)

瞧。

最新更新