os/mm/mmdevicefw/speechrecogsupport/ASR/inc/SpeechRecognitionUtility.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2002-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 //
    15 
    16 #ifndef __SPEECHRECOGNITIONUTILITY_H__
    17 #define __SPEECHRECOGNITIONUTILITY_H__
    18 
    19 // INCLUDES
    20 
    21 #include <e32base.h>
    22 #include <mmf/common/mmfcontroller.h>
    23 #include <mmf/common/speechrecognitioncustomcommands.h>
    24 #include <mmf/common/speechrecognitiondataclient.h>
    25 #include <speechrecognitionutilityobserver.h>
    26 
    27 
    28 // CLASS DECLARATION
    29 
    30 /**
    31 @publishedAll
    32 @released
    33 
    34 This is the main class of Speech Recognition Utility.
    35 
    36 @since  8.0
    37 */
    38 class CSpeechRecognitionUtility : public CBase
    39 	{
    40 	class CBody;
    41 public:
    42 
    43 	/**
    44 	Factory function for creating this class.
    45 
    46 	@param	aClientUid
    47 	        The UID of the client.
    48 	@param 	aSpeechRecognitionUtilityObserver
    49 	        A reference to the event observer class.
    50 
    51 	@return	A pointer to CSpeechRecognitionUtility object
    52 
    53 	@since  8.0
    54 	*/
    55 	IMPORT_C static CSpeechRecognitionUtility* NewL(
    56 							MSpeechRecognitionUtilityObserver&
    57 							aSpeechRecognitionUtilityObserver, TUid aClientUid );
    58 
    59 	/**
    60 	Factory function for creating this class. Leaves a pointer on the cleanup stack.
    61 
    62 	@param  aSpeechRecognitionUtilityObserver		
    63 	        A reference to the event observer class.
    64 	@param  aClientUid
    65 	        A client UID for data ownership.
    66 
    67 	@return A pointer to a CSpeechRecognitionUtility object.
    68 
    69 	@since  8.0
    70 	*/
    71 	IMPORT_C static CSpeechRecognitionUtility* NewLC(
    72 							MSpeechRecognitionUtilityObserver&
    73 							aSpeechRecognitionUtilityObserver, TUid aClientUid );
    74 
    75 	/**
    76 	Destructor.
    77 
    78 	@since  8.0
    79 	*/
    80 	IMPORT_C ~CSpeechRecognitionUtility();
    81 
    82 	/**
    83 	Returns the engine properties specified by the engine property
    84 	ID array. On return aPropertyValue contains an array of engine
    85 	properties.
    86 
    87 	@param  aPropertyId		
    88 	        A constant reference to an array of engine property ID's.
    89 	@param  aPropertyValue
    90 	        A reference to an array of engine property values.
    91 
    92 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
    93 	        another of the system-wide error codes.
    94 
    95 	@since  8.0
    96 	*/
    97 	IMPORT_C TInt GetEngineProperties( const RArray<TInt>& aPropertyId,
    98 		RArray<TInt>& aPropertyValue );
    99 
   100 	/**
   101 	Adds a new pronunciation for the given model into the
   102 	specified lexicon.
   103 	
   104 	@param  aLexiconID			
   105 	        The lexicon ID, where the new pronunciation is added to.
   106 	@param  aModelBankID		
   107 	        The model bank ID.
   108 	@param	aModelID			
   109 	        The model ID.
   110 	@param  aPronunciationID	
   111 	        A reference where the new pronunciation ID is assigned to.
   112 
   113 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   114 	        another of the system-wide error codes.
   115 
   116 	@since  8.0
   117 	*/
   118 	IMPORT_C TInt AddPronunciation( TLexiconID aLexiconID,
   119 		TModelBankID aModelBankID, TModelID aModelID,
   120 		TPronunciationID& aPronunciationID );
   121 
   122 	/**
   123 	Adds a new rule for the given pronunciation into the
   124 	specified grammar.
   125 
   126 	@param  aGrammarID			
   127 	        The grammar ID, where the new rule is added to.
   128 	@param  aLexiconID			
   129 	        The lexicon ID.
   130 	@param  aPronunciationID	
   131 	        The pronunciation ID.
   132 	@param  aRuleID				
   133 	        A reference where the new rule ID is assigned to.
   134 
   135 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   136 	        another of the system-wide error codes.
   137 
   138 	@since  8.0
   139 	*/
   140 	IMPORT_C TInt AddRule( TGrammarID aGrammarID, TLexiconID aLexiconID,
   141 		TPronunciationID aPronunciationID, TRuleID& aRuleID );
   142 
   143 	/**
   144 	Cancels the current operation.
   145 
   146 	@since 8.0
   147 	*/
   148 	IMPORT_C void Cancel();
   149 
   150 	/**
   151 	Commit the current train operation to the database.
   152 
   153 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   154 	        another of the system-wide error codes.
   155 
   156 	@since  8.0
   157 	*/
   158 	IMPORT_C TInt CommitChanges();
   159 
   160 	/**
   161 	Creates a new grammar.
   162 
   163 	@param  aGrammarID			
   164 	        A reference where grammar ID is stored.
   165 
   166 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   167 	        another of the system-wide error codes.
   168 
   169 	@since  8.0
   170 	*/
   171 	IMPORT_C TInt CreateGrammar( TGrammarID& aGrammarID );
   172 
   173 	/**
   174 	Creates a new lexicon.
   175 
   176 	@param  aLexiconID			
   177 	        A reference where lexicon ID is stored.
   178 
   179 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   180 	        another of the system-wide error codes.
   181 
   182 	@since  8.0
   183 	*/
   184 	IMPORT_C TInt CreateLexicon( TLexiconID& aLexiconID );
   185 
   186 	/**
   187 	Loads the specified model bank into the recognizer;
   188 	done prior to recognition.
   189 
   190 	@param  aModelBankID
   191 			The Model bank ID
   192 
   193 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   194 	        another of the system-wide error codes.
   195 
   196 	@since  8.0
   197 	*/
   198 	IMPORT_C TInt LoadModels( TModelBankID aModelBankID );
   199 
   200 	/**
   201 	Loads the specified grammar into the recognizer;
   202 	done prior to recognition.
   203 	
   204 	@param  aGrammarID			
   205 	        The grammar ID.
   206 
   207 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   208 	        another of the system-wide error codes.
   209 
   210 	@since  8.0
   211 	*/
   212 	IMPORT_C TInt LoadGrammar( TGrammarID aGrammarID );
   213 
   214 	/**
   215 	Loads the specified lexicon into the recognizer;
   216 	done prior to recognition.
   217 
   218 	@param  aLexiconID			
   219 	        The lexicon ID.
   220 
   221 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   222 	        another of the system-wide error codes.
   223 
   224 	@since  8.0
   225 	*/
   226 	IMPORT_C TInt LoadLexicon( TLexiconID aLexiconID );
   227 
   228 	/**
   229 	Returns the duration of the utterance for the specified model.
   230 
   231 	@param  aModelBankID		
   232 	        The model bank ID.
   233 	@param  aModelID			
   234 	        The model ID.
   235 	@param  aDuration			
   236 	        The reference where the duration of utterance is set.
   237 
   238 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   239 	        another of the system-wide error codes.
   240 
   241 	@since  8.0
   242 	*/
   243 	IMPORT_C TInt GetUtteranceDuration( TModelBankID aModelBankID,
   244 		TModelID aModelID,
   245 		TTimeIntervalMicroSeconds32& aDuration);
   246 
   247 	/**
   248 	Plays the previously trained utterance.
   249 
   250 	@param  aModelBankID
   251 	        The model bank ID.
   252 	@param  aModelID
   253 	        The model ID, whose utterance is played.
   254 
   255 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   256 	        another of the system-wide error codes.
   257 
   258 	@since  8.0
   259 	*/
   260 	IMPORT_C TInt PlayUtterance( TModelBankID aModelBankID,
   261 		TModelID aModelID);
   262 
   263 	/**
   264 	Returns the number of models in the specified model bank.
   265 
   266 	@param  aModelBankID		
   267 	        The model bank ID.
   268 	@param  aModelCount			
   269 	        The reference where the number of models is set.
   270 
   271 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   272 	        another of the system-wide error codes.
   273 
   274 	@since  8.0
   275 	*/
   276 	IMPORT_C TInt GetModelCount( TModelBankID aModelBankID, TInt& aModelCount );
   277 
   278 	/**
   279 	Ends the current recognition session. Resources allocated
   280 	for recognition are freed.
   281 
   282 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   283 	        another of the system-wide error codes.
   284 
   285 	@since  8.0
   286 	*/
   287 	IMPORT_C TInt EndRecSession();
   288 
   289 	/**
   290 	Starts a new recognition session.
   291 
   292 	@param  aMode				
   293 	        The recognition mode.
   294 
   295 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   296 	        another of the system-wide error codes.
   297 
   298 	@since  8.0
   299 	*/
   300 	IMPORT_C TInt StartRecSession( TRecognitionMode aMode );
   301 
   302 	/**
   303 	Initiates recognition; performed following loading of
   304 	model bank, lexicon, and grammar.
   305 
   306 	@param  aResultSet			
   307 	        A reference where the recognition result is set.
   308 
   309 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   310 	        another of the system-wide error codes.
   311 
   312 	@since  8.0
   313 	*/
   314 	IMPORT_C TInt Recognize( CSDClientResultSet& aResultSet );
   315 
   316 	/**
   317 	Records user utterance for training and recognition.
   318 
   319 	@param  aRecordTime			
   320 	        The recording time in microseconds.
   321 
   322 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   323 	        another of the system-wide error codes.
   324 
   325 	@since  8.0
   326 	*/
   327 	IMPORT_C TInt Record( TTimeIntervalMicroSeconds32 aRecordTime );
   328 
   329 	/**
   330 	Removes the specified grammar from the permanent storage. 
   331 
   332 	Removing a grammar will remove all rules within the grammar.
   333 
   334 	@param  aGrammarID			
   335 	        The grammar ID.
   336 
   337 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   338 	        another of the system-wide error codes.
   339 
   340 	@since  8.0
   341 	*/
   342 	IMPORT_C TInt RemoveGrammar( TGrammarID aGrammarID );
   343 
   344 	/**
   345 	Removes the specified pronunciation from the specified lexicon permanently.
   346 
   347 	@param  aLexiconID			
   348 	        The lexicon ID.
   349 	@param  aPronunciationID	
   350 	        The pronunciation ID.
   351 
   352 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   353 	        another of the system-wide error codes.
   354 
   355 	@since  8.0
   356 	*/
   357 	IMPORT_C TInt RemovePronunciation( TLexiconID aLexiconID,
   358 		TPronunciationID aPronunciationID );
   359 
   360 	/**
   361 	Removes the specified lexicon from the permanent storage.
   362 	
   363 	Removing a lexicon will remove all pronunciations within the lexicon.
   364 
   365 	@param  aLexiconID			
   366 	        The lexicon ID.
   367 
   368 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   369 	        another of the system-wide error codes.
   370 
   371 	@since  8.0
   372 	*/
   373 	IMPORT_C TInt RemoveLexicon( TLexiconID aLexiconID );
   374 
   375 	/**
   376 	Removes the specified model from the specified model bank
   377 	permanently.
   378 
   379 	@param  aModelBankID		
   380 	        The model bank ID.
   381 	@param  aModelID			
   382 	        The model ID.
   383 
   384 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   385 	        another of the system-wide error codes.
   386 
   387 	@since  8.0
   388 	*/
   389 	IMPORT_C TInt RemoveModel( TModelBankID aModelBankID,
   390 		TModelID aModelID );
   391 
   392 	/**
   393 	Removes the specified rule from the specified grammar permanently.
   394 
   395 	@param  aGrammarID			
   396 	        The grammar ID.
   397 	@param  aRuleID
   398 	        The rule ID.
   399 
   400 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   401 	        another of the system-wide error codes.
   402 
   403 	@since  8.0
   404 	*/
   405 	IMPORT_C TInt RemoveRule( TGrammarID aGrammarID, TRuleID aRuleID );
   406 
   407 	/**
   408 	Trains a new model into the specified model bank.
   409 
   410 	@param  aModelBankID		
   411 	        The model bank ID.
   412 	@param  aModelID			
   413 	        A reference where a new model ID is assigned to.
   414 
   415 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   416 	        another of the system-wide error codes.
   417 
   418 	@since  8.0
   419 	*/
   420 	IMPORT_C TInt Train( TModelBankID aModelBankID, TModelID& aModelID );
   421 
   422 	/**
   423 	Unloads the specified rule from the specified grammar in temporary memory, previously loaded 
   424 	with LoadGrammarL.
   425 
   426 	The rule in the permanent storage remains intact.
   427 
   428 	@param  aGrammarID			
   429 	        The grammar ID.
   430 	@param  aRuleID				
   431 	        The rule ID.
   432 
   433 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   434 	        another of the system-wide error codes.
   435 
   436 	@since  8.0
   437 	*/
   438 	IMPORT_C TInt UnloadRule( TGrammarID aGrammarID, TRuleID aRuleID );
   439 
   440 	/**
   441 	Sets the event handler for asynchronous events.
   442 
   443 	@param  aSpeechRecognitionUtilityObserver		
   444 	        A pointer to an observer.
   445 
   446 	@since  8.0
   447 	*/
   448 	IMPORT_C void SetEventHandler( MSpeechRecognitionUtilityObserver*
   449 		aSpeechRecognitionUtilityObserver );
   450 
   451 	/**
   452 	Returns all pronunciation IDs that exist in the specified lexicon.
   453 
   454 	@param  aLexiconID
   455 	        The lexicon ID.
   456 	@param  aPronunciationIDs
   457 	        A reference where pronunciation IDs are stored.
   458 
   459 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   460 	        another of the system-wide error codes.
   461 
   462 	@since  8.0
   463 	*/
   464 	IMPORT_C TInt GetAllPronunciationIDs( TLexiconID aLexiconID,
   465 		RArray <TPronunciationID>& aPronunciationIDs );
   466 
   467 	/**
   468 	Returns all grammar IDs owned by the client.
   469 
   470 	@param  aGrammarIDs			
   471 	        A reference where rule IDs are stored.
   472 
   473 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   474 	        another of the system-wide error codes.
   475 
   476 	@since  8.0
   477 	*/
   478 	IMPORT_C TInt GetAllClientGrammarIDs(RArray <TGrammarID>& aGrammarIDs );
   479 
   480 	/**
   481 	Returns all lexicons owned by the client.
   482 
   483 	@param  aLexiconIDs	
   484 	        A reference where lexicon IDs are stored.
   485 
   486 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   487 	        another of the system-wide error codes.
   488 
   489 	@since  8.0
   490 	*/
   491 	IMPORT_C TInt GetAllClientLexiconIDs(RArray <TLexiconID>& aLexiconIDs );
   492 
   493 	/**
   494 	Returns all modelbank IDs owned by the client.
   495 
   496 	@param  aModelBankIDs			
   497 	        A reference where modelbank IDs are stored.
   498 
   499 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   500 	        another of the system-wide error codes.
   501 
   502 	@since  8.0
   503 	*/
   504 		IMPORT_C TInt GetAllClientModelBankIDs(
   505 							RArray<TModelBankID>& aModelBankIDs );
   506 	/**
   507 	Returns all grammar IDs.
   508 
   509 	@param  aGrammarIDs			
   510 	        A reference where rule IDs are stored.
   511 
   512 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   513 	        another of the system-wide error codes.
   514 
   515 	@since  8.0
   516 	*/
   517 	IMPORT_C TInt GetAllGrammarIDs(RArray <TGrammarID>& aGrammarIDs );
   518 	
   519 	/**
   520 	Returns all lexicons IDs.
   521 
   522 	@param  aLexiconIDs	
   523 	        A reference where lexicon IDs are stored.
   524 
   525 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   526 	        another of the system-wide error codes.
   527 
   528 	@since  8.0
   529 	*/
   530 	IMPORT_C TInt GetAllLexiconIDs(RArray <TLexiconID>& aLexiconIDs );
   531 
   532 	/**
   533 	Returns all modelbank IDs.
   534 
   535 	@param  aModelBankIDs			
   536 	        A reference where modelbank IDs are stored.
   537 
   538 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   539 	        another of the system-wide error codes.
   540 
   541 	@since  8.0
   542 	*/
   543 	IMPORT_C TInt GetAllModelBankIDs(
   544 		RArray<TModelBankID>& aModelBankIDs );
   545 
   546 	/**
   547 	Returns all model IDs that exist in the specified model bank.
   548 
   549 	@param  aModelBankID		
   550 	        The model bank ID.
   551 	@param  aModelIDs			
   552 	        A reference where model IDs are stored.
   553 
   554 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   555 	        another of the system-wide error codes.
   556 
   557 	@since  8.0
   558 	*/
   559 	IMPORT_C TInt GetAllModelIDs( TModelBankID aModelBankID,
   560 		RArray <TModelID>& aModelIDs );
   561 
   562 	/**
   563 	Checks if the rule is valid or not.
   564 
   565 	@param  aGrammarID
   566 	        The grammar ID.
   567 	@param	aRuleID
   568 			The rule ID.
   569 	@param  aValid
   570 	        A reference where the validity of the rule is set.
   571 
   572 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   573 	        another of the system-wide error codes.
   574 
   575 	@since  8.0
   576 	*/
   577 	IMPORT_C TInt GetRuleValidity( TGrammarID aGrammarID, TRuleID aRuleID,
   578 		TBool& aValid );
   579 
   580 	/**
   581 	Returns all rule IDs that exist in the specified grammar.
   582 
   583 	@param  aGrammarID			
   584 	        The grammar ID.
   585 	@param  aRuleIDs			
   586 	        A reference where rule IDs are stored.
   587 
   588 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   589 	        another of the system-wide error codes.
   590 
   591 	@since  8.0
   592 	*/
   593 	IMPORT_C TInt GetAllRuleIDs( TGrammarID aGrammarID,
   594 		RArray <TRuleID>& aRuleIDs );
   595 
   596 	/**
   597 	Creates a new model bank.
   598 
   599 	@param  aModelBankID		
   600 	        A reference where a new model bank IF is assigned to.
   601 
   602 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   603 	        another of the system-wide error codes.
   604 
   605 	@since  8.0
   606 	*/
   607 	IMPORT_C TInt CreateModelBank( TModelBankID& aModelBankID );
   608 
   609 	/**
   610 	Removes the specified model bank from the permanent storage.
   611 
   612 	Removing a model bank will remove all models within the model bank.
   613 
   614 	@param  aModelBankID		
   615 	        The model bank ID.
   616 
   617 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   618 	        another of the system-wide error codes.
   619 
   620 	@since	8.0
   621 	*/
   622 	IMPORT_C TInt RemoveModelBank( TModelBankID aModelBankID );
   623 
   624 	/**
   625 	Returns the number of models available for training system model storage, based on available 
   626 	disk space.
   627 
   628 	@param  aAvailableStorage	
   629 	        The number of models that can be contained in available storage.
   630 
   631 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   632 	        another of the system-wide error codes.
   633 
   634 	@since  8.0
   635 	*/
   636 	IMPORT_C TInt GetAvailableStorage( TInt& aAvailableStorage );
   637 
   638 	/**
   639 	Loads the specified parameters into the recognition engine.
   640 
   641 	@param  aParameterId		
   642 	        The array of parameter IDs.
   643 	@param  aParameterValue		
   644 	        The array of parameter values.
   645 
   646 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   647 	        another of the system-wide error codes.
   648 
   649 	@since  8.0
   650 	*/
   651 	IMPORT_C TInt LoadEngineParameters( const RArray<TInt>& aParameterId,
   652 					const RArray<TInt>& aParameterValue );
   653 
   654 	/**
   655 	Sets the audio priority and preference for train, playback and recognition.
   656 
   657 	@param  aPriority				
   658 	        The priority for voice recognition.
   659 	@param  aTrainPreference		
   660 	        The preference for training.
   661 	@param  aPlaybackPreference		
   662 	        The preference for playback.
   663 	@param  aRecognitionPreference	
   664 	        The preference for recognition.
   665 
   666 	@return An error code indicating if the function call was successful. KErrNone on success, otherwise
   667 	        another of the system-wide error codes.
   668 
   669 	@since  8.0
   670 
   671 	*/
   672 	IMPORT_C TInt SetAudioPriority( TInt aPriority, TInt aTrainPreference,
   673 		TInt aPlaybackPreference, TInt aRecognitionPreference );
   674 
   675 private:
   676 	/**
   677 	Private C++ constructor for this class.
   678 
   679 	@since  8.0
   680 	*/
   681 	CSpeechRecognitionUtility();
   682 
   683 	/**
   684 	Second phase constructor for this class.
   685 
   686 	@param  aSpeechRecognitionUtilityObserver		
   687 	        A reference to the event observer class.
   688 
   689 	@since  8.0
   690 	*/
   691 	void ConstructL(MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver);
   692 
   693 private:
   694 	CBody* iBody;
   695 	friend class CBody;
   696 };
   697 
   698 #endif	// of __SPEECHRECOGNITIONUTILITY_H__
   699 
   700 	// End of File