|
应用于语音识别控制
应用示例可查看_MATRIX 和_AUDIO方法,可自行修改相关方法属性及添加方法属性。有任何问题建议可在下方留言,功能持续改进更新
附:
function _SPEECH(vPort,fnGetData)
{
this.port = vPort;
if(vPort.indexOf('MOD')!=-1)
{
this.port = GetCurrentIOName();
}
this.startWord = ["小薇","小微","小V","小v","小唯","小魏","小威","晓薇"];
this.endWord = ["再见"];
this.action = false;
this.noWordLen = 8;
this.enterId = 0;
this.countMax =10;
this.count = 0;
this.mainLanguage = "zh-CN";
this.tranLaugage = "en";
this.speechText = "";
this.connectCount = 0;
this.match = function(aStr)
{
for(i=0;i<aStr.length;i++){
if(this.speechText.indexOf(setU2G(aStr[i]))!=-1){
return aStr[i];
}
}
return "";
}
this.dataProcess = function(vStr)
{
fnGetData(vStr)
}
this.getRev = function(vData)
{
if(vData.indexOf("language")!=-1)
{
//sendLog("vData",vData);
var strRevJson = JSON.parse(vData);
if(strRevJson.cmd == '2')
{
fnGetData(strRevJson.language);
}
}
}
this.connect = function(vSec)
{
this.connectCount++;
if(this.connectCount>vSec)
{
this.connectCount =0;
sendCodeString(this.port,"{\"method\":\"heartbeat\"}\r\n");
}
}
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;
}
}
if(arguments.length>=2)
{
sendCodeString(this.port,"{\"method\":\"heart\"}\r\n");
setStringReceive(this.port,this.getRev);
}
this.setActive = function(vEnable)
{
var strText = "";
if(vEnable==true)
{
this.count = this.countMax;
this.action = true;
strText = {"cmd":4,"voice":{"cmd":1,"inputLanguage":"1737","translate":"en"},"unit":{"cmd":2,"inputLanguage":"zh","startUnit":true,"endUnit":false},"speech":{"cmd":3,"words":"播报内容"},"lineColor":{"cmd":4,"color":"#ADFF2F","image":"voice2"}}
}else
{
this.count = 0;
this.action = false;
strText = {"cmd":4,"voice":{"cmd":1,"inputLanguage":"1737","translate":"en"},"unit":{"cmd":2,"inputLanguage":"zh","startUnit":true,"endUnit":false},"speech":{"cmd":3,"words":"播报内容"},"lineColor":{"cmd":4,"color":"#FFFFFF","image":"voice1"}}
}
var strjson = JSON.stringify(strText);
sendCodeString(this.port,strjson+"\r\n");
}
this.play = function(vSec,vStr)
{
if(arguments.length>=2)
{
var strText = {"cmd":3,"speech":{"cmd":3,"words":setU2G(vStr)}};
var strjson = JSON.stringify(strText);
delayCodeString(vSec,this.port,strjson+"\r\n");
}
else
{
var strText = {"cmd":3,"speech":{"cmd":3,"words":setU2G(vSec)}};
var strjson = JSON.stringify(strText);
delayCodeString(0.2,this.port,strjson+"\r\n");
}
}
this.setName = function(vStr1,vStr2)
{
sendLog("v1",vStr1);
var vCnName = " ";
var vEnName = " "
if(vStr1)
{
vCnName = vStr1;
}
else
{
vCnName = " ";
}
if(vStr2)
{
vEnName = vStr2;
}
else
{
vEnName = " ";
}
var vStr3 = "#ffffff";
if(arguments.length>=3)
{
vStr3 = arguments[2];
}
var strText = {"cmd":6,"changeName":{"cmd":6,"chineseName":vCnName,"englishName":vEnName,"textColor":vStr3,"textSize":30}};
var strjson = JSON.stringify(strText);
sendCodeString(this.port,strjson+"\r\n");
}
this.playGBK = function(vSec,vStr)
{
if(arguments.length>=2)
{
var strText = {"cmd":3,"speech":{"cmd":3,"words":vStr}};
var strjson = JSON.stringify(strText);
delayCodeString(vSec,this.port,strjson+"\r\n");
}
else
{
var strText = {"cmd":3,"speech":{"cmd":3,"words":vSec}};
var strjson = JSON.stringify(strText);
delayCodeString(0.2,this.port,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;
}
}
}
|
|