local amr_voice_2g="/ldata/alarm.amr"
local voice_data=""
local function play_amr_voice()
--将test.amr音频文件的数据读出到voice_data
voice_data=""
local length = io.fileSize(amr_voice_2g)
local data,tmp
local m=length/1024
local n=length%1024
if m~=0 then
for i=1,m,1 do
data=io.readStream(amr_voice_2g, (i-1)*1024, 1024)
voice_data=voice_data..data
end
end
if n~=0 then
data=io.readStream(amr_voamr_voice_2gice_4g, m*1024, n)
voice_data=voice_data..data
end
--log.info("voice_data is len :",voice_data:len())
--log.info("voice_data",voice_data)
--将存放在voice_data里的字符串:#!AMR.<?.緁y徉.......(省略) 传给cc.transVoice()
cc.transVoice(voice_data)
end
--- “通话已建立”消息处理函数
-- @string num,建立通话的对方号码
-- @return 无
local function connected(num)
log.info("testCall.connected")
--接通后5秒后调用 play_amr_voice 在通话中发送test.amr中的音频到对端
sys.timerStart(play_amr_voice,5000)
--50秒之后主动结束通话
sys.timerStart(cc.hangUp,50000,num)
end