tSIP: handling incoming DTMFs in Lua

tSIP 0.1.58.4 adds capability of reading received DTMF signs (currently only RFC2833 aka RTP telephone-event supported) in Lua scripts. Received signs are pushed into FIFO queue and then can be read back from Lua script using GetRxDtmf() function. This function returns either empty string (if DTMF FIFO is empty) or string containing single DTMF sign (removing this sign from queue at the same time). DTMF queue is cleared at each call start.

As tSIP is able to switch audio source to wave file during call (or switch between different wave files) this allows creating IVR applications. Note that as at the moment reaching end of source wave file terminates the call each file should contain few extra seconds of silence at the end to give some time margin to switch in Lua to another file, switch back to same file (creating loop) or switch to regular audio input (microphone).

-- "on call state" event script
callState = GetCallState()
if callState == 6 then
	-- call state established
	while 1 do
		Sleep(200)
		callState = GetCallState()
		if callState == 0 then
			-- call disconnected
			return
		end
		local dtmf = GetRxDtmf()
		if (dtmf ~= "") then
			print(string.format("Lua: DTMF received = %s\n", dtmf))
		end
	end
end

Back to howto list.


 "Cookie monsters": 3208359    Parse time: 0.001 s