/* ----------------------------------------------------------------------------- This source file is part of OpenSpace3D For the latest info, see http://www.openspace3d.com Copyright (c) 2012 I-maginer This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, or go to http://www.gnu.org/copyleft/lesser.txt ----------------------------------------------------------------------------- */ struct PlugRec = [ PREC_instance : PInstance, PREC_XMLfile : XMLfile, PREC_ObjReco : ObjRecognition, PREC_Volume : I, PREC_EnableDict : I ]mkPlugRec;; fun deleteOb(inst, instRec)= _DSRecognition instRec.PREC_ObjReco; set instRec.PREC_ObjReco = nil; 0;; fun cbReadText(recognition, instRec, recoText)= let XMLgetMarkByValue instRec.PREC_XMLfile "wordlist" -> eventlistMark in let XMLgetMarkByValueAndParamValueFromMark eventlistMark "word" "value" (strlowercase recoText) -> wordmark in if wordmark == nil then nil else let XMLgetParam wordmark.XMLfather "value" -> event in ( SendPluginEvent instRec.PREC_instance event nil nil; SendPluginEvent instRec.PREC_instance "Word recognized" recoText nil; ); 0;; fun cbReadTextsAlt(recognition, instRec, recoText)= 0;; fun createGrammar(instRec) = let XMLgetMarkByValue instRec.PREC_XMLfile "wordlist" -> eventlistMark in let XMLgetMarksByValueFromMark eventlistMark "event" -> levent in while levent != nil do ( let hd levent -> eventmark in let XMLgetParam eventmark "value" -> event in let XMLgetMarksByValueFromMark eventmark "word" -> lword in while lword != nil do ( let hd lword -> wordmark in let XMLgetParam wordmark "value" -> word in _AddRecognitionWord instRec.PREC_ObjReco event word; set lword = tl lword; ); set levent = tl levent; ); 0;; fun cbRecognitionEnd(recognition, instRec)= SendPluginEvent instRec.PREC_instance "End" nil nil; 0;; fun cbRecognitionStart(recognition, instRec)= SendPluginEvent instRec.PREC_instance "Start" nil nil; 0;; fun enableReco(inst, from, action, param, rep, instRec) = if instRec.PREC_ObjReco != nil then nil else ( set instRec.PREC_ObjReco = _CRRecognition _channel; if !instRec.PREC_EnableDict then nil else createGrammar instRec; _CBRecognitionText instRec.PREC_ObjReco @cbReadText instRec; _CBRecognitionTextsAlt instRec.PREC_ObjReco @cbReadTextsAlt instRec; _SetRecogntionVolume instRec.PREC_ObjReco instRec.PREC_Volume; _CBRecognitionEnd instRec.PREC_ObjReco @cbRecognitionEnd instRec; _CBRecognitionStart instRec.PREC_ObjReco @cbRecognitionStart instRec; ); 0;; fun disableReco(inst, from, action, param, rep, instRec) = _DSRecognition instRec.PREC_ObjReco; set instRec.PREC_ObjReco = nil; 0;; fun setVolumeReco(inst, from, action, param, rep, instRec) = if (atoi param) == nil then nil else ( set instRec.PREC_Volume = atoi param; _SetRecogntionVolume instRec.PREC_ObjReco instRec.PREC_Volume; ); 0;; fun newOb(inst)= let XMLloadString webtostr (getPluginInstanceParam inst "xmldata") -> xmldata in let atoi (getPluginInstanceParam inst "enableReco") -> initStartReco in let atoi (getPluginInstanceParam inst "enableDict") -> initStartDict in let if initStartReco == nil then 1 else initStartReco -> initStartReco in let if initStartDict == nil then 1 else initStartDict -> initStartDict in let atoi (getPluginInstanceParam inst "volume") -> volume in let mkPlugRec [inst xmldata nil volume initStartDict] -> instRec in ( if !initStartReco then nil else ( set instRec.PREC_ObjReco = _CRRecognition _channel; if !initStartDict then nil else createGrammar instRec; _CBRecognitionText instRec.PREC_ObjReco @cbReadText instRec; _CBRecognitionTextsAlt instRec.PREC_ObjReco @cbReadTextsAlt instRec; _SetRecogntionVolume instRec.PREC_ObjReco volume; _CBRecognitionEnd instRec.PREC_ObjReco @cbRecognitionEnd instRec; _CBRecognitionStart instRec.PREC_ObjReco @cbRecognitionStart instRec; ); PluginRegisterAction inst "Enable" mkfun6 @enableReco instRec; PluginRegisterAction inst "Disable" mkfun6 @disableReco instRec; PluginRegisterAction inst "Set volume" mkfun6 @setVolumeReco instRec; setPluginInstanceCbDel inst mkfun2 @deleteOb instRec; ); 0;; fun IniPlug(file)= PlugRegister @newOb nil; setPluginEditor @dynamicedit; 0;;