module(...,package.seeall)

require"audio"
require"common"

--ƵȼӦaudio.playӿеpriorityֵԽȼԽߣûԼȼ
--PWRON
--CALL
--SMS¶
--TTSTTS
PWRON,CALL,SMS,TTS = 3,2,1,0

local function testcb(r)
	print("testcb",r)
end

--ƵļԽӿڣÿδһдв
local function testplayfile()
	--βĬȼ
	--audio.play(CALL,"FILE","/ldata/call.mp3")
	--βȼ7
	--audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7)
	--βȼ7Ž߳testcbص
	--audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7,testcb)
	--ѭȼ7ûѭ(һβŽһ)
	audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7,nil,true)
	--ѭȼ7ѭΪ2000
	--audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7,nil,true,2000)
end


--ttsԽӿڣÿδһдв
--ãϺͨſƼ޹˾ʱ1830֡
local ttstr = "ãϺͨſƼ޹˾ʱ1830"
local function testplaytts()
	--βţĬȼ
	--audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)))
	--βţȼ7
	--audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7)
	--βţȼ7Ž߳testcbص
	--audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7,testcb)
	--ѭţȼ7ûѭ(һβŽһ)
	audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7,nil,true)
	--ѭţȼ7ѭΪ2000
	--audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7,nil,true,2000)
end


--ųͻԽӿڣÿδһifв
local function testplayconflict()	

	if true then
		--ѭ
		audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7,nil,true)
		--5Ӻѭſ
		sys.timer_start(audio.play,5000,PWRON,"FILE","/ldata/pwron.mp3",audiocore.VOL7,nil,true)
		
	end

	
	--[[
	if true then
		--ѭ
		audio.play(CALL,"FILE","/ldata/call.mp3",audiocore.VOL7,nil,true)
		--5Ӻ󣬳ѭ¶ȼᲥ
		sys.timer_start(audio.play,5000,SMS,"FILE","/ldata/sms.mp3",audiocore.VOL7,nil,true)
		
	end
	]]
	
	--[[
	if true then
		--ѭTTS
		audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7,nil,true)
		--10Ӻѭſ
		sys.timer_start(audio.play,10000,PWRON,"FILE","/ldata/pwron.mp3",audiocore.VOL7,nil,true)
		
	end
	]]
end

local speed=0
local function playTtsCbFnc(result)
    print("playTtsCbFnc",result)
    speed = speed+1
    if speed>100 then speed=0 end
    testPlayTts()
end

local function stopTtsCbFnc(result)
    print("stopTtsCbFnc",result)
    speed = speed+1
    if speed>100 then speed=0 end
    testPlayTts()
end

function testPlayTts()
    audio.playTTS(common.gb2312toucs2(ttstr),1,speed,playTtsCbFnc)
    --sys.timer_start(audio.stopTTS,5000,stopTtsCbFnc)
end


local function testtsnew()
	--ȼͬʱĲŲԣ1ʾֹͣǰţµĲ
	audio.setstrategy(1)
	audio.play(TTS,"TTS",common.binstohexs(common.gb2312toucs2(ttstr)),audiocore.VOL7)
end


--ÿδһдв
if string.match(sys.getcorever(),"TTS") then
	sys.timer_start(testplaytts,5000)
	--Ҫttsʱ󲥷µttsδ
	--sys.timer_loop_start(testtsnew,5000)
else
	sys.timer_start(testplayfile,5000)
end
--sys.timer_start(testplayconflict,5000)
