呼叫桥接后从 Freeswitch 播放音频文件
Play audio file from Freeswitch after call is bridged
我正在从 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}"/>
第2步:在somescript.lua文件中,你需要先确定通话的uuid,然后你就可以在那个通话中播放声音,甚至可以选择播放文件的哪一段:
local theuuid = session:getVariable('uuid')
api = freeswitch.API()
local thesoundcast = "uuid_broadcast "..theuuid.."pathofsoundfile.wav aleg"
api:executeString(thesoundcast)
瞧瞧。
我正在从 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}"/>
第2步:在somescript.lua文件中,你需要先确定通话的uuid,然后你就可以在那个通话中播放声音,甚至可以选择播放文件的哪一段:
local theuuid = session:getVariable('uuid')
api = freeswitch.API()
local thesoundcast = "uuid_broadcast "..theuuid.."pathofsoundfile.wav aleg"
api:executeString(thesoundcast)
瞧瞧。