epoc32/include/mmf/devasr/devasr.h
branchSymbian2
changeset 2 2fe1408b6811
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
       
     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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __DEVASR_H__
       
    17 #define __DEVASR_H__
       
    18 
       
    19 //  INCLUDES
       
    20 #include <e32base.h>
       
    21 #include <mmf/common/speechrecognitiondatadevasr.h>
       
    22 #include <mmf/devasr/devasrcommon.h>
       
    23 
       
    24 // FORWARD DECLARATION
       
    25 class CSRSAlgorithmManager;
       
    26 class TMMFPrioritySettings;
       
    27 
       
    28 /**
       
    29 *  Interface for the DevASR callbacks that are implemented by DevASR observers.
       
    30 *
       
    31 *  @publishedAll
       
    32 *  @released
       
    33 *  @since 8.0
       
    34 */
       
    35 
       
    36 class MDevASRObserver
       
    37 	{
       
    38     public:
       
    39 
       
    40         /**
       
    41         * DevASR notifies object implementing this interface whenever a spontaneous or non-spontaneous
       
    42 		* event occurs in DevASR.
       
    43         * @since 8.0
       
    44         * @param aEvent DevASR event code
       
    45         * @param aError DevASR error code
       
    46         */
       
    47 		virtual void DevASREvent(TDevASREvent aEvent, TDevASRError aError)=0;
       
    48 
       
    49 		/**
       
    50         * DevASR notifies object implementing this interface when feature vectors are available.
       
    51         * @since 8.0
       
    52         * @param aFV Buffer containing the feature vector data
       
    53         * @param aSNR Signal-to-noise ratio
       
    54 		* @param aPosition Indicates whether the feature vector is the first, middle, or end.
       
    55         */
       
    56 		virtual void FeatureVectorDataRcvd(const TDesC16& aFV, TInt32 aSNR, TInt32 aPosition)=0;
       
    57 
       
    58         /**
       
    59         * DevASR calls this method to send a message in response to a custom command.
       
    60         * @since 8.0
       
    61         * @param aMsg Buffer containing the message
       
    62         */
       
    63 		virtual void DevASRMessage(TDesC8& aMsg)=0;
       
    64     };
       
    65 
       
    66 /**
       
    67 *  Interface Class for the DevASR API.
       
    68 *
       
    69 *  @publishedAll
       
    70 *  @released
       
    71 *  @since 8.0
       
    72 */
       
    73 class CDevASR : public CBase
       
    74     {
       
    75     public:  // Constructors and destructor
       
    76 
       
    77         /**
       
    78         * Two-phased constructor.
       
    79         *
       
    80         * @param aObserver The observer to call back when events occur
       
    81         *
       
    82         * @return pointer to object of type CDevASR
       
    83         */
       
    84         IMPORT_C static CDevASR* NewL(MDevASRObserver& aObserver);
       
    85         
       
    86         /**
       
    87         * Two-phased constructor.
       
    88         *
       
    89         * @param aObserver The observer to call back when events occur        
       
    90         *
       
    91         * @return pointer to object of type CDevASR
       
    92         */
       
    93         IMPORT_C static CDevASR* NewLC(MDevASRObserver& aObserver);
       
    94 
       
    95         /**
       
    96         * Destructor.
       
    97         */
       
    98         IMPORT_C virtual ~CDevASR();
       
    99 
       
   100     public: // New functions
       
   101 
       
   102 		/**
       
   103         * Cancels the current or started tasks.
       
   104         * @since 8.0
       
   105         */
       
   106         IMPORT_C void Cancel();
       
   107 
       
   108 		/**
       
   109         * Use to request a custom interface implementation from the component.
       
   110 		* through the DevASR API.
       
   111         * @since 8.0
       
   112         * @param aInterfaceId - Interface UID, defined with the custom interface.
       
   113 		* @return a pointer to the interface implementation, or NULL if the requested interface is
       
   114 		* not implemented. The return value must be cast to the correct type by the user.
       
   115         */
       
   116 		IMPORT_C TAny* CustomInterface(TUid aInterfaceId);
       
   117 
       
   118 		/**
       
   119         * This method is used to indicate the end of a recognition session. All loaded grammars,
       
   120 		* lexicon, and models become invalid after this call.
       
   121         * @since 8.0
       
   122         */
       
   123 		IMPORT_C void EndRecSession();
       
   124 
       
   125 
       
   126 		/**
       
   127         Retreive the properties of the underlying speech recognition engine.
       
   128 
       
   129         @param  aPropertyId
       
   130 		        An array of identifiers being querried
       
   131         @param  aPropertyValue
       
   132 		        An array of values corresponding to the querried identifiers
       
   133 
       
   134         @since  8.0
       
   135         */
       
   136         IMPORT_C void GetEnginePropertiesL(const RArray<TInt>& aPropertyId, RArray<TInt>& aPropertyValue);
       
   137 
       
   138 		/**
       
   139         * Initializes the front-end module in the speech recognition engine.
       
   140 		* The frontend module used during training/recognition functions is started
       
   141 		* as a result. This method is intended to be used in conjunction with InitTrainBE().
       
   142         * @since 8.0
       
   143         * @param aMode - Mode of the recognizer
       
   144         */
       
   145         IMPORT_C void InitFrontEnd(TRecognizerMode aMode);
       
   146 
       
   147 		/**
       
   148         * Perform any necessary initialization or allocation of the audio resource
       
   149 		* for playing a voice sample. A buffer to hold audio data to play is allocated.
       
   150 		* If allocation fails, this method will leave. Client is responsible for filling
       
   151 		* the buffer with their audio data and invoke Play() on DevASR.
       
   152         * @since 8.0
       
   153         * @param aPlayDuration - Specifies the duration of playback in microseconds
       
   154 		* @return A reference to the buffer to be filled with source audio data.
       
   155         */
       
   156 		IMPORT_C TDes8& InitPlayL(TTimeIntervalMicroSeconds32 aPlayDuration);
       
   157 
       
   158 		/**
       
   159         * Initialize the recognition engine back-end. The module responsible for recognition
       
   160 		* function is started as a result. This method must be used before any recognition
       
   161 		* operations and intended to be used in conjunction with InitFrontEnd().
       
   162         * @since 8.0
       
   163         * @param aResult - a reference to an object where the recognition result will be written
       
   164         */
       
   165         IMPORT_C void InitRecognizerBE(CSDResultSet& aResult);
       
   166 
       
   167 		/**
       
   168         * Initializes the back-end module in the speech recognition engine.
       
   169 		* The back-end module responsible for training functions is started as a result.
       
   170 		* This method is intended to be used in conjunction with InitFrontEnd().
       
   171         * @since 8.0
       
   172         * @param aModel	- Buffer in which the newly created model will be written
       
   173         */
       
   174         IMPORT_C void InitTrainBE(CSDModel& aModel);
       
   175 
       
   176 		/**
       
   177         * Load the specified recognizer parameter(s). These parameters are used to alter the
       
   178         * recognizer's default parameters. The parameters are specified as attribute-value pairs.
       
   179         * @since 8.0
       
   180         * @param aParameterId - An array of parameter identifiers
       
   181         * @param aParameterValue - An array of parameter values
       
   182         */
       
   183         IMPORT_C void LoadEngineParametersL(const RArray<TInt>& aParameterId, const RArray<TInt>& aParameterValue);
       
   184 
       
   185 		/**
       
   186         * Load the specified grammar into the recognizer.
       
   187         * @since 8.0
       
   188         * @param aGrammar - A reference to a grammar in an internal format
       
   189         */
       
   190         IMPORT_C void LoadGrammar(const CSDGrammar& aGrammar);
       
   191 
       
   192 		/**
       
   193         * Load the specified grammar into the recognizer.
       
   194         * @since 8.0
       
   195         * @param aLexicon - A reference to a lexicon in an internal format
       
   196         */
       
   197         IMPORT_C void LoadLexicon(const CSDLexicon& aLexicon);
       
   198 
       
   199 		/**
       
   200         * Load the specified Lexicon into the recognizer.
       
   201         * @since 8.0
       
   202         * @param aModels - A reference to a model bank
       
   203         */
       
   204         IMPORT_C void LoadModels(const CSDModelBank& aModels);
       
   205 
       
   206 		/**
       
   207         * Request DevASR to play the contents of its own buffer. The buffer was previously
       
   208 		* allocated by invoking method InitPlay().
       
   209         * @since 8.0
       
   210         */
       
   211         IMPORT_C void Play();
       
   212 
       
   213 		/**
       
   214         * Request to begin recording.
       
   215         * @since 8.0
       
   216         * @param aRecordDuration - Length of time to record, expressed in microseconds
       
   217         */
       
   218         IMPORT_C void Record(TTimeIntervalMicroSeconds32 aRecordDuration);
       
   219 
       
   220 		/**
       
   221         * Use to set the priority of the sound device
       
   222         * @since 8.0
       
   223         * @param aPrioritySettings Priority settings structure
       
   224 
       
   225 		@capability MultimediaDD
       
   226 		            A process requesting or using this method that has MultimediaDD capability will
       
   227 					always have precedence over a process that does not have MultimediaDD.
       
   228         */
       
   229 		IMPORT_C void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
       
   230 
       
   231 		/**
       
   232         * This method is used to start a recognition session with the recognition engine.
       
   233         * @since 8.0
       
   234 		* @param aMode Mode of the recognizer
       
   235 		* @return result code of operation
       
   236         */
       
   237         IMPORT_C TInt StartRecSession(TRecognizerMode aMode);
       
   238 
       
   239 		/**
       
   240         * Request to unload the specified rule in the grammar from recognizer.
       
   241         * @since 8.0
       
   242         * @param aGrammarID - Identifer of the grammar to operate on
       
   243 		* @param aRuleID - Identifier of the rule to remove
       
   244         */
       
   245         IMPORT_C void UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID);
       
   246 
       
   247 		/**
       
   248         * Retreive the raw audio data accumulated during recording.
       
   249         * @since 8.0
       
   250 		* @param aBuffer Reference to a buffer containing the data
       
   251 		* @param aDuration Duration of the utterance
       
   252         */
       
   253         IMPORT_C void GetUtteranceData(TDes8* aBuffer, TTimeIntervalMicroSeconds32& aDuration);
       
   254 
       
   255 
       
   256     private:
       
   257 
       
   258         /**
       
   259         * C++ default constructor.
       
   260         */
       
   261         CDevASR();
       
   262 
       
   263         /**
       
   264         * By default Symbian 2nd phase constructor is private.
       
   265         */
       
   266         void ConstructL(MDevASRObserver& aObserver);
       
   267 
       
   268     private:    // Data
       
   269         // Pointer to algorithm manager
       
   270    		CSRSAlgorithmManager* iSRSAlgorithmManager;
       
   271     };
       
   272 
       
   273 #endif // __DEVASR_H__
       
   274 
       
   275 // End of File