tSIP softphone: loop playback for outgoing calls

Script making call and playing audio file in loop.

-- config
local callTarget = "sip:100.82.171.212"
local wavFile = "tmp.wav"
-- end of config

local jsonString = [[
{
   "Calls" : {
      "DisconnectCallOnAudioError" : false
   }
}
]]
UpdateSettings(jsonString)	-- making sure call would not be disconnected at the end of wav file


Call(callTarget)
Sleep(500)
-- wait up to 30 s for connection
for i=1, 300 do
	callState = GetCallState()
	if callState == 6 then
		break
	elseif callState == 0 then
		print("Failed to initiate call\n")
		return
	end
	ret = CheckBreak()
	-- break on user request
	if ret ~= 0 then
		print ('User break\n')
		Hangup()
		return
	end	
	Sleep(100)
	print("Waiting for call confirmation...\n")
end

if callState ~= 6 then
	print("Timed out waiting for call confirmation\n")
	Hangup()
	return
end

print("Call is established\n")

audioErrCnt = GetAudioErrorCount()
SwitchAudioSource("aufile", wavFile)

while true do
	callState = GetCallState()
	if callState ~= 6 then
		return
	end
	ret = CheckBreak()
	-- break on user request
	if ret ~= 0 then
		print ('User break\n')
		break
	end
	local currentAudioErrCnt = GetAudioErrorCount()
	if currentAudioErrCnt ~= audioErrCnt then
		print(string.format("End-of-wav counter %d -> %d\n", audioErrCnt, currentAudioErrCnt)) 
		Sleep(100)
		SwitchAudioSource("aufile", wavFile)
		audioErrCnt = currentAudioErrCnt
	end
	Sleep(100)
end

Hangup()
  

Back to howto list