66 using System . ServiceModel ;
77 using System . ServiceModel . Web ;
88 using System . Drawing ;
9+ using System . Speech ;
10+ using System . Speech . Recognition ;
911 using OSAE ;
1012
1113 [ ServiceContract ]
@@ -25,19 +27,23 @@ public interface IRestService
2527 Boolean ExecuteMethod ( string name , string method , string param1 , string param2 ) ;
2628
2729 [ OperationContract ]
28- [ WebInvoke ( UriTemplate = "object/add?name={name}&alias={alias&desc }&desc={description}&type={type}&address={address}&container={container}&enabled={enabled}" ,
30+ [ WebInvoke ( UriTemplate = "object/add?name={name}&alias={alias}&desc={description}&type={type}&address={address}&container={container}&enabled={enabled}" ,
2931 RequestFormat = WebMessageFormat . Json , ResponseFormat = WebMessageFormat . Json ) ]
3032 Boolean AddObject ( string name , string alias , string description , string type , string address , string container , string enabled ) ;
3133
3234 [ OperationContract ]
33- [ WebInvoke ( UriTemplate = "object/update?oldName={oldName}&newName={newName}&alias={alias&desc} ={description}&type={type}&address={address}&container={container}&enabled={enabled}" ,
35+ [ WebInvoke ( UriTemplate = "object/update?oldName={oldName}&newName={newName}&alias={alias} &desc={description}&type={type}&address={address}&container={container}&enabled={enabled}" ,
3436 RequestFormat = WebMessageFormat . Json , ResponseFormat = WebMessageFormat . Json ) ]
3537 Boolean UpdateObject ( string oldName , string newName , string alias , string description , string type , string address , string container , string enabled ) ;
3638
3739 [ OperationContract ]
3840 [ WebGet ( UriTemplate = "objects/type/{type}" , RequestFormat = WebMessageFormat . Json , ResponseFormat = WebMessageFormat . Json ) ]
3941 OSAEObjectCollection GetObjectsByType ( string type ) ;
4042
43+ [ OperationContract ]
44+ [ WebGet ( UriTemplate = "objects/basetype/{type}" , RequestFormat = WebMessageFormat . Json , ResponseFormat = WebMessageFormat . Json ) ]
45+ OSAEObjectCollection GetObjectsByBaseType ( string type ) ;
46+
4147 [ OperationContract ]
4248 [ WebGet ( UriTemplate = "objects/container/{container}" , RequestFormat = WebMessageFormat . Json , ResponseFormat = WebMessageFormat . Json ) ]
4349 OSAEObjectCollection GetObjectsByContainer ( string container ) ;
@@ -86,7 +92,9 @@ public interface IRestService
8692 public class api : IRestService
8793 {
8894 private Logging logging = Logging . GetLogger ( "Rest" ) ;
89-
95+ private OSAE . General . OSAELog Log = new OSAE . General . OSAELog ( ) ;
96+ SpeechRecognitionEngine oRecognizer = new SpeechRecognitionEngine ( ) ;
97+
9098 public OSAEObject GetObject ( string name )
9199 {
92100 // lookup object
@@ -113,6 +121,18 @@ public OSAEObjectCollection GetObjectsByType(string type)
113121 return objects ;
114122 }
115123
124+ public OSAEObjectCollection GetObjectsByBaseType ( string type )
125+ {
126+ OSAEObjectCollection objects = OSAEObjectManager . GetObjectsByBaseType ( type ) ;
127+
128+ foreach ( OSAEObject oObj in objects )
129+ {
130+ oObj . Properties = getProperties ( oObj . Name ) ;
131+ }
132+
133+ return objects ;
134+ }
135+
116136 public OSAEObjectCollection GetObjectsByContainer ( string container )
117137 {
118138 OSAEObjectCollection objects = OSAEObjectManager . GetObjectsByContainer ( container ) ;
@@ -134,6 +154,23 @@ public Boolean ExecuteMethod(string name, string method, string param1, string p
134154
135155 public Boolean SendPattern ( string match )
136156 {
157+
158+ try
159+ {
160+ oRecognizer . SpeechRecognized += new EventHandler < SpeechRecognizedEventArgs > ( oRecognizer_SpeechRecognized ) ;
161+ //oRecognizer.AudioStateChanged += new EventHandler<AudioStateChangedEventArgs>(oRecognizer_StateChanged);
162+ }
163+ catch ( Exception ex )
164+ {
165+ Log . Error ( "Unable to configure oRecognizer" , ex ) ;
166+ }
167+
168+ oRecognizer = OSAEGrammar . Load_Direct_Grammar ( oRecognizer ) ;
169+ oRecognizer = OSAEGrammar . Load_OSA_Grammar ( oRecognizer ) ;
170+
171+
172+
173+
137174 //REPLACE WITH GRAMMAR
138175
139176
@@ -255,9 +292,7 @@ private Boolean StringToBoolean(string passedvalue)
255292 // otherwise it is probably a "1" or "0" and we will try to convert that to boolean
256293 int intvalue ;
257294 if ( Int32 . TryParse ( passedvalue , out intvalue ) )
258- {
259295 booleanvalue = Convert . ToBoolean ( intvalue ) ;
260- }
261296 }
262297
263298 return booleanvalue ;
@@ -300,6 +335,52 @@ public List<OSAEStateHistory> GetStateHistory(string objName, string from, strin
300335 return list ;
301336 }
302337
338+ private void oRecognizer_SpeechRecognized ( object sender , System . Speech . Recognition . SpeechRecognizedEventArgs e )
339+ {
340+ string gCurrentUser = "Unidentified Person" ;
341+ try
342+ {
343+ RecognitionResult result = e . Result ;
344+ SemanticValue semantics = e . Result . Semantics ;
345+ string scriptParameter = "" ;
346+ if ( e . Result . Semantics . ContainsKey ( "PARAM1" ) )
347+ {
348+ string temp = e . Result . Semantics [ "PARAM1" ] . Value . ToString ( ) . Replace ( "'s" , "" ) . Replace ( "'S" , "" ) ;
349+ if ( temp . ToUpper ( ) == "I" || temp . ToUpper ( ) == "ME" || temp . ToUpper ( ) == "MY" ) temp = gCurrentUser ;
350+ if ( temp . ToUpper ( ) == "YOU" || temp . ToUpper ( ) == "YOUR" ) temp = "SYSTEM" ;
351+ scriptParameter = temp ;
352+ if ( e . Result . Semantics . ContainsKey ( "PARAM2" ) )
353+ {
354+ temp = e . Result . Semantics [ "PARAM2" ] . Value . ToString ( ) . Replace ( "'s" , "" ) . Replace ( "'S" , "" ) ;
355+ if ( temp . ToUpper ( ) == "I" || temp . ToUpper ( ) == "ME" || temp . ToUpper ( ) == "MY" ) temp = gCurrentUser ;
356+ if ( temp . ToUpper ( ) == "YOU" || temp . ToUpper ( ) == "YOUR" ) temp = "SYSTEM" ;
357+ scriptParameter += "," + temp ;
358+ if ( e . Result . Semantics . ContainsKey ( "PARAM3" ) )
359+ {
360+ temp = e . Result . Semantics [ "PARAM3" ] . Value . ToString ( ) . Replace ( "'s" , "" ) . Replace ( "'S" , "" ) ;
361+ if ( temp . ToUpper ( ) == "I" || temp . ToUpper ( ) == "ME" || temp . ToUpper ( ) == "MY" ) temp = gCurrentUser ;
362+ if ( temp . ToUpper ( ) == "YOU" || temp . ToUpper ( ) == "YOUR" ) temp = "SYSTEM" ;
363+ scriptParameter += "," + temp ;
364+ }
365+ }
366+ }
367+ string sResults = "" ;
368+ if ( result . Grammar . Name . ToString ( ) == "Direct Match" )
369+ {
370+ Log . Debug ( "Searching for: " + sResults ) ;
371+ sResults = OSAEGrammar . SearchForMeaning ( result . Text , scriptParameter , gCurrentUser ) ;
372+ }
373+ else
374+ {
375+ Log . Debug ( "Searching for: " + sResults ) ;
376+ sResults = OSAEGrammar . SearchForMeaning ( result . Grammar . Name . ToString ( ) , scriptParameter , gCurrentUser ) ;
377+ }
378+
379+ Log . Info ( "Search Results: " + sResults ) ;
380+ }
381+ catch ( Exception ex )
382+ { Log . Error ( "Error in _SpeechRecognized!" , ex ) ; }
383+ }
303384 }
304385
305386 public class OSAEPropertyHistory
0 commit comments