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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
21 #include <mmf/common/speechrecognitiondatadevasr.h>
22 #include <mmf/devasr/devasrcommon.h>
24 // FORWARD DECLARATION
25 class CSRSAlgorithmManager;
26 class TMMFPrioritySettings;
29 * Interface for the DevASR callbacks that are implemented by DevASR observers.
41 * DevASR notifies object implementing this interface whenever a spontaneous or non-spontaneous
42 * event occurs in DevASR.
44 * @param aEvent DevASR event code
45 * @param aError DevASR error code
47 virtual void DevASREvent(TDevASREvent aEvent, TDevASRError aError)=0;
50 * DevASR notifies object implementing this interface when feature vectors are available.
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.
56 virtual void FeatureVectorDataRcvd(const TDesC16& aFV, TInt32 aSNR, TInt32 aPosition)=0;
59 * DevASR calls this method to send a message in response to a custom command.
61 * @param aMsg Buffer containing the message
63 virtual void DevASRMessage(TDesC8& aMsg)=0;
67 * Interface Class for the DevASR API.
73 class CDevASR : public CBase
75 public: // Constructors and destructor
78 * Two-phased constructor.
80 * @param aObserver The observer to call back when events occur
82 * @return pointer to object of type CDevASR
84 IMPORT_C static CDevASR* NewL(MDevASRObserver& aObserver);
87 * Two-phased constructor.
89 * @param aObserver The observer to call back when events occur
91 * @return pointer to object of type CDevASR
93 IMPORT_C static CDevASR* NewLC(MDevASRObserver& aObserver);
98 IMPORT_C virtual ~CDevASR();
100 public: // New functions
103 * Cancels the current or started tasks.
106 IMPORT_C void Cancel();
109 * Use to request a custom interface implementation from the component.
110 * through the DevASR API.
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.
116 IMPORT_C TAny* CustomInterface(TUid aInterfaceId);
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.
123 IMPORT_C void EndRecSession();
127 Retreive the properties of the underlying speech recognition engine.
130 An array of identifiers being querried
131 @param aPropertyValue
132 An array of values corresponding to the querried identifiers
136 IMPORT_C void GetEnginePropertiesL(const RArray<TInt>& aPropertyId, RArray<TInt>& aPropertyValue);
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().
143 * @param aMode - Mode of the recognizer
145 IMPORT_C void InitFrontEnd(TRecognizerMode aMode);
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.
153 * @param aPlayDuration - Specifies the duration of playback in microseconds
154 * @return A reference to the buffer to be filled with source audio data.
156 IMPORT_C TDes8& InitPlayL(TTimeIntervalMicroSeconds32 aPlayDuration);
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().
163 * @param aResult - a reference to an object where the recognition result will be written
165 IMPORT_C void InitRecognizerBE(CSDResultSet& aResult);
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().
172 * @param aModel - Buffer in which the newly created model will be written
174 IMPORT_C void InitTrainBE(CSDModel& aModel);
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.
180 * @param aParameterId - An array of parameter identifiers
181 * @param aParameterValue - An array of parameter values
183 IMPORT_C void LoadEngineParametersL(const RArray<TInt>& aParameterId, const RArray<TInt>& aParameterValue);
186 * Load the specified grammar into the recognizer.
188 * @param aGrammar - A reference to a grammar in an internal format
190 IMPORT_C void LoadGrammar(const CSDGrammar& aGrammar);
193 * Load the specified grammar into the recognizer.
195 * @param aLexicon - A reference to a lexicon in an internal format
197 IMPORT_C void LoadLexicon(const CSDLexicon& aLexicon);
200 * Load the specified Lexicon into the recognizer.
202 * @param aModels - A reference to a model bank
204 IMPORT_C void LoadModels(const CSDModelBank& aModels);
207 * Request DevASR to play the contents of its own buffer. The buffer was previously
208 * allocated by invoking method InitPlay().
211 IMPORT_C void Play();
214 * Request to begin recording.
216 * @param aRecordDuration - Length of time to record, expressed in microseconds
218 IMPORT_C void Record(TTimeIntervalMicroSeconds32 aRecordDuration);
221 * Use to set the priority of the sound device
223 * @param aPrioritySettings Priority settings structure
226 IMPORT_C void SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings);
229 * This method is used to start a recognition session with the recognition engine.
231 * @param aMode Mode of the recognizer
232 * @return result code of operation
234 IMPORT_C TInt StartRecSession(TRecognizerMode aMode);
237 * Request to unload the specified rule in the grammar from recognizer.
239 * @param aGrammarID - Identifer of the grammar to operate on
240 * @param aRuleID - Identifier of the rule to remove
242 IMPORT_C void UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID);
245 * Retreive the raw audio data accumulated during recording.
247 * @param aBuffer Reference to a buffer containing the data
248 * @param aDuration Duration of the utterance
250 IMPORT_C void GetUtteranceData(TDes8* aBuffer, TTimeIntervalMicroSeconds32& aDuration);
256 * C++ default constructor.
261 * By default Symbian 2nd phase constructor is private.
263 void ConstructL(MDevASRObserver& aObserver);
266 // Pointer to algorithm manager
267 CSRSAlgorithmManager* iSRSAlgorithmManager;
270 #endif // __DEVASR_H__