|
1 /* |
|
2 * Copyright (c) 2004-2006 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 CNssSpeechItem provides speech mechanism to request services |
|
15 * from SRS. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 |
|
23 #include "srsfbldvariant.hrh" |
|
24 #include <nssvascoreconstant.h> |
|
25 #include "nssvascspeechitem.h" |
|
26 #include "nssvascspeechitemtrainer.h" |
|
27 #include "nssvasctag.h" |
|
28 #include "nssvasctrainingparameters.h" |
|
29 #include "nssvasdbkonsts.h" |
|
30 #include "rubydebug.h" |
|
31 |
|
32 // CONSTANTS |
|
33 // This value is used for maximum retry times |
|
34 const TInt KVASSpeechItemMaxRetry = 2; |
|
35 // This value is used to reset the retry number |
|
36 const TInt KVASSpeechItemResetRetry = 0; |
|
37 |
|
38 // Character which is used instead of separator marker |
|
39 _LIT( KEmptySpace, " " ); |
|
40 |
|
41 // Panic category |
|
42 _LIT( KSpeechItemPanic, "CNssSpeechItem" ); |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CNssSpeechItem::CNssSpeechItem |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CNssSpeechItem::CNssSpeechItem( CNssContext& aContext, |
|
51 CNssSpeechItemSrsPortal& aPortal, |
|
52 CNssSpeechItemTrainer& aTrainer ) |
|
53 : iRuleID( KInvalidRuleID ), |
|
54 iTrainedType( TNssVasCoreConstant::EVasNotTrained ), |
|
55 iState( TNssSpeechItemConstant::EIdle ), |
|
56 iContext( aContext ), |
|
57 iPortal( aPortal ), |
|
58 iTrainer( aTrainer ), |
|
59 iTagId( KNssVASDbDefaultValue ), |
|
60 iTrained( EFalse ), |
|
61 iRecover( EFalse ) |
|
62 { |
|
63 //Register to Portal |
|
64 iPortal.Register(); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CNssSpeechItem::~CNssSpeechItem |
|
69 // Destructor |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CNssSpeechItem::~CNssSpeechItem() |
|
73 { |
|
74 delete iText; |
|
75 delete iTrimmedText; |
|
76 |
|
77 if ( iTtsData ) |
|
78 { |
|
79 CleanPlayback(); |
|
80 } |
|
81 |
|
82 iPortal.Deregister(); // Deregister to Portal |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CNssSpeechItem::NewL |
|
87 // Two-phased constructor. |
|
88 // This is for new SpeechItem |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CNssSpeechItem* CNssSpeechItem::NewL( CNssContext& aContext, |
|
92 CNssSpeechItemSrsPortal& aPortal, |
|
93 CNssSpeechItemTrainer& aTrainer ) |
|
94 { |
|
95 CNssSpeechItem* self = new (ELeave) CNssSpeechItem( aContext, aPortal, aTrainer ); |
|
96 return self; |
|
97 } |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CNssSpeechItem::ConstructL |
|
101 // Symbian 2nd phase constructor can leave. |
|
102 // This is overloaded function for SpeechItem from database |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 void CNssSpeechItem::ConstructL( TUint32 aRuleID, const TDesC& aText ) |
|
106 { |
|
107 SetTextL( aText ); |
|
108 iRuleID = aRuleID; |
|
109 } |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CNssSpeechItem::NewLC |
|
113 // Two-phased constructor. |
|
114 // This is overloaded function for SpeechItem from database |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 CNssSpeechItem* CNssSpeechItem::NewLC( CNssContext& aContext, |
|
118 CNssSpeechItemSrsPortal& aPortal, |
|
119 CNssSpeechItemTrainer& aTrainer, |
|
120 TUint32 aRuleID, const TDesC& aText ) |
|
121 { |
|
122 CNssSpeechItem* self = new (ELeave) CNssSpeechItem( aContext, aPortal, aTrainer ); |
|
123 CleanupStack::PushL( self ); |
|
124 self->ConstructL( aRuleID, aText ); |
|
125 return self; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CNssSpeechItem::NewL |
|
130 // Two-phased constructor. |
|
131 // This is overloaded function for SpeechItem from database |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 CNssSpeechItem* CNssSpeechItem::NewL( CNssContext& aContext, |
|
135 CNssSpeechItemSrsPortal& aPortal, |
|
136 CNssSpeechItemTrainer& aTrainer, |
|
137 TUint32 aRuleID, |
|
138 const TDesC& aText ) |
|
139 { |
|
140 CNssSpeechItem* self = NewLC( aContext, aPortal, aTrainer, aRuleID, |
|
141 aText ); |
|
142 CleanupStack::Pop( self ); |
|
143 return self; |
|
144 } |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 // CNssSpeechItem::PlayL |
|
148 // Method to do play operation. In SI, this means synthesizing the name. |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 MNssSpeechItem::TNssSpeechItemResult |
|
152 CNssSpeechItem::PlayL( MNssPlayEventHandler* aPlayEventHandler, TLanguage aLanguage ) |
|
153 { |
|
154 if ( !iTtsData ) |
|
155 { |
|
156 iTtsData = new (ELeave) TTtsData; |
|
157 } |
|
158 |
|
159 iTtsData->iStyle.iLanguage = aLanguage; |
|
160 |
|
161 RUBY_DEBUG1( "CNssSpeechItem::PlayL lang id: %d", iTtsData->iStyle.iLanguage ); |
|
162 |
|
163 // Verify for valid state |
|
164 if (!(iState == TNssSpeechItemConstant::EIdle || |
|
165 iState == TNssSpeechItemConstant::ETrainComplete)) |
|
166 { |
|
167 RUBY_DEBUG0( "CNssSpeechItem::PlayL - wrong state" ); |
|
168 |
|
169 return MNssSpeechItem::EVasUnexpectedRequest; |
|
170 } |
|
171 |
|
172 // Verify for valid event handler |
|
173 if ( aPlayEventHandler ) |
|
174 { |
|
175 iPlayEventHandler = aPlayEventHandler; |
|
176 } |
|
177 else |
|
178 { |
|
179 return MNssSpeechItem::EVasInvalidParameter; |
|
180 } |
|
181 |
|
182 TRAPD( err, DoPlayL() ); |
|
183 if ( err != KErrNone ) |
|
184 { |
|
185 CleanPlayback(); |
|
186 return MNssSpeechItem::EVasPlayFailed; |
|
187 } |
|
188 |
|
189 return MNssSpeechItem::EVasErrorNone; |
|
190 |
|
191 } |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CNssSpeechItem::PlayL |
|
195 // Method to do play operation. In SI, this means synthesizing the name. |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 MNssSpeechItem::TNssSpeechItemResult |
|
199 CNssSpeechItem::PlayL( MNssPlayEventHandler* aPlayEventHandler ) |
|
200 { |
|
201 // Use UI language by default |
|
202 // If synthesis engine does not support UI language for some reason, |
|
203 // then language identification will be used instead |
|
204 return PlayL( aPlayEventHandler, User::Language() ); |
|
205 } |
|
206 |
|
207 // ----------------------------------------------------------------------------- |
|
208 // CNssSpeechItem::DoPlayL |
|
209 // Starts playing. Assumes that all checks have been done earlier. |
|
210 // ----------------------------------------------------------------------------- |
|
211 // |
|
212 void CNssSpeechItem::DoPlayL() |
|
213 { |
|
214 TTtsData* d = iTtsData; |
|
215 |
|
216 d->iTts = CNssTtsUtilityWrapper::NewL( *this ); |
|
217 d->iStyleID = d->iTts->AddStyleL( d->iStyle ); |
|
218 |
|
219 d->iParsedText = CTtsParsedText::NewL(); |
|
220 d->iParsedText->SetTextL( Text() ); |
|
221 |
|
222 d->iSegment.SetTextPtr( d->iParsedText->Text() ); |
|
223 d->iSegment.SetStyleID( d->iStyleID ); |
|
224 |
|
225 d->iParsedText->AddSegmentL( d->iSegment ); |
|
226 |
|
227 d->iTts->OpenAndPlayParsedTextL( *d->iParsedText ); |
|
228 |
|
229 iOldState = iState; |
|
230 iState = TNssSpeechItemConstant::EPlayStart; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CNssSpeechItem::CleanPlayback |
|
235 // Cleans playback and releases all memory. |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CNssSpeechItem::CleanPlayback() |
|
239 { |
|
240 TTtsData* d = iTtsData; |
|
241 |
|
242 if ( d->iTts ) |
|
243 { |
|
244 d->iTts->Stop(); |
|
245 d->iTts->Close(); |
|
246 } |
|
247 |
|
248 delete d->iParsedText; |
|
249 d->iParsedText = NULL; |
|
250 |
|
251 delete d->iTts; |
|
252 d->iTts = NULL; |
|
253 |
|
254 delete iTtsData; |
|
255 iTtsData = NULL; |
|
256 |
|
257 iState = iOldState; |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // CNssSpeechItem::MakePlayCallback |
|
262 // Makes callback to VAS client. Uses error status from TTS Utility to decide |
|
263 // callback and parameters. |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CNssSpeechItem::MakePlayCallback( TInt aResult ) |
|
267 { |
|
268 MNssPlayEventHandler::TNssPlayResult res; |
|
269 |
|
270 if ( aResult == KErrNone ) |
|
271 { |
|
272 iPlayEventHandler->HandlePlayComplete( MNssPlayEventHandler::EVasErrorNone ); |
|
273 } |
|
274 else{ |
|
275 switch( aResult ) |
|
276 { |
|
277 case KErrNoMemory: |
|
278 res = MNssPlayEventHandler::EVasPlayNoMemory; |
|
279 break; |
|
280 |
|
281 case KErrAccessDenied: |
|
282 res = MNssPlayEventHandler::EVasPlayAccessDeny; |
|
283 break; |
|
284 |
|
285 default: |
|
286 res = MNssPlayEventHandler::EVasPlayFailed; |
|
287 break; |
|
288 } |
|
289 iPlayEventHandler->HandlePlayComplete( res ); |
|
290 } |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CNssSpeechItem::MapcCustomCommandEvent |
|
295 // TTS may call this method if we had used custom interfaces, |
|
296 // But we don't use custom interfaces. |
|
297 // ----------------------------------------------------------------------------- |
|
298 // |
|
299 void CNssSpeechItem::MapcCustomCommandEvent( TInt /*aEvent*/, TInt /*aError*/ ) |
|
300 { |
|
301 // We don't expect to arrive here |
|
302 } |
|
303 |
|
304 // ----------------------------------------------------------------------------- |
|
305 // CNssSpeechItem::MapcInitComplete |
|
306 // TTS calls this method to announce that it has initialized playing. |
|
307 // ----------------------------------------------------------------------------- |
|
308 // |
|
309 void CNssSpeechItem::MapcInitComplete( TInt aError, const TTimeIntervalMicroSeconds& aDuration ) |
|
310 { |
|
311 if ( aError != KErrNone ) |
|
312 { |
|
313 CleanPlayback(); |
|
314 MakePlayCallback( aError ); |
|
315 } |
|
316 else |
|
317 { |
|
318 if ((iState == TNssSpeechItemConstant::EPlayStart) || |
|
319 (iState == TNssSpeechItemConstant::EPlayMemoryStart) |
|
320 ) |
|
321 { |
|
322 iPlayDuration = I64LOW( aDuration.Int64() ); |
|
323 iPlayEventHandler->HandlePlayStarted(iPlayDuration); |
|
324 } |
|
325 else |
|
326 { |
|
327 NotifyHandlerForUnexpectedEvent(); |
|
328 } |
|
329 } |
|
330 } |
|
331 |
|
332 // ----------------------------------------------------------------------------- |
|
333 // CNssSpeechItem::MapcPlayComplete |
|
334 // TTS calls this method to announce that playing has finished. |
|
335 // ----------------------------------------------------------------------------- |
|
336 // |
|
337 void CNssSpeechItem::MapcPlayComplete( TInt aError ) |
|
338 { |
|
339 CleanPlayback(); |
|
340 MakePlayCallback( aError ); |
|
341 } |
|
342 |
|
343 // ----------------------------------------------------------------------------- |
|
344 // CNssSpeechItem::RecordL |
|
345 // Method to do record operation |
|
346 // ----------------------------------------------------------------------------- |
|
347 // |
|
348 MNssSpeechItem::TNssSpeechItemResult |
|
349 CNssSpeechItem::RecordL( MNssTrainVoiceEventHandler* aTrainVoiceEventHandler ) |
|
350 { |
|
351 RUBY_DEBUG1( "CNssSpeechItem::RecordL tagid [%d]", iTagId ); |
|
352 |
|
353 // Verify for valid state |
|
354 if (iState == TNssSpeechItemConstant::EIdle) |
|
355 { |
|
356 RUBY_DEBUG0( "CNssSpeechItem::RecordL - wrong state" ); |
|
357 |
|
358 return MNssSpeechItem::EVasUnexpectedRequest; |
|
359 } |
|
360 |
|
361 // Verify for valid event handler |
|
362 if (aTrainVoiceEventHandler) |
|
363 { |
|
364 iTrainVoiceEventHandler = aTrainVoiceEventHandler; |
|
365 } |
|
366 else |
|
367 { |
|
368 return MNssSpeechItem::EVasInvalidParameter; |
|
369 } |
|
370 |
|
371 return MNssSpeechItem::EVasErrorNone; |
|
372 } |
|
373 |
|
374 // ----------------------------------------------------------------------------- |
|
375 // CNssSpeechItem::TrainVoiceL |
|
376 // Method to do train operation |
|
377 // For retraining, the previous utterance data need to be preserved for the |
|
378 // delete operation later. |
|
379 // ----------------------------------------------------------------------------- |
|
380 // |
|
381 MNssSpeechItem::TNssSpeechItemResult |
|
382 CNssSpeechItem::TrainVoiceL(MNssTrainVoiceEventHandler* /*aTrainVoiceEventHandler*/) |
|
383 { |
|
384 // This is SI, don't even try to train by voice. |
|
385 return MNssSpeechItem::EVasUnexpectedRequest; |
|
386 } |
|
387 |
|
388 // ----------------------------------------------------------------------------- |
|
389 // CNssSpeechItem::CancelL |
|
390 // Method to do cancel operation by calling the SpeechRecognitionUtility Cancel |
|
391 // method, and cleanup the SRS from the current transaction. |
|
392 // ----------------------------------------------------------------------------- |
|
393 // |
|
394 MNssSpeechItem::TNssSpeechItemResult CNssSpeechItem::CancelL() |
|
395 { |
|
396 RUBY_DEBUG1( "CNssSpeechItem::CancelL tagid [%d]", iTagId ); |
|
397 |
|
398 //Verify a transaction is in progress |
|
399 if (iState == TNssSpeechItemConstant::EIdle) |
|
400 { |
|
401 return MNssSpeechItem::EVasUnexpectedRequest; |
|
402 } |
|
403 |
|
404 // Do the Clean up |
|
405 CleanUp(); |
|
406 |
|
407 return MNssSpeechItem::EVasErrorNone; |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CNssSpeechItem::TrainingCapabilities |
|
412 // Method to get the Training capabilities |
|
413 // ----------------------------------------------------------------------------- |
|
414 // |
|
415 CArrayFixFlat<TNssVasCoreConstant::TNssTrainingCapability>* |
|
416 CNssSpeechItem::TrainingCapabilities() |
|
417 { |
|
418 return NULL; |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CNssSpeechItem::RuleID |
|
423 // Method to get the rule ID |
|
424 // ----------------------------------------------------------------------------- |
|
425 // |
|
426 TUint32 CNssSpeechItem::RuleID() |
|
427 { |
|
428 return iRuleID; |
|
429 } |
|
430 |
|
431 // ----------------------------------------------------------------------------- |
|
432 // CNssSpeechItem::SetRuleID |
|
433 // Method to set the rule ID |
|
434 // ----------------------------------------------------------------------------- |
|
435 // |
|
436 void CNssSpeechItem::SetRuleID(TUint32 aRuleID) |
|
437 { |
|
438 iRuleID = aRuleID; |
|
439 } |
|
440 |
|
441 // ----------------------------------------------------------------------------- |
|
442 // CNssSpeechItem::TrainedType |
|
443 // Method to get the Trained Type |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 TNssVasCoreConstant::TNssTrainedType CNssSpeechItem::TrainedType() |
|
447 { |
|
448 return iTrainedType; |
|
449 } |
|
450 |
|
451 // ----------------------------------------------------------------------------- |
|
452 // CNssSpeechItem::SetTrainedType |
|
453 // Method to set the Trained Type |
|
454 // ----------------------------------------------------------------------------- |
|
455 // |
|
456 void CNssSpeechItem::SetTrainedType( TNssVasCoreConstant::TNssTrainedType aTrainType ) |
|
457 { |
|
458 iTrainedType = aTrainType; |
|
459 } |
|
460 |
|
461 // ----------------------------------------------------------------------------- |
|
462 // CNssSpeechItem::Text |
|
463 // Method to get the Text |
|
464 // ----------------------------------------------------------------------------- |
|
465 // |
|
466 TDesC& CNssSpeechItem::Text() |
|
467 { |
|
468 if ( iTrimmedText ) |
|
469 { |
|
470 return *iTrimmedText; |
|
471 } |
|
472 |
|
473 if ( iText ) |
|
474 { |
|
475 return *iText; |
|
476 } |
|
477 else |
|
478 { |
|
479 return (TDesC&)KNullDesC; |
|
480 } |
|
481 } |
|
482 |
|
483 // ----------------------------------------------------------------------------- |
|
484 // CNssSpeechItem::RawText |
|
485 // Method to get the raw text |
|
486 // ----------------------------------------------------------------------------- |
|
487 // |
|
488 TDesC& CNssSpeechItem::RawText() |
|
489 { |
|
490 if ( !iText ) |
|
491 { |
|
492 return (TDesC&)KNullDesC; |
|
493 } |
|
494 |
|
495 return *iText; |
|
496 } |
|
497 |
|
498 // ----------------------------------------------------------------------------- |
|
499 // CNssSpeechItem::PartialTextL |
|
500 // Returns the part of the text which is indentified with the given ID |
|
501 // ----------------------------------------------------------------------------- |
|
502 // |
|
503 HBufC* CNssSpeechItem::PartialTextL( const TDesC& aIdentifier ) |
|
504 { |
|
505 if ( !iText ) |
|
506 { |
|
507 User::Leave( KErrNotFound ); |
|
508 } |
|
509 |
|
510 // Copy text for manipulation |
|
511 HBufC* partialText = HBufC::NewL( iText->Length() ); |
|
512 CleanupStack::PushL( partialText ); |
|
513 *partialText = *iText; |
|
514 TPtr partialTextPtr = partialText->Des(); |
|
515 |
|
516 // Find all separator characters from text |
|
517 TInt markerIndex = partialTextPtr.Find( KNameSeparator ); |
|
518 TBool found( EFalse ); |
|
519 |
|
520 while ( markerIndex != KErrNotFound ) |
|
521 { |
|
522 // Separator marker should never be the last character of string |
|
523 __ASSERT_ALWAYS( markerIndex <= partialTextPtr.Length(), User::Leave( KErrCorrupt ) ); |
|
524 |
|
525 TBool removeThisPart( ETrue ); |
|
526 |
|
527 if ( partialTextPtr.Mid( markerIndex + 1, 1 ) == aIdentifier ) |
|
528 { |
|
529 found = ETrue; |
|
530 removeThisPart = EFalse; |
|
531 } |
|
532 |
|
533 if ( markerIndex == 0 ) |
|
534 { |
|
535 // Remove separator marker & the next char (which is the identifier) |
|
536 partialTextPtr.Delete( markerIndex, KTrainingIndexSize ); |
|
537 } |
|
538 else |
|
539 { |
|
540 // Replace separator marker & the next char |
|
541 partialTextPtr.Replace( markerIndex, KTrainingIndexSize, KEmptySpace ); |
|
542 } |
|
543 |
|
544 if ( removeThisPart ) |
|
545 { |
|
546 // Find next separator |
|
547 TInt tempIndex = partialTextPtr.Find( KNameSeparator ); |
|
548 if ( tempIndex != KErrNotFound ) |
|
549 { |
|
550 partialTextPtr.Delete( markerIndex, tempIndex - markerIndex ); |
|
551 } |
|
552 else |
|
553 { |
|
554 partialTextPtr.Delete( markerIndex, partialTextPtr.Length() ); |
|
555 } |
|
556 } |
|
557 |
|
558 // Find the next marker |
|
559 markerIndex = partialTextPtr.Find( KNameSeparator ); |
|
560 } |
|
561 |
|
562 if ( found ) |
|
563 { |
|
564 CleanupStack::Pop( partialText ); |
|
565 } |
|
566 else |
|
567 { |
|
568 CleanupStack::PopAndDestroy( partialText ); |
|
569 User::Leave( KErrNotFound ); |
|
570 } |
|
571 |
|
572 // Ownership transferred to client |
|
573 return partialText; |
|
574 } |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // CNssSpeechItem::SetTextL |
|
578 // Method to set the Text |
|
579 // ----------------------------------------------------------------------------- |
|
580 // |
|
581 void CNssSpeechItem::SetTextL( const TDesC& aText ) |
|
582 { |
|
583 if ( iText ) |
|
584 { |
|
585 delete iText; |
|
586 iText = NULL; |
|
587 } |
|
588 iText = aText.Left( KNssVasDbTagName ).AllocL(); |
|
589 |
|
590 if ( iTrimmedText ) |
|
591 { |
|
592 delete iTrimmedText; |
|
593 iTrimmedText = NULL; |
|
594 } |
|
595 iTrimmedText = iText->AllocL(); |
|
596 |
|
597 // Remove escape characters |
|
598 for ( TInt iCounter = 0; iCounter < iTrimmedText->Length(); iCounter ++ ) |
|
599 { |
|
600 if ( (*iTrimmedText)[iCounter] == KNameSeparator()[0] ) |
|
601 { |
|
602 TPtr ptr( iTrimmedText->Des() ); |
|
603 if ( iCounter == iTrimmedText->Length() - 1 ) |
|
604 { |
|
605 // Special handling for last char |
|
606 ptr.Delete( iCounter, 1 ); |
|
607 } |
|
608 else |
|
609 { |
|
610 ptr.Replace( iCounter, KTrainingIndexSize, KEmptySpace ); |
|
611 } |
|
612 } |
|
613 |
|
614 } |
|
615 TPtr ptr( iTrimmedText->Des() ); |
|
616 ptr.Trim(); |
|
617 } |
|
618 |
|
619 // ----------------------------------------------------------------------------- |
|
620 // CNssSpeechItem::IsPlayingSupported |
|
621 // Method to query playing support |
|
622 // ----------------------------------------------------------------------------- |
|
623 // |
|
624 TBool CNssSpeechItem::IsPlayingSupported() |
|
625 { |
|
626 if ( Text().Length() == 0 ) |
|
627 { |
|
628 return EFalse; |
|
629 } |
|
630 |
|
631 return( ETrue ); |
|
632 } |
|
633 |
|
634 // ----------------------------------------------------------------------------- |
|
635 // CNssSpeechItem::TrainTextL |
|
636 // Method to train a speech model from text |
|
637 // ----------------------------------------------------------------------------- |
|
638 // |
|
639 CNssSpeechItem::TNssSpeechItemResult CNssSpeechItem::TrainTextL( |
|
640 MNssTrainTextEventHandler *aEventHandler, |
|
641 CNssTrainingParameters *aTrainingParams ) |
|
642 { |
|
643 |
|
644 if ( /*aEventHandler == 0 ||*/ Text().Length() == 0 ) |
|
645 { |
|
646 return CNssSpeechItem::EVasInvalidParameter; |
|
647 } |
|
648 |
|
649 RUBY_DEBUG1( "CNssSpeechItem::TrainTextL tagig [%d]", iTagId ); |
|
650 |
|
651 // Verify for the valid state |
|
652 if (iState != TNssSpeechItemConstant::EIdle && |
|
653 iState != TNssSpeechItemConstant::ETrainComplete ) |
|
654 { |
|
655 RUBY_DEBUG0( "CNssSpeechItem::TrainTextL - wrong state" ); |
|
656 |
|
657 return MNssSpeechItem::EVasUnexpectedRequest; |
|
658 } |
|
659 |
|
660 // Verify for the valid event handler |
|
661 if ( !aEventHandler ) |
|
662 { |
|
663 return MNssSpeechItem::EVasInvalidParameter; |
|
664 } |
|
665 |
|
666 |
|
667 iState = TNssSpeechItemConstant::ETrainStart; |
|
668 |
|
669 // To diffrentiate from voice trained tags |
|
670 iTrainedType = TNssVasCoreConstant::EVasTrainText; |
|
671 |
|
672 // Training assigns rule ID from KInvalidRuleID to some correct value. |
|
673 if ( iRuleID == KInvalidRuleID ) |
|
674 { |
|
675 return( iTrainer.TrainTextDelayed( aEventHandler, aTrainingParams, *this, iContext )); |
|
676 } |
|
677 else |
|
678 { |
|
679 return( iTrainer.RetrainTextDelayed( aEventHandler, aTrainingParams, *this, iContext )); |
|
680 } |
|
681 |
|
682 // Use delayed training to train the new phrase. |
|
683 //return EVasErrorNone; |
|
684 } |
|
685 |
|
686 // ----------------------------------------------------------------------------- |
|
687 // CNssSpeechItem::NSSBeginSaveToSrsL |
|
688 // Method to begin the transaction for saving the utterance data to SRS |
|
689 // ----------------------------------------------------------------------------- |
|
690 // |
|
691 MNssCoreSrsDBEventHandler::TNssSrsDBResult |
|
692 CNssSpeechItem::NSSBeginSaveToSrs( MNssSaveTagClient* aSaveTagClient, CNssTag* aTag ) |
|
693 { |
|
694 RUBY_DEBUG1( "CNssSpeechItem::BeginSaveToSrsL tagid: [%d]", aTag->TagId() ); |
|
695 |
|
696 // The state should be in the Training Complete |
|
697 if (iState != TNssSpeechItemConstant::ETrainComplete) |
|
698 { |
|
699 RUBY_DEBUG0( "CNssSpeechItem::BeginSaveToSrsL - wrong state" ); |
|
700 |
|
701 return MNssCoreSrsDBEventHandler::EVasUnexpectedRequest; |
|
702 } |
|
703 |
|
704 TInt ret = iTrainer.SaveTagDelayed( aSaveTagClient, *aTag ); |
|
705 |
|
706 if ( ret != KErrNone ) |
|
707 { |
|
708 return MNssCoreSrsDBEventHandler::EVasUnexpectedRequest; |
|
709 } |
|
710 |
|
711 return MNssCoreSrsDBEventHandler::EVasSuccess; |
|
712 } |
|
713 |
|
714 // ----------------------------------------------------------------------------- |
|
715 // CNssSpeechItem::NSSBeginDeleteFromSrsL |
|
716 // Method to begin the transaction for saving the utterance data to SRS |
|
717 // ----------------------------------------------------------------------------- |
|
718 // |
|
719 MNssCoreSrsDBEventHandler::TNssSrsDBResult |
|
720 CNssSpeechItem::NSSBeginDeleteFromSrs( MNssDeleteTagClient* aDeleteTagClient, CNssTag* aTag ) |
|
721 { |
|
722 RUBY_DEBUG1( "CNssSpeechItem::BeginDeleteFromSrsL tagid: [%d]", aTag->TagId() ); |
|
723 |
|
724 // The state should be in the Training Complete |
|
725 if (iState != TNssSpeechItemConstant::ETrainComplete && |
|
726 iState != TNssSpeechItemConstant::EIdle ) |
|
727 { |
|
728 RUBY_DEBUG0( "CNssSpeechItem::BeginSaveToSrsL - wrong state" ); |
|
729 |
|
730 return MNssCoreSrsDBEventHandler::EVasUnexpectedRequest; |
|
731 } |
|
732 |
|
733 TInt ret = iTrainer.DeleteTagDelayed( aDeleteTagClient, *aTag ); |
|
734 |
|
735 if ( ret != KErrNone ) |
|
736 { |
|
737 return MNssCoreSrsDBEventHandler::EVasUnexpectedRequest; |
|
738 } |
|
739 |
|
740 return MNssCoreSrsDBEventHandler::EVasSuccess; |
|
741 } |
|
742 |
|
743 // ----------------------------------------------------------------------------- |
|
744 // CNssSpeechItem::CommitSrsChanges |
|
745 // Method to to commit the transaction to the SRS. |
|
746 // This is a SYNCHRONOUS method |
|
747 // ----------------------------------------------------------------------------- |
|
748 // |
|
749 MNssCoreSrsDBEventHandler::TNssSrsDBResult CNssSpeechItem::CommitSrsChanges() |
|
750 { |
|
751 // Not used |
|
752 User::Panic( KSpeechItemPanic, __LINE__ ); |
|
753 return MNssCoreSrsDBEventHandler::EVasSuccess; |
|
754 } |
|
755 |
|
756 // ----------------------------------------------------------------------------- |
|
757 // CNssSpeechItem::CommitSrsChanges |
|
758 // Method to to roll back the transaction to the SRS. |
|
759 // This is a SYNCHRONOUS method |
|
760 // ----------------------------------------------------------------------------- |
|
761 // |
|
762 MNssCoreSrsDBEventHandler::TNssSrsDBResult CNssSpeechItem::RollbackSrsChanges() |
|
763 { |
|
764 // Not used |
|
765 User::Panic( KSpeechItemPanic, __LINE__ ); |
|
766 return MNssCoreSrsDBEventHandler::EVasSuccess; |
|
767 } |
|
768 |
|
769 |
|
770 // ----------------------------------------------------------------------------- |
|
771 // CNssSpeechItem::CopyUtteranceData |
|
772 // Method to copy utterance data from current data to transient data |
|
773 // ----------------------------------------------------------------------------- |
|
774 // |
|
775 void CNssSpeechItem::CopyUtteranceData() |
|
776 { |
|
777 iTransientRuleID = iRuleID; |
|
778 } |
|
779 |
|
780 // ----------------------------------------------------------------------------- |
|
781 // CNssSpeechItem::MsruoEvent |
|
782 // Method to process the events from SRS utility object |
|
783 // ----------------------------------------------------------------------------- |
|
784 // |
|
785 void CNssSpeechItem::MsruoEvent( TUid aEvent, TInt aResult ) |
|
786 { |
|
787 RUBY_DEBUG2( "CNssSpeechItem::MsruoEvent, Event=0x%x, Result=%d", aEvent.iUid, aResult ); |
|
788 |
|
789 switch (aEvent.iUid) |
|
790 { |
|
791 |
|
792 |
|
793 //---------------------------------------------------------------------- |
|
794 // Pre-Train Events |
|
795 //---------------------------------------------------------------------- |
|
796 |
|
797 |
|
798 case KUidAsrEventGetModelCountVal: |
|
799 RUBY_ERROR0( "CNssSpeechItem::MsruoEvent KUidAsrEventAddRuleVal not expected" ); |
|
800 break; |
|
801 |
|
802 case KUidAsrEventGetAvailableStorageVal: |
|
803 if (aResult == KErrNone) |
|
804 { |
|
805 DoGetAvailableStorageCompleteEvent(); |
|
806 } |
|
807 else |
|
808 { |
|
809 DoTrainFailEvent(aResult); |
|
810 } |
|
811 break; |
|
812 |
|
813 |
|
814 //---------------------------------------------------------------------- |
|
815 // Train Events |
|
816 //---------------------------------------------------------------------- |
|
817 |
|
818 case KUidAsrEventTrainReadyVal: |
|
819 RUBY_DEBUG0( "CNssSpeechItem::MsruoEvent - TrainReadyEvent" ); |
|
820 |
|
821 // Always success, no need to verify aResult |
|
822 if (iState == TNssSpeechItemConstant::ETrainStart) |
|
823 { |
|
824 iTrainVoiceEventHandler->HandleReadyToRecord(); |
|
825 } |
|
826 else |
|
827 { |
|
828 NotifyHandlerForUnexpectedEvent(); |
|
829 } |
|
830 break; |
|
831 |
|
832 case KUidAsrEventRecordStartedVal: |
|
833 RUBY_DEBUG0( "CNssSpeechItem::MsruoEvent - RecordStartedEvent" ); |
|
834 |
|
835 // Always success, no need to verify aResult |
|
836 if (iState == TNssSpeechItemConstant::ETrainStart) |
|
837 { |
|
838 iTrainVoiceEventHandler->HandleRecordStarted(); |
|
839 } |
|
840 else |
|
841 { |
|
842 NotifyHandlerForUnexpectedEvent(); |
|
843 } |
|
844 break; |
|
845 case KUidAsrEventEouDetectedVal: |
|
846 RUBY_DEBUG0( "CNssSpeechItem::MsruoEvent - EouDetectedEvent" ); |
|
847 |
|
848 // Always success, no need to verify aResult |
|
849 if (iState == TNssSpeechItemConstant::ETrainStart) |
|
850 { |
|
851 iTrainVoiceEventHandler->HandleEouDetected(); |
|
852 } |
|
853 else |
|
854 { |
|
855 NotifyHandlerForUnexpectedEvent(); |
|
856 } |
|
857 break; |
|
858 |
|
859 case KUidAsrEventTrainVal: |
|
860 if (aResult == KErrNone) |
|
861 { |
|
862 DoTrainCompleteEvent(); |
|
863 } |
|
864 else |
|
865 { |
|
866 DoTrainFailEvent(aResult); |
|
867 } |
|
868 break; |
|
869 |
|
870 // currently this is only for fail cases |
|
871 case KUidAsrEventRecordVal: |
|
872 RUBY_DEBUG0( "CNssSpeechItem::MsruoEvent - ERecordFailed" ); |
|
873 |
|
874 // If the result is success, do nothing |
|
875 if (aResult != KErrNone) |
|
876 { |
|
877 DoTrainFailEvent(aResult); |
|
878 } |
|
879 break; |
|
880 |
|
881 |
|
882 // End of Train Events |
|
883 |
|
884 |
|
885 //---------------------------------------------------------------------- |
|
886 // Save Events |
|
887 //---------------------------------------------------------------------- |
|
888 |
|
889 case KUidAsrEventAddRuleVal: |
|
890 RUBY_ERROR0( "CNssSpeechItem::MsruoEvent KUidAsrEventAddRuleVal not expected" ); |
|
891 break; |
|
892 |
|
893 // End of Save to Srs Events |
|
894 |
|
895 |
|
896 //---------------------------------------------------------------------- |
|
897 // Delete Events |
|
898 //---------------------------------------------------------------------- |
|
899 |
|
900 |
|
901 case KUidAsrEventRemoveRuleVal: |
|
902 RUBY_ERROR0( "CNssSpeechItem::MsruoEvent KUidAsrEventRemoveRuleVal not expected" ); |
|
903 break; |
|
904 |
|
905 // End of Deleting from Srs Events |
|
906 |
|
907 |
|
908 default: |
|
909 RUBY_DEBUG0( "CNssSpeechItem::MsruoEvent ERROR:default in switch" ); |
|
910 |
|
911 NotifyHandlerForUnexpectedEvent(); |
|
912 break; |
|
913 } |
|
914 } |
|
915 |
|
916 |
|
917 |
|
918 // ------------------------- Play ----------------------------- // |
|
919 |
|
920 // ------------------------- Train ---------------------------- // |
|
921 |
|
922 |
|
923 // ----------------------------------------------------------------------------- |
|
924 // CNssSpeechItem::DoGetAvailableStorageCompleteEvent |
|
925 // Method to handle the "GetAvailableStorage" Event. |
|
926 // Verify the size of available storage, if it is not zero, continue with |
|
927 // the next operation to train. |
|
928 // If the size is zero, send the error message. |
|
929 // ----------------------------------------------------------------------------- |
|
930 // |
|
931 void CNssSpeechItem::DoGetAvailableStorageCompleteEvent() |
|
932 { |
|
933 // Obsolete |
|
934 User::Panic( KSpeechItemPanic, __LINE__ ); |
|
935 } |
|
936 |
|
937 |
|
938 // ----------------------------------------------------------------------------- |
|
939 // CNssSpeechItem::DoTrainCompleteEvent |
|
940 // Method to process the Train event. |
|
941 // ----------------------------------------------------------------------------- |
|
942 // |
|
943 void CNssSpeechItem::DoTrainCompleteEvent() |
|
944 { |
|
945 RUBY_DEBUG0( "CNssSpeechItem::DoTrainCompleteEvent" ); |
|
946 |
|
947 if (iState == TNssSpeechItemConstant::ETrainStart) |
|
948 { |
|
949 iState = TNssSpeechItemConstant::ETrainComplete; |
|
950 //iTrainVoiceEventHandler->HandleTrainComplete(); |
|
951 iTrainVoiceEventHandler->HandleTrainComplete( KErrNone ); |
|
952 } |
|
953 else |
|
954 { |
|
955 NotifyHandlerForUnexpectedEvent(); |
|
956 } |
|
957 } |
|
958 |
|
959 |
|
960 |
|
961 // ----------------------------------------------------------------------------- |
|
962 // CNssSpeechItem::DoTrainFailEvent |
|
963 // Method to process the train failed events |
|
964 // ----------------------------------------------------------------------------- |
|
965 // |
|
966 void CNssSpeechItem::DoTrainFailEvent( TInt aResult ) |
|
967 { |
|
968 RUBY_DEBUG1( "CNssSpeechItem::DoTrainFailEvent [%d]", aResult ); |
|
969 |
|
970 if (iState != TNssSpeechItemConstant::ETrainStart) |
|
971 { |
|
972 NotifyHandlerForUnexpectedEvent(); |
|
973 return; |
|
974 } |
|
975 |
|
976 CleanUp(); |
|
977 MNssTrainVoiceEventHandler::TNssTrainResult errorCode = DoTrainResult( aResult ); |
|
978 |
|
979 iTrainVoiceEventHandler->HandleTrainComplete( errorCode ); |
|
980 } |
|
981 |
|
982 |
|
983 |
|
984 // ----------------------------------------------------------------------------- |
|
985 // CNssSpeechItem::DoTrainResult |
|
986 // Method to process the Train result. |
|
987 // ----------------------------------------------------------------------------- |
|
988 // |
|
989 MNssTrainVoiceEventHandler::TNssTrainResult |
|
990 CNssSpeechItem::DoTrainResult( TInt aResult ) |
|
991 { |
|
992 |
|
993 MNssTrainVoiceEventHandler::TNssTrainResult errorCode; |
|
994 |
|
995 switch (aResult) |
|
996 { |
|
997 case KErrAsrNoSpeech: |
|
998 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - EVasTrainFailedNoSpeech" ); |
|
999 |
|
1000 errorCode = MNssTrainVoiceEventHandler::EVasTrainFailedNoSpeech; |
|
1001 break; |
|
1002 case KErrAsrSpeechTooEarly: |
|
1003 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - EVasTrainFailedTooEarly" ); |
|
1004 |
|
1005 errorCode = MNssTrainVoiceEventHandler::EVasTrainFailedTooEarly; |
|
1006 break; |
|
1007 case KErrAsrSpeechTooLong: |
|
1008 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - EVasTrainFailedTooLong" ); |
|
1009 |
|
1010 errorCode = MNssTrainVoiceEventHandler::EVasTrainFailedTooLong; |
|
1011 break; |
|
1012 case KErrAsrSpeechTooShort: |
|
1013 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - KErrAsrSpeechTooShort" ); |
|
1014 |
|
1015 errorCode = MNssTrainVoiceEventHandler::EVasTrainFailedTooShort; |
|
1016 break; |
|
1017 case KErrAccessDenied: // this is temporary ..... |
|
1018 case KErrDied: |
|
1019 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - EVasTrainAccessDeny" ); |
|
1020 |
|
1021 errorCode = MNssTrainVoiceEventHandler::EVasTrainAccessDeny; |
|
1022 break; |
|
1023 case KErrNoMemory: |
|
1024 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - EVasTrainNoMemory" ); |
|
1025 |
|
1026 errorCode = MNssTrainVoiceEventHandler::EVasTrainNoMemory; |
|
1027 break; |
|
1028 default: |
|
1029 RUBY_DEBUG0( "CNssSpeechItem::DoTrainResult - default" ); |
|
1030 |
|
1031 errorCode = MNssTrainVoiceEventHandler::EVasTrainFailed; |
|
1032 break; |
|
1033 } |
|
1034 |
|
1035 return errorCode; |
|
1036 } |
|
1037 |
|
1038 // ----------------------------------------------------------------------------- |
|
1039 // CNssSpeechItem::DoSrsDBResult |
|
1040 // Method to process the SRS DB result. |
|
1041 // ----------------------------------------------------------------------------- |
|
1042 // |
|
1043 MNssCoreSrsDBEventHandler::TNssSrsDBResult |
|
1044 CNssSpeechItem::DoSrsDBResult( TInt aResult ) |
|
1045 { |
|
1046 |
|
1047 MNssCoreSrsDBEventHandler::TNssSrsDBResult errorCode; |
|
1048 |
|
1049 switch (aResult) |
|
1050 { |
|
1051 case KErrDiskFull: |
|
1052 RUBY_DEBUG0( "CNssSpeechItem::DoSrsDBResult - KErrDiskFull" ); |
|
1053 |
|
1054 errorCode = MNssCoreSrsDBEventHandler::EVasDiskFull; |
|
1055 break; |
|
1056 case KErrNoMemory: |
|
1057 RUBY_DEBUG0( "CNssSpeechItem::DoSrsDBResult - EVasNoMemory" ); |
|
1058 |
|
1059 errorCode = MNssCoreSrsDBEventHandler::EVasNoMemory; |
|
1060 break; |
|
1061 default: |
|
1062 { |
|
1063 RUBY_DEBUG0( "CNssSpeechItem::DoSrsDBResult - default" ); |
|
1064 |
|
1065 switch ( iState ) |
|
1066 { |
|
1067 case TNssSpeechItemConstant::ESaveToSrsStart: |
|
1068 errorCode = MNssCoreSrsDBEventHandler::EVasAddPronunciationFailed; |
|
1069 break; |
|
1070 case TNssSpeechItemConstant::EAddPronounciationComplete: |
|
1071 errorCode = MNssCoreSrsDBEventHandler::EVasAddRuleFailed; |
|
1072 break; |
|
1073 case TNssSpeechItemConstant::EDeleteToSrsStart: |
|
1074 errorCode = MNssCoreSrsDBEventHandler::EVasRemoveRuleFailed; |
|
1075 break; |
|
1076 case TNssSpeechItemConstant::ERemoveRuleComplete: |
|
1077 errorCode = MNssCoreSrsDBEventHandler::EVasRemovePronunciationFailed; |
|
1078 break; |
|
1079 case TNssSpeechItemConstant::ERemovePronounciationComplete: |
|
1080 errorCode = MNssCoreSrsDBEventHandler::EVasRemoveModelFailed; |
|
1081 break; |
|
1082 default: |
|
1083 errorCode = MNssCoreSrsDBEventHandler::EVasDBOperationError; |
|
1084 break; |
|
1085 } |
|
1086 } |
|
1087 } |
|
1088 |
|
1089 return errorCode; |
|
1090 } |
|
1091 |
|
1092 // ----------------------------------------------------------------------------- |
|
1093 // CNssSpeechItem::NotifyHandlerForUnexpectedEvent |
|
1094 // Method to notify the event handler for receiving the Unexpected Event |
|
1095 // ----------------------------------------------------------------------------- |
|
1096 // |
|
1097 void CNssSpeechItem::NotifyHandlerForUnexpectedEvent() |
|
1098 { |
|
1099 RUBY_DEBUG1( "CNssSpeechItem::NotifyHandlerForUnexpectedEvent tagid: %d", iTagId ); |
|
1100 |
|
1101 switch( iState ) |
|
1102 { |
|
1103 case TNssSpeechItemConstant::EAddPronounciationComplete: |
|
1104 case TNssSpeechItemConstant::EAddRuleComplete: |
|
1105 case TNssSpeechItemConstant::ERemoveRuleComplete: |
|
1106 case TNssSpeechItemConstant::ERemovePronounciationComplete: |
|
1107 case TNssSpeechItemConstant::ERemoveModelCompelete: |
|
1108 case TNssSpeechItemConstant::EWaitForCommitChanges: |
|
1109 // Shouldn't happen, since all calls to SRS |
|
1110 // are done at CNssSpeechItemTrainer. |
|
1111 User::Panic( KSpeechItemPanic, __LINE__ ); |
|
1112 |
|
1113 break; |
|
1114 |
|
1115 case TNssSpeechItemConstant::EPlayMemoryStart: |
|
1116 case TNssSpeechItemConstant::EPlayStart: |
|
1117 if (iPlayEventHandler) |
|
1118 { |
|
1119 CleanUp(); |
|
1120 iPlayEventHandler->HandlePlayComplete( |
|
1121 MNssPlayEventHandler::EVasPlayFailed); |
|
1122 } |
|
1123 break; |
|
1124 |
|
1125 case TNssSpeechItemConstant::ETrainStart: |
|
1126 if (iTrainVoiceEventHandler) |
|
1127 { |
|
1128 CleanUp(); |
|
1129 iTrainVoiceEventHandler->HandleTrainComplete( |
|
1130 MNssTrainVoiceEventHandler::EVasTrainFailed); |
|
1131 } |
|
1132 break; |
|
1133 |
|
1134 default: |
|
1135 break; |
|
1136 } |
|
1137 } |
|
1138 |
|
1139 // ----------------------------------------------------------------------------- |
|
1140 // CNssSpeechItem::SetTagId |
|
1141 // Method to set the Tag ID |
|
1142 // ----------------------------------------------------------------------------- |
|
1143 // |
|
1144 void CNssSpeechItem::SetTagId( TInt aTagId ) |
|
1145 { |
|
1146 iTagId = aTagId; |
|
1147 } |
|
1148 |
|
1149 // ----------------------------------------------------------------------------- |
|
1150 // CNssSpeechItem::TagId |
|
1151 // Method to return the Tag ID |
|
1152 // ----------------------------------------------------------------------------- |
|
1153 // |
|
1154 TInt CNssSpeechItem::TagId() |
|
1155 { |
|
1156 return iTagId; |
|
1157 } |
|
1158 |
|
1159 // ----------------------------------------------------------------------------- |
|
1160 // CNssSpeechItem::GrammarId |
|
1161 // Method to return the Grammar ID |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // |
|
1164 TUint32 CNssSpeechItem::GrammarId() |
|
1165 { |
|
1166 return iContext.GrammarId(); |
|
1167 } |
|
1168 |
|
1169 // ----------------------------------------------------------------------------- |
|
1170 // CNssSpeechItem::SetTrained |
|
1171 // Method to set the Trained flag |
|
1172 // ----------------------------------------------------------------------------- |
|
1173 // |
|
1174 void CNssSpeechItem::SetTrained( TBool aTrained ) |
|
1175 { |
|
1176 iTrained = aTrained; |
|
1177 } |
|
1178 |
|
1179 // ----------------------------------------------------------------------------- |
|
1180 // CNssSpeechItem::Trained |
|
1181 // Method to return the Trained flag |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // |
|
1184 TBool CNssSpeechItem::Trained() |
|
1185 { |
|
1186 return iTrained; |
|
1187 } |
|
1188 |
|
1189 // --------------------------------------------------------- |
|
1190 // CNssSpeechItem::CopyL |
|
1191 // creates a copy of this SpeechItem |
|
1192 // --------------------------------------------------------- |
|
1193 // |
|
1194 CNssSpeechItem* CNssSpeechItem::CopyL( CNssContext* aContext ) |
|
1195 { |
|
1196 RUBY_DEBUG1( "CNssSpeechItem::CopyL tagid: %d", iTagId ); |
|
1197 |
|
1198 CNssSpeechItem* copy = new (ELeave) CNssSpeechItem(*aContext, iPortal, iTrainer); |
|
1199 |
|
1200 if ( iText ) |
|
1201 { |
|
1202 copy->iText = iText->Alloc(); |
|
1203 } |
|
1204 if ( iTrimmedText ) |
|
1205 { |
|
1206 copy->iTrimmedText = iTrimmedText->Alloc(); |
|
1207 } |
|
1208 copy->iRuleID = iRuleID; |
|
1209 copy->iTransientRuleID = iTransientRuleID; |
|
1210 |
|
1211 copy->iTrainedType = iTrainedType; |
|
1212 copy->iState = iState; |
|
1213 copy->iContext = iContext; |
|
1214 copy->iPortal = iPortal; |
|
1215 copy->iPlayEventHandler = iPlayEventHandler; |
|
1216 //copy->iSrsDBEventHandler = iSrsDBEventHandler; |
|
1217 copy->iTrainVoiceEventHandler = iTrainVoiceEventHandler; |
|
1218 |
|
1219 copy->iTagId = iTagId; |
|
1220 copy->iTrained = iTrained; |
|
1221 copy->iPlayDuration = iPlayDuration; |
|
1222 |
|
1223 |
|
1224 // set the iSrsApi to NULL |
|
1225 // set the iRetry to NULL |
|
1226 |
|
1227 // set the state to Idle |
|
1228 copy->iState = TNssSpeechItemConstant::EIdle; |
|
1229 // set iRecover to False |
|
1230 copy->iRecover = EFalse; |
|
1231 |
|
1232 return copy; |
|
1233 } |
|
1234 |
|
1235 // --------------------------------------------------------- |
|
1236 // CNssSpeechItem::CleanUp |
|
1237 // Method to do the clean up |
|
1238 // --------------------------------------------------------- |
|
1239 // |
|
1240 void CNssSpeechItem::CleanUp() |
|
1241 { |
|
1242 RUBY_DEBUG1( "CNssSpeechItem::CleanUp tagid: %d", iTagId ); |
|
1243 |
|
1244 if ( iTtsData ) |
|
1245 { |
|
1246 CleanPlayback(); |
|
1247 } |
|
1248 } |
|
1249 |
|
1250 // --------------------------------------------------------- |
|
1251 // CNssSpeechItem::DoRetry |
|
1252 // Method to verify whether retry is already max out, |
|
1253 // if not return ETrue, else return EFalse |
|
1254 // --------------------------------------------------------- |
|
1255 // |
|
1256 TBool CNssSpeechItem::DoRetry() |
|
1257 { |
|
1258 if ( iRetry < KVASSpeechItemMaxRetry ) |
|
1259 { |
|
1260 iRetry++; |
|
1261 return ETrue; |
|
1262 } |
|
1263 else |
|
1264 { |
|
1265 // Reset the retry count |
|
1266 iRetry = KVASSpeechItemResetRetry; |
|
1267 return EFalse; |
|
1268 } |
|
1269 } |
|
1270 |
|
1271 // ----------------------------------------------------------------------------- |
|
1272 // CNssSpeechItem::DelayedTrainingComplete |
|
1273 // Updates the speech item, after SI training has been carried out. |
|
1274 // ----------------------------------------------------------------------------- |
|
1275 // |
|
1276 void CNssSpeechItem::DelayedTrainingComplete( TUint32 aRuleID ) |
|
1277 { |
|
1278 SetRuleID( aRuleID ); |
|
1279 |
|
1280 if ( aRuleID != KInvalidRuleID ) |
|
1281 { |
|
1282 this->iTrainedType = TNssVasCoreConstant::EVasTrainText; |
|
1283 } |
|
1284 else |
|
1285 { |
|
1286 // Training failed; mark all invalid |
|
1287 SetRuleID( KInvalidRuleID ); |
|
1288 |
|
1289 this->iTrainedType = TNssVasCoreConstant::EVasNotTrained; |
|
1290 } |
|
1291 |
|
1292 this->iTrained = ETrue; |
|
1293 this->iState = TNssSpeechItemConstant::ETrainComplete; |
|
1294 } |
|
1295 |
|
1296 // ----------------------------------------------------------------------------- |
|
1297 // TTtsData::TTtsData |
|
1298 // Initializes everything to zero. |
|
1299 // ----------------------------------------------------------------------------- |
|
1300 // |
|
1301 CNssSpeechItem::TTtsData::TTtsData() : iStyle(), |
|
1302 iStyleID( 0 ), |
|
1303 iSegment( 0 ), |
|
1304 iTts( NULL ), |
|
1305 iParsedText( NULL ) |
|
1306 { |
|
1307 // Nothing |
|
1308 } |
|
1309 |
|
1310 // End of file |