freeswitch录音功能

   首先备份/usr/local/freeswitch/conf/dialplan/default.xml 。
然后vi编辑default.xml ,在
<extension name="Local_Extension">
     <condition field="destination_number" expression="^(10[01][0-8])$">
下面加入以下语句即可录音。
<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) 2011"/>
   <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"/>
大家应该看明白了,录音会自动存放在${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

	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>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值