http://blog.chinaunix.net/uid-26616507-id-3196482.html
http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_record_session
function grabaEntrada(tablaGraba, tablaGrabaMod) local razon, OWNER, destino = '', '', ''; local handle, k, v = nil, nil, nil OWNER = 'grabaEntrada' function mkDir(dir) local d = nil local OWNER = 'mkDir' local tmp = '' if type(dir) == 'string' then dir = backSlash(dir) for d in string.gfind(dir, ".-/") do tmp = tmp .. d end dir = tmp os.execute(string.format('MKDIR %s', string.gsub(dir, '/', '%\\') )) end end function onInputCBF(s, _type, obj, arg) local k, v = nil, nil if tablaGrabaMod._debug then for k, v in pairs(tablaGrabaMod) do print(string.format('tablaGrabaMod k-> %s v->%s\n', tostring(k), tostring(v))) end for k, v in pairs(obj) do printSessionFunctions(obj) print(string.format('obj k-> %s v->%s\n', tostring(k), tostring(v))) end if _type == 'table' then for k, v in pairs(_type) do print(string.format('_type k-> %s v->%s\n', tostring(k), tostring(v))) end end print(string.format('\n(%s == dtmf) and (obj.digit [%s] == [%s] tablaGrabaMod.dtmf)\n', _type, obj.digit, tablaGrabaMod.dtmf)) end if (_type == "dtmf") and (obj.digit == tablaGrabaMod.dtmf) then print(string.format('\nBREAK!!!\n')) return 'break' else print(string.format('\nCONTINUE!!!\n')) return '' end end if type(tablaGraba) ~= 'table' then razon= string.format('ERROR Parametros invalidos') return false end if type(tablaGrabaMod) ~= 'table' then tablaGrabaMod = { segundosMax = 7, umbralSilencio = 500, segundosInterrupcion = 3, dtmf = '#', _debug = false } end if type(tablaGraba.dir ) ~= 'string'then razon= string.format('ERROR tablaGraba.dir no es tipo string, Abortando') return false end if type(tablaGraba.audioT) ~= 'table' then razon= string.format('ERROR tablaGraba.audioT no es tipo table, Abortando') return false end if #tablaGraba.audioT == 0 then razon= string.format('WARNING tablaGraba.audioT NO tiene audios definidos, defina audios (tablaGraba.audioT = {\'aviso.wav\', \'beep.wav\' })') end if (type(tablaGraba.nombre) ~= 'string' ) or (tablaGraba.nombre == '') then tablaGraba.nombre = dameNombreUnico(CUUID)..'.wav' razon= string.format('WARNING tablaGraba.nombre NO definido e esta VACIO, valor Asignado [%s]', tablaGraba.nombre) end if type(tablaGrabaMod.dtmf) ~= 'string' or #tablaGrabaMod.dtmf == 0 then tablaGrabaMod.dtmf = '#' end if type(tablaGrabaMod._debug) ~= 'boolean' then tablaGrabaMod._debug = false end tablaGrabaMod.segundosMax = tonumber(tablaGrabaMod.segundosMax) or 7; tablaGrabaMod.umbralSilencio = tonumber(tablaGrabaMod.umbralSilencio) or 500; tablaGrabaMod.segundosInterrupcion = tonumber(tablaGrabaMod.segundosInterrupcion) or 3; tablaGrabaMod.dtmf = tablaGrabaMod.dtmf:sub(1,1) --Solo un caracter if tablaGraba.dir:sub(#tablaGraba.dir) ~= '/' then tablaGraba.dir = tablaGraba.dir..'/' end destino = string.format('%s%s', tablaGraba.dir, tablaGraba.nombre) handle = io.open(destino, 'w') if handle == nil then --Trata de crear el directorio sino existe local tmp, d, dir = '', '', '' dir = destino for d in string.gfind(dir, ".-/") do tmp = tmp .. d end dir = tmp mkDir(dir else handle:close() end session:execute('flush_dtmf') razon= string.format('LISTO path [%s] FLUSH_DTMF EJECUTADO!!', destino) parametros = creaInforme(razon, string.format('INFO %s', razon), CONSOLE_W, OWNER) if session:ready() then for k, v in pairs(tablaGraba.audioT) do session:streamFile(v) end session:setInputCallback('onInputCBF', ''); session:recordFile(destino, tablaGrabaMod.segundosMax, tablaGrabaMod.umbralSilencio, tablaGrabaMod.segundosInterrupcion); end end
http://wiki.freeswitch.org.cn/wiki/Channel_Variables.html#execute_on_answer
<context name="hanguponhook"> <extension name="hanguphook" continue="true"> <condition> <action application="set" data="api_hangup_hook=luarun rec_ins_db.lua ${uuid} ${answered_time} ${caller_id_number} ${sip_to_user} ${audiofile} "/> </condition> </extension> </context> <context name="audio"> <extension name="audio" continue="true"> <condition field="${trksno}" expression="^(\d+)$" break="on-true"> <action application="set" data="session_in_hangup_hook=true"/> <action application="set" data="RECORD_TITLE=Recording ${destination_number} ${caller_id_number} ${strftime(%Y-%m-%d %H:%M)}"/> <action application="set" data="RECORD_COPYRIGHT=(c) 2012"/> <action application="set" data="RECORD_SOFTWARE=Freeswitch"/> <action application="set" data="RECORD_ARTIST=Freeswitch"/>
<action application="set" data="RECORD_COMMENT=Freeswitch"/>
<action application="set" data="RECORD_DATE=${strftime(%Y-%m-%d %H:%M)}"/>
<action application="set" data="RECORD_STEREO=true"/>
<action application="record_session" data="${audiofile}"/>
<action application="set" data="execute_on_answer=execute_extension hanguphook XML hanguponhook"/>
</condition>
</extension>
</context>
<context name="default">
<extension name="rec">
<condition field="destination_number" expression="^${REC_IC}(\d+)$">
<action application="ring_ready"/>
<action application="lua" data="audio_rec.lua $1"/>
<action application="execute_extension" data="audio XML audio"/>
<action application="set" data="hangup_after_bridge=false"/>
<action application="bridge" data="sofia/internal/${REC_OG}$1@${sip_received_ip}:${sip_received_port}"/>
</condition>
</extension>
</context>
</include>