1 /* |
|
2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: The CNssRecognitionHandler class performs the recognition function. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef NSSVASCRECOGNITIONHANDLER_H |
|
20 #define NSSVASCRECOGNITIONHANDLER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <nsssispeechrecognitionutilityobserver.h> |
|
24 #include "nssvasmrecognitionhandler.h" |
|
25 #include "nssvasccontextmgr.h" |
|
26 #include "nssvasmadaptationeventhandler.h" |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 |
|
30 class CNssSiUtilityWrapper; |
|
31 class CNssTagMgr; |
|
32 class CNssVASDBBuilder; |
|
33 class CNssAdaptationItem; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 |
|
37 /** |
|
38 * |
|
39 * The CNssRecognitionHandler class performs the recognition function. |
|
40 * |
|
41 * @lib NssVASApi.lib |
|
42 * @since 2.8 |
|
43 */ |
|
44 |
|
45 class CNssRecognitionHandler :public CBase, |
|
46 public MNssRecognitionHandler, |
|
47 public MSISpeechRecognitionUtilityObserver |
|
48 { |
|
49 |
|
50 public: //enum |
|
51 |
|
52 enum TNssRState |
|
53 { |
|
54 EVasIdle, |
|
55 EVasWaitingForLoadModelsComplete, |
|
56 EVasWaitingForLoadLexiconComplete, |
|
57 EVasWaitingForLoadGrammarComplete, |
|
58 EVasWaitingForRecognitionReadyRecognitionInit, |
|
59 EVasWaitingForRecognize, |
|
60 EVasWaitingForRecordStarted, |
|
61 EVasWaitingForEouDetected, |
|
62 EVasWaitingForRecognitionComplete, |
|
63 EVasWaitingForSelectTag, |
|
64 EVasWaitingForUnloadRuleComplete, |
|
65 EVasWaitingForRecognitionReadyRejectTag, |
|
66 EVasDirectAdaptation, |
|
67 EVasIdleAdaptation, |
|
68 EVasCorrectingPluginDatabase |
|
69 }; |
|
70 |
|
71 |
|
72 public: // Constructors and destructor |
|
73 |
|
74 /** |
|
75 * Two-phased constructor. |
|
76 */ |
|
77 static CNssRecognitionHandler* NewL(); |
|
78 |
|
79 /** |
|
80 * Two-phased constructor. |
|
81 */ |
|
82 static CNssRecognitionHandler* NewLC(); |
|
83 |
|
84 /** |
|
85 * Destructor. |
|
86 */ |
|
87 virtual ~CNssRecognitionHandler(); |
|
88 |
|
89 public: // Functions from base classes |
|
90 |
|
91 /** |
|
92 * Perform initialization for the recognize funtion. |
|
93 * @since 2.0 |
|
94 * @param aInitCompleteHandler The event call back to receive recognize |
|
95 * init events. |
|
96 * @param aRecognitionVocabulary List of context, which are active in recognition. |
|
97 * @param aMaxResults The maximum number of voice tags to be recognized. |
|
98 * @return TNssRecognitionResult Return indicating request is valid. |
|
99 */ |
|
100 TNssRecognitionResult RecognizeInitL( |
|
101 MNssRecognizeInitCompleteHandler* aInitCompleteHandler, |
|
102 const CArrayPtrFlat<MNssContext>& aRecognitionVocabulary, |
|
103 TInt aMaxResults); |
|
104 /** |
|
105 * Perform initialization for the recognize funtion. Automatically loads |
|
106 * the commands and the names as recognition vocabulary. |
|
107 * @since 2.0 |
|
108 * @param aInitCompleteHandler The event call back to receive recognize |
|
109 * init events. |
|
110 * @param aMaxResults The maximum number of voice tags to be recognized. |
|
111 * @return TNssRecognitionResult Return indicating request is valid. |
|
112 */ |
|
113 TNssRecognitionResult RecognizeInitL( |
|
114 MNssRecognizeInitCompleteHandler* aInitCompleteHandler, |
|
115 TInt aMaxResults ); |
|
116 /** |
|
117 * From MNssRecognitionHandler Interface |
|
118 * Perform the recognize function. |
|
119 * @since 2.0 |
|
120 * @param aEventHandler The event call back to receive recognize events. |
|
121 * @return TNssRecognitionResult Return indicating request is valid. |
|
122 */ |
|
123 TNssRecognitionResult Recognize( MNssRecognizeEventHandler* aEventHandler ); |
|
124 |
|
125 /** |
|
126 * From MNssRecognitionHandler |
|
127 * Starts sampling already before RecognizeInitL and Recognize calls. |
|
128 * This is used to ensure that there is no delay between user notification |
|
129 * and sampling start. |
|
130 * |
|
131 * @since 3.2 |
|
132 * @param aInitCompleteHandler Callback handler |
|
133 * @return Return indicating request is valid. |
|
134 */ |
|
135 TNssRecognitionResult PreStartSampling( MNssRecognizeInitCompleteHandler* aInitCompleteHandler ); |
|
136 |
|
137 /** |
|
138 * From MNssRecognitionHandler Interface |
|
139 * Initiate the Select Tag event. |
|
140 * @since 2.0 |
|
141 * @param aClientTag The voice tag which was selected. The tag is owned |
|
142 * by the client. |
|
143 * @return TNssRecognitionResult Return indicating request is valid. |
|
144 */ |
|
145 TNssRecognitionResult SelectTagL( MNssTag* aClientTag ); |
|
146 |
|
147 /** |
|
148 * From MNssRecognitionHandler Interface |
|
149 * Initiate the Select Tag event. |
|
150 * @since 2.0 |
|
151 * @param aClientTag The voice tag which was selected. The tag is owned |
|
152 * by the client. |
|
153 * @param aNotifyHandlers If false, the global context handlers won't be notified. |
|
154 * @return TNssRecognitionResult Return indicating request is valid. |
|
155 */ |
|
156 TNssRecognitionResult SelectTagL( MNssTag* aClientTag, TBool aNotifyHandlers ); |
|
157 |
|
158 /** |
|
159 * Request Reject Tag, i.e. blacklisting. |
|
160 * @since 2.0 |
|
161 * @param aClientTagList The list of voice tags which is to be rejected, i.e. |
|
162 * blacklisted. The tag list is owned by the client. |
|
163 * @return TNssRecognitionResult Return indicating request is valid. |
|
164 */ |
|
165 TNssRecognitionResult RejectTagL( |
|
166 MNssRejectTagCompleteHandler* aRejectTagCompleteHandler, |
|
167 CArrayPtrFlat<MNssTag>* aClientTagList ); |
|
168 |
|
169 /** |
|
170 * From MNssRecognitionHandler Interface |
|
171 * Cancel the last recognition function. |
|
172 * @since 2.0 |
|
173 * @param - |
|
174 * @return TNssRecognitionResult Return indicating request is valid. |
|
175 */ |
|
176 TNssRecognitionResult Cancel(); |
|
177 |
|
178 /** |
|
179 * From MNssRecognitionHandler Interface |
|
180 * Get the adaptation item to adapt, when you know whether |
|
181 * the result was correct or not. |
|
182 * @since 2.0 |
|
183 * @param - |
|
184 * @return MNssAdaptationItem The adaptation item. |
|
185 */ |
|
186 MNssAdaptationItem* GetAdaptationItemL(); |
|
187 |
|
188 /** |
|
189 * From MSpeechRecognitionEvent Interface |
|
190 * Handle Speech Recognition Utility event |
|
191 * @since 2.0 |
|
192 * @param aEvent The event callback to receive Speech Recognition Utility |
|
193 * events. |
|
194 * @param aResult The result value associated with aEvent. |
|
195 * @return - |
|
196 */ |
|
197 void MsruoEvent( TUid aEvent, TInt aResult ); |
|
198 |
|
199 public: // New functions |
|
200 |
|
201 /** |
|
202 * AdaptL - called by adaptation item. Adapts the acoustic models. |
|
203 * @since 2.0 |
|
204 * @return None |
|
205 */ |
|
206 void AdaptL( MNssAdaptationEventHandler* aCallback, |
|
207 CSIClientResultSet* aResultSet, |
|
208 TInt aCorrect ); |
|
209 |
|
210 /** |
|
211 * RemoveAdaptationItem - When an adaptation item is destroyed, |
|
212 * it signals to its "host" recognition handler. This way, the host |
|
213 * knows to remove it from the list of active adaptation items. |
|
214 */ |
|
215 void RemoveAdaptationItem( CNssAdaptationItem* anItem ); |
|
216 |
|
217 private: |
|
218 |
|
219 /** |
|
220 * Constructor. |
|
221 */ |
|
222 CNssRecognitionHandler(); |
|
223 |
|
224 /** |
|
225 * By default Symbian 2nd phase constructor is private. |
|
226 */ |
|
227 void ConstructL(); |
|
228 |
|
229 /** |
|
230 * Perform required cleanup to get back to the EIdle state and issue the |
|
231 * HandleRecognizeInitError event with RecognizeInitFailed error code |
|
232 * @return void |
|
233 */ |
|
234 void CleanupRecognizeInitFailed(); |
|
235 |
|
236 /** |
|
237 * Perform required cleanup to get back to the EIdle state and issue the |
|
238 * HandleRecognizeError event with RecognizeFailed error code |
|
239 * @return void |
|
240 */ |
|
241 void CleanupRecognizeFailed(); |
|
242 |
|
243 /** |
|
244 * Perform required cleanup to get back to the EIdle state and issue the |
|
245 * HandleRejectTagError event with RejectTagFailed error code |
|
246 * @return void |
|
247 */ |
|
248 void CleanupRejectTagFailed(); |
|
249 |
|
250 /** |
|
251 * Perform required cleanup to get back to the EIdle state |
|
252 * @return void |
|
253 */ |
|
254 void Cleanup(); |
|
255 |
|
256 /** |
|
257 * Gracefully terminate and delete the SRF object, iSrsApi. |
|
258 * @return void |
|
259 */ |
|
260 void DeleteSrf(); |
|
261 |
|
262 /** |
|
263 * Delete context objects from iContextList |
|
264 * @return void |
|
265 */ |
|
266 void ClearContextList(); |
|
267 |
|
268 /** |
|
269 * Delete the tag objects from iTagList |
|
270 * @return void |
|
271 */ |
|
272 void ClearTagList(); |
|
273 |
|
274 /** |
|
275 * Delete the TRuleEntry objects from iRuleList |
|
276 * @return void |
|
277 */ |
|
278 void ClearRuleList(); |
|
279 |
|
280 /** |
|
281 * Delete entries from iContextStatus |
|
282 * @return void |
|
283 */ |
|
284 void ClearContextStatus(); |
|
285 |
|
286 /** |
|
287 * Cleanup and determine the correct event handler |
|
288 * @return void |
|
289 */ |
|
290 void UnexpectedEvent(); |
|
291 |
|
292 /** |
|
293 * Handle LoadModelsComplete SRF event |
|
294 * @return void |
|
295 */ |
|
296 void DoLoadModelsComplete(); |
|
297 |
|
298 /** |
|
299 * Handle LoadModelsFailed SRF event |
|
300 * @return void |
|
301 */ |
|
302 void DoLoadModelsFailed(); |
|
303 |
|
304 /** |
|
305 * Handle LoadLexiconComplete SRF event |
|
306 * @return void |
|
307 */ |
|
308 void DoLoadLexiconComplete(); |
|
309 |
|
310 /** |
|
311 * Handle LoadLexiconFailed SRF event |
|
312 * @return void |
|
313 */ |
|
314 void DoLoadLexiconFailed(); |
|
315 |
|
316 /** |
|
317 * Handle LoadGrammarComplete SRF event |
|
318 * @return void |
|
319 */ |
|
320 void DoLoadGrammarComplete(); |
|
321 |
|
322 /** |
|
323 * Handle LoadGrammarFailed SRF event |
|
324 * @return void |
|
325 */ |
|
326 void DoLoadGrammarFailed(); |
|
327 |
|
328 /** |
|
329 * Handle RecognitionReady SRF event |
|
330 * @return void |
|
331 */ |
|
332 void DoRecognitionReady(); |
|
333 |
|
334 /** |
|
335 * Handle RecognitionComplete SRF event |
|
336 * @return void |
|
337 */ |
|
338 void DoRecognitionComplete(); |
|
339 |
|
340 /** |
|
341 * Handle RecognitionFailedNoSpeech, RecognitionFailedTooEarly, |
|
342 * RecognitionFailedTooLong, and RecognitionFailedTooShort SRF events |
|
343 * @param aResult The Msruo event Result code. |
|
344 * @return void |
|
345 */ |
|
346 void DoRecognitionFailedNoSpeech( TInt aResult ); |
|
347 |
|
348 /** |
|
349 * Handle RecognitionFailedNoMatch SRF event |
|
350 * @return void |
|
351 */ |
|
352 void DoRecognitionFailedNoMatch(); |
|
353 |
|
354 /** |
|
355 * Handle RecognitionFailed SRF event |
|
356 * @return void |
|
357 */ |
|
358 void DoRecognitionFailed(); |
|
359 |
|
360 /** |
|
361 * Handle RecordStarted SRF event |
|
362 * @return void |
|
363 */ |
|
364 void DoRecordStarted(); |
|
365 |
|
366 /** |
|
367 * Handle RecordFailed SRF event |
|
368 * @param aResult The Msruo event Result code. |
|
369 * @return void |
|
370 */ |
|
371 void DoRecordFailed( TInt aResult ); |
|
372 |
|
373 /** |
|
374 * Handle EouDetected SRF event |
|
375 * @return void |
|
376 */ |
|
377 void DoEouDetected(); |
|
378 |
|
379 /** |
|
380 * Handle UnloadRuleComplete SRF event |
|
381 * @return void |
|
382 */ |
|
383 void DoUnloadRuleComplete(); |
|
384 |
|
385 /** |
|
386 * Handle UnloadRuleFailed SRF event |
|
387 * @return void |
|
388 */ |
|
389 void DoUnloadRuleFailed(); |
|
390 |
|
391 /** |
|
392 * Handle PreStartSampling SRSF event |
|
393 */ |
|
394 void DoPreStartSamplingComplete( TInt aError ); |
|
395 |
|
396 /** |
|
397 * Handle Tag Check for contexts |
|
398 * @return void |
|
399 */ |
|
400 void HandleTagCheckL(); |
|
401 |
|
402 /** |
|
403 * Create the SRF object, iSrsApi. |
|
404 * @return void |
|
405 */ |
|
406 void CreateSrfL(); |
|
407 |
|
408 /** |
|
409 * Perform those RecognizeInitL tasks, |
|
410 * which do not depend on vocabulary. |
|
411 */ |
|
412 MNssRecognitionHandler::TNssRecognitionResult CommonRecognizeInitL( |
|
413 MNssRecognizeInitCompleteHandler* aInitCompleteHandler, |
|
414 TInt aMaxResults ); |
|
415 |
|
416 |
|
417 struct TRuleEntry |
|
418 { |
|
419 TUint32 ruleId; |
|
420 TUint32 grammarId; |
|
421 }; |
|
422 |
|
423 |
|
424 private: // Data |
|
425 |
|
426 // Pointer to SRS Utility object. |
|
427 CNssSiUtilityWrapper* iSrsApi; |
|
428 |
|
429 // Pointer to SRS to ClientResultSet object, i.e. returned SRS data. |
|
430 CSIClientResultSet* iSIClientResultSet; |
|
431 |
|
432 // Pointer to RecognizeInit Complete Event Handler object. |
|
433 MNssRecognizeInitCompleteHandler* iInitCompleteHandler; |
|
434 |
|
435 // Pointer to Recognize Complete Event Handler object. |
|
436 MNssRecognizeEventHandler* iEventHandler; |
|
437 |
|
438 // Pointer to RejectTag Complete Event Handler object. |
|
439 MNssRejectTagCompleteHandler* iRejectTagCompleteHandler; |
|
440 |
|
441 // Pointer to VAS Database Builder object. |
|
442 CNssVASDBBuilder* iVasDBBuilder; |
|
443 |
|
444 // Pointer to Context Manager object. |
|
445 CNssContextMgr* iContextMgr; |
|
446 |
|
447 // Pointer to Context List object. |
|
448 TMNssContextList* iContextList; |
|
449 |
|
450 // Pointer to Tag Manager object. |
|
451 CNssTagMgr* iTagMgr; |
|
452 |
|
453 // Pointer to Tag List object. |
|
454 CArrayPtrFlat<CNssTag>* iTagList; |
|
455 |
|
456 // Pointer to Rule List object - used during RejectTag |
|
457 CArrayFixFlat<TRuleEntry>* iRuleList; |
|
458 |
|
459 // Context Status Array - True indicates tags for context exist |
|
460 // False indicates there are not tags in the context |
|
461 CArrayFixFlat<TBool>* iContextStatus; |
|
462 |
|
463 // Current Loop Counter used across asynch Context logic |
|
464 // during RecognizeInit |
|
465 TInt iContextCurrentLoopCount; |
|
466 |
|
467 // Number of contexts - used across asynch Context logic |
|
468 // during RecognizeInit |
|
469 TInt iContextCount; |
|
470 |
|
471 // Current Loop Counter used across asynch Result (tag) logic |
|
472 // during Recognize |
|
473 TInt iTagCurrentLoopCount; |
|
474 |
|
475 // Number of returned Results (tags) - used across asynch tag logic |
|
476 // during Recognize |
|
477 TInt iTagCount; |
|
478 |
|
479 // Current Loop Counter used across asynch RejectTag logic |
|
480 TInt iRejectTagCurrentLoopCount; |
|
481 |
|
482 // Number of rejected tags - used across asynch RejectTag logic |
|
483 TInt iRejectTagCount; |
|
484 |
|
485 // Maximum number of voice tags to be recognized, requested by client |
|
486 TInt iMaxResults; |
|
487 |
|
488 // The current recognition state. |
|
489 TNssRState iRState; |
|
490 |
|
491 // Array of adaptation items. Each MNssAdaptationItem is |
|
492 // internally linked to some "host" CNssRecognitionHandler. |
|
493 RPointerArray<CNssAdaptationItem> iAdaptItemArray; |
|
494 |
|
495 // Callback after adaptation |
|
496 MNssAdaptationEventHandler* iAdaptationHandler; |
|
497 |
|
498 // Wait loop |
|
499 CActiveSchedulerWait iWait; |
|
500 }; |
|
501 |
|
502 #endif // NSSVASCRECOGNITIONHANDLER_H |
|
503 |
|
504 // End of File |
|