williamr@2: // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: #ifndef __DEVASR_H__ williamr@2: #define __DEVASR_H__ williamr@2: williamr@2: // INCLUDES williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: // FORWARD DECLARATION williamr@2: class CSRSAlgorithmManager; williamr@2: class TMMFPrioritySettings; williamr@2: williamr@2: /** williamr@2: * Interface for the DevASR callbacks that are implemented by DevASR observers. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since 8.0 williamr@2: */ williamr@2: williamr@2: class MDevASRObserver williamr@2: { williamr@2: public: williamr@2: williamr@2: /** williamr@2: * DevASR notifies object implementing this interface whenever a spontaneous or non-spontaneous williamr@2: * event occurs in DevASR. williamr@2: * @since 8.0 williamr@2: * @param aEvent DevASR event code williamr@2: * @param aError DevASR error code williamr@2: */ williamr@2: virtual void DevASREvent(TDevASREvent aEvent, TDevASRError aError)=0; williamr@2: williamr@2: /** williamr@2: * DevASR notifies object implementing this interface when feature vectors are available. williamr@2: * @since 8.0 williamr@2: * @param aFV Buffer containing the feature vector data williamr@2: * @param aSNR Signal-to-noise ratio williamr@2: * @param aPosition Indicates whether the feature vector is the first, middle, or end. williamr@2: */ williamr@2: virtual void FeatureVectorDataRcvd(const TDesC16& aFV, TInt32 aSNR, TInt32 aPosition)=0; williamr@2: williamr@2: /** williamr@2: * DevASR calls this method to send a message in response to a custom command. williamr@2: * @since 8.0 williamr@2: * @param aMsg Buffer containing the message williamr@2: */ williamr@2: virtual void DevASRMessage(TDesC8& aMsg)=0; williamr@2: }; williamr@2: williamr@2: /** williamr@2: * Interface Class for the DevASR API. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since 8.0 williamr@2: */ williamr@2: class CDevASR : public CBase williamr@2: { williamr@2: public: // Constructors and destructor williamr@2: williamr@2: /** williamr@2: * Two-phased constructor. williamr@2: * williamr@2: * @param aObserver The observer to call back when events occur williamr@2: * williamr@2: * @return pointer to object of type CDevASR williamr@2: */ williamr@2: IMPORT_C static CDevASR* NewL(MDevASRObserver& aObserver); williamr@2: williamr@2: /** williamr@2: * Two-phased constructor. williamr@2: * williamr@2: * @param aObserver The observer to call back when events occur williamr@2: * williamr@2: * @return pointer to object of type CDevASR williamr@2: */ williamr@2: IMPORT_C static CDevASR* NewLC(MDevASRObserver& aObserver); williamr@2: williamr@2: /** williamr@2: * Destructor. williamr@2: */ williamr@2: IMPORT_C virtual ~CDevASR(); williamr@2: williamr@2: public: // New functions williamr@2: williamr@2: /** williamr@2: * Cancels the current or started tasks. williamr@2: * @since 8.0 williamr@2: */ williamr@2: IMPORT_C void Cancel(); williamr@2: williamr@2: /** williamr@2: * Use to request a custom interface implementation from the component. williamr@2: * through the DevASR API. williamr@2: * @since 8.0 williamr@2: * @param aInterfaceId - Interface UID, defined with the custom interface. williamr@2: * @return a pointer to the interface implementation, or NULL if the requested interface is williamr@2: * not implemented. The return value must be cast to the correct type by the user. williamr@2: */ williamr@2: IMPORT_C TAny* CustomInterface(TUid aInterfaceId); williamr@2: williamr@2: /** williamr@2: * This method is used to indicate the end of a recognition session. All loaded grammars, williamr@2: * lexicon, and models become invalid after this call. williamr@2: * @since 8.0 williamr@2: */ williamr@2: IMPORT_C void EndRecSession(); williamr@2: williamr@2: williamr@2: /** williamr@2: Retreive the properties of the underlying speech recognition engine. williamr@2: williamr@2: @param aPropertyId williamr@2: An array of identifiers being querried williamr@2: @param aPropertyValue williamr@2: An array of values corresponding to the querried identifiers williamr@2: williamr@2: @since 8.0 williamr@2: */ williamr@2: IMPORT_C void GetEnginePropertiesL(const RArray& aPropertyId, RArray& aPropertyValue); williamr@2: williamr@2: /** williamr@2: * Initializes the front-end module in the speech recognition engine. williamr@2: * The frontend module used during training/recognition functions is started williamr@2: * as a result. This method is intended to be used in conjunction with InitTrainBE(). williamr@2: * @since 8.0 williamr@2: * @param aMode - Mode of the recognizer williamr@2: */ williamr@2: IMPORT_C void InitFrontEnd(TRecognizerMode aMode); williamr@2: williamr@2: /** williamr@2: * Perform any necessary initialization or allocation of the audio resource williamr@2: * for playing a voice sample. A buffer to hold audio data to play is allocated. williamr@2: * If allocation fails, this method will leave. Client is responsible for filling williamr@2: * the buffer with their audio data and invoke Play() on DevASR. williamr@2: * @since 8.0 williamr@2: * @param aPlayDuration - Specifies the duration of playback in microseconds williamr@2: * @return A reference to the buffer to be filled with source audio data. williamr@2: */ williamr@2: IMPORT_C TDes8& InitPlayL(TTimeIntervalMicroSeconds32 aPlayDuration); williamr@2: williamr@2: /** williamr@2: * Initialize the recognition engine back-end. The module responsible for recognition williamr@2: * function is started as a result. This method must be used before any recognition williamr@2: * operations and intended to be used in conjunction with InitFrontEnd(). williamr@2: * @since 8.0 williamr@2: * @param aResult - a reference to an object where the recognition result will be written williamr@2: */ williamr@2: IMPORT_C void InitRecognizerBE(CSDResultSet& aResult); williamr@2: williamr@2: /** williamr@2: * Initializes the back-end module in the speech recognition engine. williamr@2: * The back-end module responsible for training functions is started as a result. williamr@2: * This method is intended to be used in conjunction with InitFrontEnd(). williamr@2: * @since 8.0 williamr@2: * @param aModel - Buffer in which the newly created model will be written williamr@2: */ williamr@2: IMPORT_C void InitTrainBE(CSDModel& aModel); williamr@2: williamr@2: /** williamr@2: * Load the specified recognizer parameter(s). These parameters are used to alter the williamr@2: * recognizer's default parameters. The parameters are specified as attribute-value pairs. williamr@2: * @since 8.0 williamr@2: * @param aParameterId - An array of parameter identifiers williamr@2: * @param aParameterValue - An array of parameter values williamr@2: */ williamr@2: IMPORT_C void LoadEngineParametersL(const RArray& aParameterId, const RArray& aParameterValue); williamr@2: williamr@2: /** williamr@2: * Load the specified grammar into the recognizer. williamr@2: * @since 8.0 williamr@2: * @param aGrammar - A reference to a grammar in an internal format williamr@2: */ williamr@2: IMPORT_C void LoadGrammar(const CSDGrammar& aGrammar); williamr@2: williamr@2: /** williamr@2: * Load the specified grammar into the recognizer. williamr@2: * @since 8.0 williamr@2: * @param aLexicon - A reference to a lexicon in an internal format williamr@2: */ williamr@2: IMPORT_C void LoadLexicon(const CSDLexicon& aLexicon); williamr@2: williamr@2: /** williamr@2: * Load the specified Lexicon into the recognizer. williamr@2: * @since 8.0 williamr@2: * @param aModels - A reference to a model bank williamr@2: */ williamr@2: IMPORT_C void LoadModels(const CSDModelBank& aModels); williamr@2: williamr@2: /** williamr@2: * Request DevASR to play the contents of its own buffer. The buffer was previously williamr@2: * allocated by invoking method InitPlay(). williamr@2: * @since 8.0 williamr@2: */ williamr@2: IMPORT_C void Play(); williamr@2: williamr@2: /** williamr@2: * Request to begin recording. williamr@2: * @since 8.0 williamr@2: * @param aRecordDuration - Length of time to record, expressed in microseconds williamr@2: */ williamr@2: IMPORT_C void Record(TTimeIntervalMicroSeconds32 aRecordDuration); williamr@2: williamr@2: /** williamr@2: * Use to set the priority of the sound device williamr@2: * @since 8.0 williamr@2: * @param aPrioritySettings Priority settings structure williamr@2: williamr@2: */ williamr@2: IMPORT_C void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings); williamr@2: williamr@2: /** williamr@2: * This method is used to start a recognition session with the recognition engine. williamr@2: * @since 8.0 williamr@2: * @param aMode Mode of the recognizer williamr@2: * @return result code of operation williamr@2: */ williamr@2: IMPORT_C TInt StartRecSession(TRecognizerMode aMode); williamr@2: williamr@2: /** williamr@2: * Request to unload the specified rule in the grammar from recognizer. williamr@2: * @since 8.0 williamr@2: * @param aGrammarID - Identifer of the grammar to operate on williamr@2: * @param aRuleID - Identifier of the rule to remove williamr@2: */ williamr@2: IMPORT_C void UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID); williamr@2: williamr@2: /** williamr@2: * Retreive the raw audio data accumulated during recording. williamr@2: * @since 8.0 williamr@2: * @param aBuffer Reference to a buffer containing the data williamr@2: * @param aDuration Duration of the utterance williamr@2: */ williamr@2: IMPORT_C void GetUtteranceData(TDes8* aBuffer, TTimeIntervalMicroSeconds32& aDuration); williamr@2: williamr@2: williamr@2: private: williamr@2: williamr@2: /** williamr@2: * C++ default constructor. williamr@2: */ williamr@2: CDevASR(); williamr@2: williamr@2: /** williamr@2: * By default Symbian 2nd phase constructor is private. williamr@2: */ williamr@2: void ConstructL(MDevASRObserver& aObserver); williamr@2: williamr@2: private: // Data williamr@2: // Pointer to algorithm manager williamr@2: CSRSAlgorithmManager* iSRSAlgorithmManager; williamr@2: }; williamr@2: williamr@2: #endif // __DEVASR_H__ williamr@2: williamr@2: // End of File