|
应用于手机软件程序控制
应用示例可查看_MATRIX 和_AUDIO方法,可自行修改相关方法属性及添加方法属性。有任何问题建议可在下方留言,功能持续改进更新
附:
function _MOBILE(iMax,fnGetData)
{
this.btnMax = iMax;
this.startWord = ["小薇","小微","小V","小v","小唯","小魏","小威"];
this.endWord = ["再见"];
this.noWordLen = 8;
this.enterId = 0;
this.client = null;
this.speechText = null;
this.count = 0;
this.countMax = 10;
this.action = false;
this.power = new Array();
this.name = new Array();
this.btnData = new Array();
this.setbtnData = function(iNum)
{
var sTemp = {"btnid":iNum,"btnname":this.name[iNum],"status":this.power[iNum]};
return sTemp;
}
this.getData = function()
{
this.btnData = new Array();
for(var i = 1;i<=this.btnMax;i++)
{
this.btnData.push(this.setbtnData(i));
}
var strtemp = {"success":1,"data":this.btnData};
return strtemp;
}
for(var i=0;i<=this.btnMax;i++)
{
this.power[i] = 1;
this.name[i] = "Button"+i;
}
this.setStatus = function(vID,vSta)
{
if(arguments.length>=2)
{
this.power[vID] = vSta;
}
this.sendCodeString(setU2G(JSON.stringify(this.getData())));
}
this.setActive = function(vEnable)
{
var strText = "";
if(vEnable==true)
{
this.count = this.countMax;
this.action = true;
}else
{
this.count = 0;
this.action = false;
}
}
this.noAction = function(vStr)
{
if(this.action == false)
{
if(this.find(this.startWord)==false && this.speechText.length>=this.noWordLen)
{
this.play(vStr);
}
}
else
{
this.action = false;
}
}
this.connect = function(handle)
{
this.client = handle;
fnGetData(handle,"Connect",strAndroid,"");
}
this.receive = function(data,handle)
{
this.nowHand = handle;
var strAndroid= getTcpString(data);
//sendLog("strAndroid",strAndroid);
if(strAndroid.indexOf("enquire")!=-1)
{
fnGetData(handle,"Status",strAndroid,"");
}
else if(strAndroid.indexOf("control")!=-1)
{
var strRevJson = JSON.parse(strAndroid);
fnGetData(handle,"Button",parseInt(strRevJson.control[0].btnid),parseInt(strRevJson.control[0].status));
}
else if(strAndroid.indexOf("voice")!=-1)
{
var strRevJson = JSON.parse(strAndroid);
fnGetData(handle,"ASR",strRevJson.voice[0].speedtext,"");
}
}
this.sendCodeString = function(vStr)
{
sendTcpServer(this.client,vStr+"\r\n");
}
setTcpServer(18081,this.receive,this.connect);
this.play = function(vSec,vStr)
{
if(arguments.length>=2)
{
var strText = {"success":2,"data":[{"text":setU2G(vStr)}]};
var strjson = JSON.stringify(strText);
delay(vSec,function(){sendTcpServer(this.client,strjson+"\r\n");});
}
else
{
var strText = {"success":2,"data":[{"text":setU2G(vSec)}]};
var strjson = JSON.stringify(strText);
sendTcpServer(this.client,strjson+"\r\n");
}
}
this.find = function(aStr1,aStr2)
{
var findCount =0;
for(var i=0;i<arguments.length;i++)
{
for(j=0;j<arguments[i].length;j++){
if(this.speechText.indexOf(setU2G(arguments[i][j]))!=-1){
findCount++;
break;
}
}
}
if(findCount==arguments.length)
{
return true;
}
else
{
return false;
}
}
}
|
|