speechsrv_plat/nss_devasr_api/inc/nssdevasr.h
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2004-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:  This file contains definition of the DevASR API.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NSSDEVASRAPI_H
       
    20 #define NSSDEVASRAPI_H
       
    21 
       
    22 //#define AUDIOBUFFER_TO_FILE
       
    23 
       
    24 //  INCLUDES
       
    25 #include <e32base.h>
       
    26 #include <nsssispeechrecognitiondatadevasr.h>
       
    27 #include <nssdevasrcommon.h>
       
    28 
       
    29 // FORWARD DECLARATIONS
       
    30 class CSRSAlgorithmManager;
       
    31 class CVMAlgorithmManager;
       
    32 class TMMFPrioritySettings;
       
    33 
       
    34 /**
       
    35 *  Interface for the DevASR callbacks that are implemented by DevASR observers.
       
    36 *
       
    37 *  @lib NssDevASR.lib
       
    38 *  @since 2.8
       
    39 */
       
    40 class MDevASRObserver
       
    41     {
       
    42     public:
       
    43         /**
       
    44         * DevASR calls this method to get configuration data.
       
    45         *
       
    46         * @since 2.8
       
    47         * @param "TUint32 aPackageType" Type identifier.
       
    48         * @param "TUint32 aPackageID" Identifier of package.
       
    49         * @param "TUint32 aStartPosition" Starting position within package in bytes.
       
    50         * @param "TUint32 aEndPosition" Ending position within package in bytes.
       
    51         * @return Pointer to created buffer containing the request data.
       
    52         */
       
    53         virtual HBufC8* ConfigurationData( TUint32 aPackageType, 
       
    54                                            TUint32 aPackageID,
       
    55                                            TUint32 aStartPosition = 0,
       
    56                                            TUint32 aEndPosition = KMaxTUint32 ) = 0;
       
    57         
       
    58         /**
       
    59         * DevASR notifies object implementing this interface whenever a spontaneous or non-spontaneous
       
    60         * event occurs in DevASR.
       
    61         *
       
    62         * @since 2.8
       
    63         * @param "TDevASREvent aEvent" DevASR event code.
       
    64         * @param "TDevASRError aError" DevASR error code.
       
    65         */
       
    66         virtual void DevASREvent( TDevASREvent aEvent, TDevASRError aError ) = 0;
       
    67         
       
    68         /**
       
    69         * DevASR notifies object implementing this interface when feature vectors are available.
       
    70         *
       
    71         * @since 2.8
       
    72         * @param "TDesC16& aFV" Buffer containing the feature vector data.
       
    73         * @param "TInt32 aSNR" Signal-to-noise ratio.
       
    74         * @param "TInt32 aPosition" Indicates whether the feature vector is the first, middle, or end.
       
    75         */
       
    76         virtual void FeatureVectorDataRcvd( const TDesC8& aFV, TInt32 aSNR, TInt32 aPosition ) = 0;
       
    77         
       
    78         /**
       
    79         * DevASR calls this method to send a message in response to a custom command.
       
    80         *
       
    81         * @since 2.8
       
    82         * @param "TDesC8& aMsg" Buffer containing the message.
       
    83         */
       
    84         virtual void DevASRMessage( TDesC8& aMsg ) = 0;
       
    85         
       
    86         /**
       
    87         * Called when DevASR needs a SI lexicon.
       
    88         *
       
    89         * @since 2.8
       
    90         * @param "TSILexiconID aLexiconID" Lexicon ID of requested lexicon.
       
    91         * @return Pointer to created lexicon.
       
    92         */
       
    93         virtual CSILexicon* SILexiconL( TSILexiconID aLexiconID ) = 0;
       
    94 
       
    95         /**
       
    96         * Invoked by DevASR when it needs utterance data. The response is sent
       
    97         * using SendSpeechData().
       
    98         *
       
    99         * @since 2.8
       
   100         */
       
   101         virtual void RequestSpeechData() = 0;
       
   102     };
       
   103 
       
   104 /**
       
   105 *  Interface Class for the DevASR API.
       
   106 *
       
   107 *  @lib NssDevASR.lib
       
   108 *  @since 2.8
       
   109 */
       
   110 class CDevASR : public CBase
       
   111     {
       
   112     public: // Constructors and destructor
       
   113         
       
   114         /**
       
   115         * Two-phased constructors.
       
   116         *
       
   117         * @param "MDevASRObserver& aObserver" Reference to callback observer.
       
   118         */
       
   119         IMPORT_C static CDevASR* NewL( MDevASRObserver& aObserver );
       
   120         IMPORT_C static CDevASR* NewLC( MDevASRObserver& aObserver );
       
   121         
       
   122         /**
       
   123         * Destructor.
       
   124         */
       
   125         IMPORT_C virtual ~CDevASR();
       
   126         
       
   127     public: // New functions
       
   128         
       
   129         /**
       
   130         * Activates a grammar.
       
   131         *
       
   132         * @since 2.8
       
   133         * @param "TSIGrammarID aGrammarID" A grammar identifier.
       
   134         */
       
   135         IMPORT_C void ActivateGrammarL( TSIGrammarID aGrammarID );
       
   136         
       
   137         /**
       
   138         * Adapts vocabulary and models after successful recognition.
       
   139         *
       
   140         * @since 2.8
       
   141         * @param "CSIResultSet& aResultSet" Reco result set.
       
   142         * @param "TInt aResultIndex" Index of correct result.
       
   143         */
       
   144         IMPORT_C void AdaptL( const CSIResultSet& aResultSet, TInt aResultIndex );
       
   145         
       
   146         /**
       
   147         * Cancels the current or started tasks.
       
   148         * @since 2.8
       
   149         */
       
   150         IMPORT_C void Cancel();
       
   151         
       
   152         /**
       
   153         * Compiles an SI grammar.
       
   154         *
       
   155         * @since 2.8
       
   156         * @param "CSICompiledGrammar& aGrammar" Reference to a grammar to be compiled.
       
   157         */
       
   158         IMPORT_C void CompileGrammarL( CSICompiledGrammar& aGrammar );
       
   159 
       
   160         /**
       
   161         * Computes number of rule variants for grammar.
       
   162         *
       
   163         * @since 2.8
       
   164         * @param "CSIGrammar& aGrammar" A grammar where to add new rules.
       
   165         * @param "TUint32 aTargetNRuleVariants" Preferable target number of all 
       
   166         *         rule variants after adding new rule variants.
       
   167         * @param "TUint32 aMaxNRuleVariants" Maximum number of all rule variants.
       
   168         * @param "RArray<TUint>& aNewRuleScores" Scores for each new rule. The 
       
   169         *         size of array tells also how many new rules will be added. 
       
   170         *         Based on the scores some rules can get more rule variants than
       
   171         *         others. If there is no scores available, the array should 
       
   172         *         initialize with constant values.
       
   173         * @param "RArray<TUint>& aNewRuleVariants" Array where to add number 
       
   174         *         of new rule variants for new rules. The order is equivalent 
       
   175         *         to aNewRuleScores.
       
   176         * @param "TUint32& aNPrune" Number of rule variants which should be 
       
   177         *         pruned before adding new rule variants.
       
   178         */
       
   179         IMPORT_C void ComputeNewGrammarSizeL( const CSIGrammar& aGrammar, 
       
   180 											  const TUint32 aTargetNRuleVariants,
       
   181                                               const TUint32 aMaxNRuleVariants,
       
   182                                               const RArray<TUint>& aNewRuleScores,
       
   183                                               RArray<TUint>& aNewRuleVariants,
       
   184                                               TUint32& aNPrune );
       
   185 
       
   186         /**
       
   187         * Use to request a custom interface implementation from the component.
       
   188         * through the DevASR API.
       
   189         *
       
   190         * @since 2.8
       
   191         * @param "TUid aInterfaceId" Interface UID, defined with the custom 
       
   192         *         interface.
       
   193         * @return A pointer to the interface implementation, or NULL if the 
       
   194         *         requested interface is not implemented. The return value must
       
   195         *         be cast to the correct type by the user.
       
   196         */
       
   197         IMPORT_C TAny* CustomInterface( TUid aInterfaceId );
       
   198         
       
   199         /**
       
   200         * Deactivates a grammar.
       
   201         *
       
   202         * @since 2.8
       
   203         * @param "TSIGrammarID aGrammarID" A grammar identifier.
       
   204         */
       
   205         IMPORT_C void DeactivateGrammarL( TSIGrammarID aGrammarID );
       
   206         
       
   207         /**
       
   208         * Requests to end recording and a result will be resolved.
       
   209         *
       
   210         * @since 2.8
       
   211         */
       
   212         IMPORT_C void EndRecord();
       
   213 
       
   214         /**
       
   215         * This method is used to indicate the end of a recognition session. All loaded grammars,
       
   216         * lexicon, and models become invalid after this call.
       
   217         *
       
   218         * @since 2.8
       
   219         */
       
   220         IMPORT_C void EndRecSession();
       
   221         
       
   222         /**
       
   223         * Retreive the properties of the underlying speech recognition engine.
       
   224         *
       
   225         * @since 2.8
       
   226         * @param "RArray<TInt>& aPropertyId" An array of identifiers being querried.
       
   227         * @param "RArray<TInt>& aPropertyValue" An array of values corresponding
       
   228         *         to the querried identifiers.
       
   229         */
       
   230         IMPORT_C void GetEnginePropertiesL( const RArray<TInt>& aPropertyId, 
       
   231                                             RArray<TInt>& aPropertyValue );
       
   232         
       
   233         /**
       
   234         * Retreive the raw audio data accumulated during recording.
       
   235         *
       
   236         * @since 2.8
       
   237         * @param "TDes8* aBuffer" The buffer where utterance data will be 
       
   238         *        written.
       
   239         * @param "TTimeIntervalMicroSeconds32& aDuration" Duration of the 
       
   240         *        utterance.
       
   241         */
       
   242         IMPORT_C void GetUtteranceData( TDes8* aBuffer, 
       
   243                                         TTimeIntervalMicroSeconds32& aDuration );
       
   244         
       
   245         /**
       
   246         * Initializes the front-end module in the speech recognition engine.
       
   247         * The frontend module used during training/recognition functions is started
       
   248         * as a result. This method is intended to be used in conjunction with InitTrainBE().
       
   249         *
       
   250         * @since 2.8
       
   251         * @param "TRecognizerMode aMode" Mode of the recognizer.
       
   252         */
       
   253         IMPORT_C void InitFrontEnd( TRecognizerMode aMode );
       
   254         
       
   255         /**
       
   256         * Initialize the recognition engine back-end. The module responsible for recognition
       
   257         * function is started as a result. This method must be used before any recognition
       
   258         * operations and intended to be used in conjunction with InitFrontEnd().
       
   259         *
       
   260         * @since 2.8
       
   261         * @param "CSIResultSet& aResult" A reference to an object where the 
       
   262         *        recognition result will be written.
       
   263         */
       
   264         IMPORT_C void InitRecognizerBE( CSIResultSet& aResult );
       
   265         
       
   266         /**
       
   267         * Load the specified recognizer parameter(s). These parameters are used to alter the
       
   268         * recognizer's default parameters. The parameters are specified as attribute-value pairs.
       
   269         *
       
   270         * @since 2.8
       
   271         * @param "RArray<TInt>& aParameterId" An array of parameter identifiers.
       
   272         * @param "RArray<TInt>& aParameterValue" An array of parameter values.
       
   273         */
       
   274         IMPORT_C void LoadEngineParametersL( const RArray<TInt>& aParameterId, 
       
   275                                              const RArray<TInt>& aParameterValue );
       
   276         
       
   277         /**
       
   278         * Load the specified grammar into the recognizer.
       
   279         *
       
   280         * @since 2.8
       
   281         * @param "CSIGrammar& aGrammar" A reference to a SI grammar.
       
   282         */
       
   283         IMPORT_C void LoadGrammar( const CSIGrammar& aGrammar );
       
   284         
       
   285         /**
       
   286         * Load the specified grammar into the recognizer.
       
   287         *
       
   288         * @since 2.8
       
   289         * @param "CSICompiledGrammar& aGrammar" A reference to a compiled 
       
   290         *         SI grammar
       
   291         */
       
   292         IMPORT_C void LoadGrammar( const CSICompiledGrammar& aGrammar );
       
   293         
       
   294         /**
       
   295         * Unloads the specified grammar from the recognizer.
       
   296         *
       
   297         * @since 2.8
       
   298         * @param "CSIGrammar& aGrammar" A reference to a SI grammar.
       
   299         */
       
   300         IMPORT_C void UnloadGrammar( const CSIGrammar& aGrammar );
       
   301         
       
   302         /**
       
   303         * Unloads the specified grammar from the recognizer.
       
   304         *
       
   305         * @since 2.8
       
   306         * @param "CSICompiledGrammar& aGrammar" A reference to a compiled 
       
   307         *         SI grammar
       
   308         */
       
   309         IMPORT_C void UnloadGrammar( const CSICompiledGrammar& aGrammar );
       
   310 
       
   311         /**
       
   312         * Load the specified SI lexicon into the recognizer.
       
   313         *
       
   314         * @since 2.8
       
   315         * @param "CSILexicon& aLexicon" A reference to a SI lexicon.
       
   316         */
       
   317         IMPORT_C void LoadLexicon( const CSILexicon& aLexicon );
       
   318         
       
   319         /**
       
   320         * Load the specified model bank into the recognizer.
       
   321         *
       
   322         * @since 2.8
       
   323         * @param "CSIModelBank& aModels" A reference to a SI model bank.
       
   324         */
       
   325         IMPORT_C void LoadModels( const CSIModelBank& aModels );
       
   326         
       
   327         /**
       
   328         * Determines which rule variants can be removed.
       
   329         *
       
   330         * @since 2.8
       
   331         * @param "CSIGrammar& aGrammar" A grammar to be pruned.
       
   332         * @param "TUint32 aMinNumber" Minimum number of pruned items.
       
   333         * @param "RArray<TSIRuleVariantInfo>" A array where to put information 
       
   334         *        which variants can be pruned.
       
   335         */
       
   336         IMPORT_C TBool PruneGrammar( const CSIGrammar& aGrammar, 
       
   337                                      const TUint32 aMinNumber, 
       
   338                                      RArray<TSIRuleVariantInfo>& aPrunedRuleVariants );
       
   339       
       
   340         /**
       
   341         * Request to begin recognition.
       
   342         *
       
   343         * @since 2.8
       
   344         * @param "TTimeIntervalMicroSeconds32 aRecordDuration" Length of time
       
   345         *        to record, expressed in microseconds. Zero means infinite
       
   346         *        duration.
       
   347         */
       
   348         IMPORT_C void Record( TTimeIntervalMicroSeconds32 aRecordDuration );
       
   349 
       
   350         /**
       
   351         * Starts sampling before Record call.
       
   352         * 
       
   353         * @since 3.2
       
   354         */
       
   355         IMPORT_C void PreStartSamplingL();
       
   356 
       
   357         /**
       
   358         * Use to send the utterance data as a response to the RequestSpeechData().
       
   359         *
       
   360         * @since 2.8
       
   361         * @param "TDesC8& aBuffer" Buffer containing utterance data.
       
   362         * @param "TBool aEnd" Flag to tell if given buffer is the last one.
       
   363         */
       
   364         IMPORT_C void SendSpeechData( TPtrC8& aBuffer, TBool aEnd );
       
   365         
       
   366         /**
       
   367         * Use to set the priority of the sound device.
       
   368         *
       
   369         * @since 2.8
       
   370         * @param "TMMFPrioritySettings& aPrioritySettings" Priority settings 
       
   371         *        structure.
       
   372         */
       
   373         IMPORT_C void SetPrioritySettings( const TMMFPrioritySettings& aPrioritySettings );
       
   374        
       
   375         /**
       
   376         * This method is used to start a recognition session with the recognition engine.
       
   377         *
       
   378         * @since 2.8
       
   379         * @param "TRecognizerMode aMode" Mode of the recognizer.
       
   380         * @return Result code of operation.
       
   381         */
       
   382         IMPORT_C TInt StartRecSession( TRecognizerMode aMode );
       
   383         
       
   384         /**
       
   385         * Starts training from text
       
   386         *
       
   387         * @since 2.8
       
   388         * @param "CSITtpWordList& aWordList" List of text entries for training.
       
   389         * @param "RArray<TLanguage>& aDefaultLanguage" Default language for 
       
   390         *        pronunciations.
       
   391         * @param "RArray<TUint>& aMaxNPronunsForWord" Maximum number of 
       
   392         *        pronunciation per word.
       
   393         */
       
   394         IMPORT_C void StartTrainingFromTextL( CSITtpWordList& aWordList, 
       
   395                                               const RArray<TLanguage>& aDefaultLanguage, 
       
   396                                               const RArray<TUint32>& aMaxNPronunsForWord );
       
   397    
       
   398         /**
       
   399         * Request to unload the specified rule in the grammar from recognizer.
       
   400         *
       
   401         * @since 2.8
       
   402         * @param "TSIGrammarID aGrammarID" Identifer of the grammar to operate on.
       
   403         * @param "TSIRuleID aRuleID" Identifier of the rule to remove.
       
   404         */
       
   405         IMPORT_C void UnloadRule( TSIGrammarID aGrammarID, TSIRuleID aRuleID );
       
   406         
       
   407         /**
       
   408         * Checks if grammar is loaded or not
       
   409         *
       
   410         * @since 2.8
       
   411         * @param "TSIGrammarID aGrammarID" Grammar ID
       
   412         * @return ETrue if grammar is currently loaded, EFalse otherwise.
       
   413         */
       
   414         IMPORT_C TBool IsGrammarLoaded( TSIGrammarID aGrammarID );
       
   415         
       
   416         /**
       
   417         * Checks if grammar is active or not
       
   418         *
       
   419         * @since 2.8
       
   420         * @param "TSIGrammarID aGrammarID" Grammar ID
       
   421         * @return ETrue if grammar is active, EFalse otherwise.
       
   422         */
       
   423         IMPORT_C TBool IsGrammarActive( TSIGrammarID aGrammarID );
       
   424 
       
   425     private:
       
   426         
       
   427         /**
       
   428         * C++ default constructor.
       
   429         */
       
   430         CDevASR();
       
   431         
       
   432         /**
       
   433         * By default Symbian 2nd phase constructor is private.
       
   434         */
       
   435         void ConstructL(MDevASRObserver& aObserver);
       
   436         
       
   437     private: // Data
       
   438         
       
   439         // Pointer to recognition algorithm manager
       
   440         CSRSAlgorithmManager* iSRSAlgorithmManager;
       
   441        
       
   442         // Reserved for future use
       
   443         TAny* iReserved1;
       
   444         TAny* iReserved2;
       
   445 
       
   446     };
       
   447     
       
   448 #endif // NSSDEVASRAPI_H
       
   449     
       
   450 // End of File