FreeSWITCH recording function

Source: Internet
Author: User
Tags lua mkdir freeswitch
FreeSWITCH recording function (2012-05-04-16:08) Tags: FreeSWITCH recording record Category: FreeSWITCH

Http://blog.chinaunix.net/uid-26616507-id-3196482.html

Http://wiki.freeswitch.org/wiki/Misc._Dialplan_Tools_record_session

Backup/usr/local/freeswitch/conf/dialplan/default.xml first. Then VI edit Default.xml, in <extension name= "Local_extension" >
<condition field= "Destination_number" expression= "^ (10[01][0-8]) $" >
You can record it by adding the following statement below. <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)"/>
<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= "$${base_dir}/recordings/archive/${strftime (%Y-%m-%d-%H-%M-%S)}_${ Destination_number}_${caller_id_number}.wav "/>
You should see that the recording will be stored automatically under the ${base_dir}/recordings/archive.


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 Fu Nction ONINPUTCBF (S, _type, obj, arg) Local k, V = nil, nil if Tablagrabamod._debug then for K, V in pairs (tabla  GRABAMOD) do print (String.Format (' Tablagrabamod k-> %s v->%s\n ', ToString (k), ToString (v))) End for K, V in pairs (obj) does printsessionfunctions (obj) print (String.Format (' obj k-> %s v->%s\n ', ToString (k ), ToString (v))) End If _type = = ' table ' then for K, V-pairs (_type) do print (String.Format (' _type k-&gt ;  %s v->%s\n ', ToString (k), ToString (v)) End end print (String.Format (' \ n (%s = = DTMF) and (obj.digit [%s] = = [%s] Tablag RABAMOD.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, Umbralsile Ncio = $, 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 Typ E (Tablagraba.audiot) ~= ' table ' then razon= string.format (' ERROR tablagraba.audiot no es tipo table, Abortando ') retur N False End If #tablaGraba. Audiot = = 0 Then razon= String.Format (' WARNING tablagraba.audiot NO tiene audios definidos, DeFina audios (Tablagraba.audiot = {\ ' A Viso.wav\ ', \ ' beep.wav\ ') ') End if (Type (tablagraba.nombre) ~= ' string ') or (Tablagraba.nombre = = ") then tab Lagraba.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 Typ E (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 (--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), CONSOL E_w, OWNER) if Session:ready () then for K, V in pairs (Tablagraba.audiot) do Session:streamfile (v) End Sessi 
		On: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) "/>         <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)}"/>   & nbsp     <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>   & nbsp </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 $"/>         <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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.