mmdevicefw/speechrecogsupport/ASR/src/SpeechRecognitionDataDevASR.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // SpeechRecognitionDataClient.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32base.h>
       
    19 #include <mmf/common/mmfcontroller.h>
       
    20 #include <mmf/common/speechrecognitioncustomcommands.h>
       
    21 #include <mmf/common/speechrecognitiondatadevasr.h>
       
    22 #include <mmf/common/speechrecognitiondatatest.h>
       
    23 
       
    24 
       
    25 EXPORT_C CSDPronunciation::~CSDPronunciation()
       
    26 	{
       
    27 	}
       
    28 	
       
    29 CSDPronunciation::CSDPronunciation(TPronunciationID aPronunciationID, TModelBankID aModelBankID, TPhonemeID aPhonemeID)
       
    30 	: iPronunciationID(aPronunciationID),
       
    31 	  iModelBankID(aModelBankID),
       
    32 	  iPhonemeID(aPhonemeID)
       
    33 	{
       
    34 	
       
    35 	}
       
    36 	
       
    37 void CSDPronunciation::ConstructL()
       
    38 	{
       
    39 	
       
    40 	}
       
    41 
       
    42 	
       
    43 EXPORT_C CSDPronunciation* CSDPronunciation::NewL(TPronunciationID aPronunciationID, TModelBankID aModelBankID, TPhonemeID aPhonemeID)
       
    44 	{
       
    45 	CSDPronunciation* self = CSDPronunciation::NewLC(aPronunciationID, aModelBankID, aPhonemeID);
       
    46 	CleanupStack::Pop(self);
       
    47 	return self;
       
    48 	}	
       
    49 	
       
    50 EXPORT_C CSDPronunciation* CSDPronunciation::NewLC(TPronunciationID aPronunciationID, TModelBankID aModelBankID, TPhonemeID aPhonemeID)
       
    51 	{
       
    52 	CSDPronunciation* self = new (ELeave) CSDPronunciation(aPronunciationID, aModelBankID, aPhonemeID);
       
    53 	CleanupStack::PushL(self);
       
    54 	self->ConstructL();	
       
    55 	return self;
       
    56 	}	
       
    57 	
       
    58 	
       
    59 
       
    60 EXPORT_C TPronunciationID CSDPronunciation::PronunciationID() const
       
    61 	{
       
    62 	return iPronunciationID;
       
    63 	
       
    64 	}
       
    65 
       
    66 EXPORT_C TModelBankID CSDPronunciation::ModelBankID() const
       
    67 	{
       
    68 	return iModelBankID;
       
    69 	}
       
    70 
       
    71 EXPORT_C TPhonemeID CSDPronunciation::PhonemeID() const
       
    72 	{
       
    73 	return iPhonemeID;
       
    74 	
       
    75 	}
       
    76 
       
    77 	
       
    78 	
       
    79 CSDLexicon::CSDLexicon(TLexiconID aLexiconID)
       
    80 	{
       
    81 	iLexiconID = aLexiconID;
       
    82 	}
       
    83 
       
    84 
       
    85 EXPORT_C CSDLexicon::~CSDLexicon()
       
    86 	{
       
    87 	iPronunciationArray.ResetAndDestroy();
       
    88 	}
       
    89 
       
    90 EXPORT_C CSDLexicon* CSDLexicon::NewL(TLexiconID aLexiconID)
       
    91 	{
       
    92 	CSDLexicon* self = CSDLexicon::NewLC(aLexiconID);
       
    93 	CleanupStack::Pop(self);
       
    94 	return self;	
       
    95 	}
       
    96 	
       
    97 EXPORT_C CSDLexicon* CSDLexicon::NewLC(TLexiconID aLexiconID)
       
    98 	{
       
    99 	CSDLexicon* self = new (ELeave) CSDLexicon(aLexiconID);
       
   100 	CleanupStack::PushL(self);
       
   101 	self->ConstructL();
       
   102 	return self;	
       
   103 	}
       
   104 
       
   105 void CSDLexicon::ConstructL() 
       
   106 	{
       
   107 	}
       
   108 
       
   109 
       
   110 EXPORT_C TInt CSDLexicon::Add(CSDPronunciation& aPronunciation)
       
   111 	{
       
   112 	if (FindPronunciation(aPronunciation.PronunciationID())!=KErrNotFound)
       
   113 		return KErrAlreadyExists;
       
   114 	return iPronunciationArray.Append(&aPronunciation);
       
   115 	}
       
   116 
       
   117 
       
   118 EXPORT_C TInt CSDLexicon::FindPronunciation(TPronunciationID aPronunciationID) const
       
   119 	{
       
   120 	TBool found = EFalse;
       
   121 	TInt index = 0;
       
   122 	TInt count = iPronunciationArray.Count();
       
   123 	for (TInt i=0;i < count;i++) 
       
   124 		{
       
   125 		if (aPronunciationID == iPronunciationArray[i]->PronunciationID()) 
       
   126 			{
       
   127 			found = true;
       
   128 			index = i;
       
   129 			break;
       
   130 			}
       
   131 		}
       
   132 	if (found)
       
   133 		return index;
       
   134 	else
       
   135 		return KErrNotFound;
       
   136 	}
       
   137 
       
   138 
       
   139 EXPORT_C TInt CSDLexicon::Count() const
       
   140 	{
       
   141 	return iPronunciationArray.Count();
       
   142 	}
       
   143 
       
   144 
       
   145 EXPORT_C const CSDPronunciation& CSDLexicon::At(TInt aIndex) const
       
   146 	{
       
   147 	return *iPronunciationArray[aIndex];
       
   148 	}
       
   149 
       
   150 EXPORT_C TLexiconID CSDLexicon::LexiconID() const
       
   151 	{
       
   152 	return iLexiconID;
       
   153 	}
       
   154 
       
   155 
       
   156 	
       
   157 //------------------------------------------------------------------------------------------
       
   158 EXPORT_C CSDRule::~CSDRule()
       
   159 	{
       
   160 	}
       
   161 	
       
   162 CSDRule::CSDRule(TRuleID aRuleID, TLexiconID aLexiconID, TPronunciationID aPronunciationID)
       
   163 	: iRuleID(aRuleID),
       
   164 	  iLexiconID(aLexiconID),
       
   165 	  iPronunciationID(aPronunciationID)
       
   166 	{
       
   167 	
       
   168 	}
       
   169 	
       
   170 void CSDRule::ConstructL()
       
   171 	{
       
   172 	
       
   173 	}
       
   174 
       
   175 	
       
   176 EXPORT_C CSDRule* CSDRule::NewL(TRuleID aRuleID, TLexiconID aLexiconID, TPronunciationID aPronunciationID)
       
   177 	{
       
   178 	CSDRule* self = CSDRule::NewLC(aRuleID, aLexiconID, aPronunciationID);
       
   179 	CleanupStack::Pop(self);
       
   180 	return self;
       
   181 	}	
       
   182 	
       
   183 EXPORT_C CSDRule* CSDRule::NewLC(TRuleID aRuleID, TLexiconID aLexiconID, TPronunciationID aPronunciationID)
       
   184 	{
       
   185 	CSDRule* self = new (ELeave) CSDRule(aRuleID, aLexiconID, aPronunciationID);
       
   186 	CleanupStack::PushL(self);
       
   187 	self->ConstructL();	
       
   188 	return self;
       
   189 	}	
       
   190 	
       
   191 	
       
   192 
       
   193 EXPORT_C TRuleID CSDRule::RuleID() const
       
   194 	{
       
   195 	return iRuleID;
       
   196 	
       
   197 	}
       
   198 
       
   199 EXPORT_C TLexiconID CSDRule::LexiconID() const
       
   200 	{
       
   201 	return iLexiconID;
       
   202 	}
       
   203 
       
   204 EXPORT_C TPronunciationID CSDRule::PronunciationID() const
       
   205 	{
       
   206 	return iPronunciationID;
       
   207 	
       
   208 	}
       
   209 
       
   210 	
       
   211 	
       
   212 CSDGrammar::CSDGrammar(TGrammarID aGrammarID)
       
   213 	{
       
   214 	iGrammarID = aGrammarID;
       
   215 	}
       
   216 
       
   217 
       
   218 EXPORT_C CSDGrammar::~CSDGrammar()
       
   219 	{
       
   220 	iRuleArray.ResetAndDestroy();
       
   221 	}
       
   222 
       
   223 EXPORT_C CSDGrammar* CSDGrammar::NewL(TGrammarID aGrammarID)
       
   224 	{
       
   225 	CSDGrammar* self = CSDGrammar::NewLC(aGrammarID);
       
   226 	CleanupStack::Pop(self);
       
   227 	return self;	
       
   228 	}
       
   229 	
       
   230 EXPORT_C CSDGrammar* CSDGrammar::NewLC(TGrammarID aGrammarID)
       
   231 	{
       
   232 	CSDGrammar* self = new (ELeave) CSDGrammar(aGrammarID);
       
   233 	CleanupStack::PushL(self);
       
   234 	self->ConstructL();
       
   235 	return self;	
       
   236 	}
       
   237 
       
   238 void CSDGrammar::ConstructL() 
       
   239 	{
       
   240 	}
       
   241 
       
   242 EXPORT_C TGrammarID CSDGrammar::GrammarID() const
       
   243 	{
       
   244 	return iGrammarID;
       
   245 	}
       
   246 
       
   247 
       
   248 EXPORT_C TInt CSDGrammar::Add(CSDRule& aRule)
       
   249 	{
       
   250 	if (FindRule(aRule.RuleID())!=KErrNotFound)
       
   251 		return KErrAlreadyExists;
       
   252 
       
   253 	return iRuleArray.Append(&aRule);
       
   254 	}
       
   255 
       
   256 
       
   257 EXPORT_C TInt CSDGrammar::FindRule(TRuleID aRuleID) const
       
   258 	{
       
   259 	TBool found = EFalse;
       
   260 	TInt index = 0;
       
   261 	TInt count = iRuleArray.Count();
       
   262 	for (TInt i=0;i < count;i++) 
       
   263 		{
       
   264 		if (aRuleID == iRuleArray[i]->RuleID()) 
       
   265 			{
       
   266 			found = true;
       
   267 			index = i;
       
   268 			break;
       
   269 			}
       
   270 		}
       
   271 	if (found)
       
   272 		return index;
       
   273 	else
       
   274 		return KErrNotFound;
       
   275 	}
       
   276 
       
   277 EXPORT_C void CSDGrammar::Delete(TRuleID aRuleID)
       
   278 	{
       
   279 	TInt count = iRuleArray.Count();
       
   280 	for (TInt i=0;i < count;i++) 
       
   281 		{
       
   282 		if (aRuleID == iRuleArray[i]->RuleID()) 
       
   283 			{
       
   284 			iRuleArray.Remove(i);
       
   285 			break;
       
   286 			}
       
   287 		}
       
   288 	}
       
   289 
       
   290 
       
   291 EXPORT_C TInt CSDGrammar::Count() const
       
   292 	{
       
   293 	return iRuleArray.Count();
       
   294 	}
       
   295 
       
   296 
       
   297 
       
   298 
       
   299 EXPORT_C const CSDRule& CSDGrammar::At(TInt aIndex) const
       
   300 	{
       
   301 	return *iRuleArray[aIndex];
       
   302 	}
       
   303 
       
   304 //------------------------------------------------------------------------------------------
       
   305 EXPORT_C CSDModel::~CSDModel()
       
   306 	{
       
   307 	TUint8* data = const_cast<TUint8*>(iAcousticModelPtr.Ptr());
       
   308 	delete[] data;
       
   309 	}
       
   310 
       
   311 CSDModel::CSDModel()
       
   312 	: iAcousticModelPtr(NULL,0)
       
   313 	{
       
   314 	
       
   315 	}
       
   316 
       
   317 
       
   318 CSDModel::CSDModel(TPhonemeID aPhonemeID)
       
   319 	: iPhonemeID(aPhonemeID), iAcousticModelPtr(NULL,0)
       
   320 	{
       
   321 	
       
   322 	}
       
   323 	
       
   324 void CSDModel::ConstructL()
       
   325 	{
       
   326 	
       
   327 	}
       
   328 
       
   329 
       
   330 EXPORT_C CSDModel* CSDModel::NewL()
       
   331 	{
       
   332 	CSDModel* self = CSDModel::NewLC();
       
   333 	CleanupStack::Pop(self);
       
   334 	return self;
       
   335 	}	
       
   336 	
       
   337 EXPORT_C CSDModel* CSDModel::NewLC()
       
   338 	{
       
   339 	CSDModel* self = new (ELeave) CSDModel;
       
   340 	CleanupStack::PushL(self);
       
   341 	self->ConstructL();	
       
   342 	return self;
       
   343 	}	
       
   344 
       
   345 
       
   346 	
       
   347 EXPORT_C CSDModel* CSDModel::NewL(TPhonemeID aPhonemeID)
       
   348 	{
       
   349 	CSDModel* self = CSDModel::NewLC(aPhonemeID);
       
   350 	CleanupStack::Pop(self);
       
   351 	return self;
       
   352 	}	
       
   353 	
       
   354 EXPORT_C CSDModel* CSDModel::NewLC(TPhonemeID aPhonemeID)
       
   355 	{
       
   356 	CSDModel* self = new (ELeave) CSDModel(aPhonemeID);
       
   357 	CleanupStack::PushL(self);
       
   358 	self->ConstructL();	
       
   359 	return self;
       
   360 	}	
       
   361 	
       
   362 
       
   363 EXPORT_C TPhonemeID CSDModel::PhonemeID() const
       
   364 	{
       
   365 	return iPhonemeID;
       
   366 	
       
   367 	}
       
   368 
       
   369 
       
   370 EXPORT_C void CSDModel::SetPhonemeID(TPhonemeID aPhonemeID)
       
   371 	{
       
   372 	iPhonemeID = aPhonemeID;
       
   373 	}
       
   374 
       
   375 EXPORT_C void CSDModel::SetAcousticModel(TPtr8& aAcousticModelPtr)
       
   376 	{
       
   377 	iAcousticModelPtr.Set(aAcousticModelPtr);
       
   378 	}
       
   379 
       
   380 EXPORT_C const TDesC8& CSDModel::AcousticModel() const
       
   381 	{
       
   382 	return iAcousticModelPtr;
       
   383 	}
       
   384 	
       
   385 	
       
   386 CSDModelBank::CSDModelBank(TModelBankID aModelBankID)
       
   387 	{
       
   388 	iModelBankID = aModelBankID;
       
   389 	}
       
   390 
       
   391 
       
   392 EXPORT_C CSDModelBank::~CSDModelBank()
       
   393 	{
       
   394 	iModelArray.ResetAndDestroy();
       
   395 	}
       
   396 
       
   397 EXPORT_C CSDModelBank* CSDModelBank::NewL(TModelBankID aModelBankID)
       
   398 	{
       
   399 	CSDModelBank* self = CSDModelBank::NewLC(aModelBankID);
       
   400 	CleanupStack::Pop(self);
       
   401 	return self;	
       
   402 	}
       
   403 	
       
   404 EXPORT_C CSDModelBank* CSDModelBank::NewLC(TModelBankID aModelBankID)
       
   405 	{
       
   406 	CSDModelBank* self = new (ELeave) CSDModelBank(aModelBankID);
       
   407 	CleanupStack::PushL(self);
       
   408 	self->ConstructL();
       
   409 	return self;	
       
   410 	}
       
   411 
       
   412 void CSDModelBank::ConstructL() 
       
   413 	{
       
   414 	}
       
   415 
       
   416 EXPORT_C TInt CSDModelBank::Add(CSDModel& aModel)
       
   417 	{
       
   418 	if (FindModel(aModel.PhonemeID())!=KErrNotFound)
       
   419 		return KErrAlreadyExists;
       
   420 
       
   421 	return iModelArray.Append(&aModel);
       
   422 	}
       
   423 
       
   424 
       
   425 EXPORT_C TInt CSDModelBank::FindModel(TModelID aModelID) const
       
   426 	{
       
   427 	TBool found = EFalse;
       
   428 	TInt index = 0;
       
   429 	TInt count = iModelArray.Count();
       
   430 	for (TInt i=0;i < count;i++) 
       
   431 		{
       
   432 		if (aModelID == iModelArray[i]->PhonemeID()) 
       
   433 			{
       
   434 			found = true;
       
   435 			index = i;
       
   436 			break;
       
   437 			}
       
   438 		}
       
   439 	if (found)
       
   440 		return index;
       
   441 	else
       
   442 		return KErrNotFound;
       
   443 
       
   444 	}
       
   445 
       
   446 
       
   447 EXPORT_C TInt CSDModelBank::Count() const
       
   448 	{
       
   449 	return iModelArray.Count();
       
   450 	}
       
   451 
       
   452 EXPORT_C TModelBankID CSDModelBank::ModelBankID() const
       
   453 	{
       
   454 	return iModelBankID;
       
   455 	}
       
   456 
       
   457 
       
   458 
       
   459 EXPORT_C const CSDModel& CSDModelBank::At(TInt aIndex) const
       
   460 	{
       
   461 	return *iModelArray[aIndex];
       
   462 	}
       
   463 //-------------------------------------------------------------------------------------
       
   464 EXPORT_C CSDResult::~CSDResult()
       
   465 	{
       
   466 	}
       
   467 	
       
   468 CSDResult::CSDResult()
       
   469 	{
       
   470 	}
       
   471 CSDResult::CSDResult(TGrammarID aGrammarID, TRuleID aRuleID)
       
   472 	: iGrammarID(aGrammarID),
       
   473 	  iRuleID(aRuleID)
       
   474 	{
       
   475 	
       
   476 	}
       
   477 	
       
   478 void CSDResult::ConstructL()
       
   479 	{
       
   480 	
       
   481 	}
       
   482 
       
   483 EXPORT_C CSDResult* CSDResult::NewLC()
       
   484 	{
       
   485 	CSDResult* self = new (ELeave) CSDResult;
       
   486 	CleanupStack::PushL(self);
       
   487 	self->ConstructL();	
       
   488 	return self;
       
   489 	}	
       
   490 	
       
   491 EXPORT_C CSDResult* CSDResult::NewL()
       
   492 	{
       
   493 	CSDResult* self = CSDResult::NewLC();
       
   494 	CleanupStack::Pop(self);
       
   495 	return self;
       
   496 	}	
       
   497 	
       
   498 EXPORT_C CSDResult* CSDResult::NewLC(TGrammarID aGrammarID, TRuleID aRuleID)
       
   499 	{
       
   500 	CSDResult* self = new (ELeave) CSDResult(aGrammarID, aRuleID);
       
   501 	CleanupStack::PushL(self);
       
   502 	self->ConstructL();	
       
   503 	return self;
       
   504 	}	
       
   505 	
       
   506 EXPORT_C CSDResult* CSDResult::NewL(TGrammarID aGrammarID, TRuleID aRuleID)
       
   507 	{
       
   508 	CSDResult* self = CSDResult::NewLC(aGrammarID, aRuleID);
       
   509 	CleanupStack::Pop(self);
       
   510 	return self;
       
   511 	}	
       
   512 
       
   513 	
       
   514 EXPORT_C void CSDResult::SetGrammarID(TGrammarID aGrammarID)
       
   515 	{
       
   516 	iGrammarID = aGrammarID;	
       
   517 	
       
   518 	}
       
   519 
       
   520 EXPORT_C TGrammarID CSDResult::GrammarID() const
       
   521 	{
       
   522 	return iGrammarID;
       
   523 	
       
   524 	}
       
   525 
       
   526 
       
   527 EXPORT_C TInt32 CSDResult::Score() const
       
   528 	{
       
   529 	return iScore;
       
   530 	}
       
   531 
       
   532 EXPORT_C void CSDResult::SetScore(TInt32 aScore)
       
   533 	{
       
   534 	iScore = aScore;
       
   535 	}
       
   536 
       
   537 EXPORT_C void CSDResult::SetRuleID(TRuleID aRuleID)
       
   538 	{
       
   539 	iRuleID = aRuleID;
       
   540 	}
       
   541 
       
   542 EXPORT_C TRuleID CSDResult::RuleID() const
       
   543 	{
       
   544 	return iRuleID;
       
   545 	}
       
   546 	
       
   547 	
       
   548 CSDResultSet::CSDResultSet()
       
   549 	{
       
   550 	}
       
   551 
       
   552 
       
   553 EXPORT_C CSDResultSet::~CSDResultSet()
       
   554 	{
       
   555 	iResultArray.ResetAndDestroy();
       
   556 	delete iDiagnostic;
       
   557 	}
       
   558 
       
   559 EXPORT_C CSDResultSet* CSDResultSet::NewL()
       
   560 	{
       
   561 	CSDResultSet* self = CSDResultSet::NewLC();
       
   562 	CleanupStack::Pop(self);
       
   563 	return self;	
       
   564 	}
       
   565 	
       
   566 EXPORT_C CSDResultSet* CSDResultSet::NewLC()
       
   567 	{
       
   568 	CSDResultSet* self = new (ELeave) CSDResultSet;
       
   569 	CleanupStack::PushL(self);
       
   570 	self->ConstructL();
       
   571 	return self;	
       
   572 	}
       
   573 
       
   574 
       
   575 EXPORT_C TInt CSDResultSet::Add(CSDResult& aResult)
       
   576 	{
       
   577 	return iResultArray.Append(&aResult);
       
   578 	}
       
   579 
       
   580 EXPORT_C TInt CSDResultSet::Count() const
       
   581 	{
       
   582 	return iResultArray.Count();
       
   583 	}
       
   584 
       
   585 	
       
   586 
       
   587 EXPORT_C const CSDResult& CSDResultSet::At(TInt aIndex)
       
   588 	{
       
   589 	return *iResultArray[aIndex];
       
   590 	}
       
   591 
       
   592 EXPORT_C void CSDResultSet::SetDiagnostic(TDiagnostic& aDiagnostic)
       
   593 	{
       
   594 	iDiagnostic = &aDiagnostic;
       
   595 	}
       
   596 
       
   597 EXPORT_C const TDiagnostic& CSDResultSet::Diagnostic() const
       
   598 	{
       
   599 	return *iDiagnostic;
       
   600 	}
       
   601 
       
   602 
       
   603 	
       
   604 	
       
   605 void CSDResultSet::ConstructL()
       
   606 	{
       
   607 	}
       
   608 
       
   609 EXPORT_C TDiagnostic::TDiagnostic() 
       
   610 	: iData(NULL,0)
       
   611 	{
       
   612 	iSNR = 0;
       
   613 	iAccepted = EFalse;
       
   614 	}
       
   615 	
       
   616 
       
   617 EXPORT_C TDiagnostic::~TDiagnostic() 
       
   618 	{
       
   619 	}
       
   620