如何计算通话时间?
当用户加入3200并等待10秒而没有人加入时,3200然后我要播放音频文件。
但是,请问我如何计算持续时间?我尝试了以下操作,但是它不起作用,因为它仅在电话挂断后才触发。但是我需要在呼叫开始时启动计数器。
/usr/local/freeswitch/script/wait.py
import os
from freeswitch import *
def hangup_hook(session, what):
consoleLog("info","hangup hook for %s!!\n\n" % what)
return
def input_callback(session, what, obj):
if (what == "dtmf"):
consoleLog("info", what + " " + obj.digit + "\n")
else:
consoleLog("info", what + " " + obj.serialize() + "\n")
return "pause"
def handler(session, args):
new_api_obj = API()
new_api_obj.executeString("pyrun postprocessing " + session.getVariable('caller_id_number'))
session.answer()
session.setHangupHook(hangup_hook)
session.setInputCallback(input_callback)
session.execute("conference", "$1-${domain_name}@ultrawideband")
session.hangup()
/usr/local/freeswitch/script/postprocessing.py
import os, sys, time
from freeswitch import *
def runtime(arg1):
time.sleep(10)
# is there 2 person or 1 person?
# if 1 person after 10 second play
#session.streamFile("/var/tmp/ivr/sara4.wav")
# if 2 person after 10 second do nothing
consoleLog( "info", "Caller: %s hung up 10s ago!\n" % arg1 )
现在,调用结束时,postprocessing.py正在运行
最佳答案
您可以使用sched_api命令。
在创建会议之前,请执行以下操作(这是Javascript示例):
const conferenceName = "test@conference";
apiExecute("sched_api", `+10 none jsrun /etc/freeswitch/countConferenceMembers.js
${conferenceName }`);
在countConferenceMembers.js脚本中检查会议成员计数。如果小于2,请播放声音然后挂断所有人。
const conferenceName = argv[0];
const count = apiExecute("conference", `${conferenceName } count`);
if (Number(count) < 2) {
apiExecute("conference", `${conferenceName} play SOUND_FILE_PATH`)
apiExecute("conference", `${conferenceName} hup all`)
}
Freeswitch命令
[https://freeswitch.org/confluence/display/FREESWITCH/mod_commands]
Freeswitch mod_conference
[https://freeswitch.org/confluence/display/FREESWITCH/mod_conference]
关于python - 计算一个freeswitch调用的持续时间,如果大于10秒则没有人加入,然后播放IVR,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22291803/