|
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 is the implementation of DevASR. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <nssdevasr.h> |
|
21 #include "devasrsrsalgorithmmanager.h" |
|
22 |
|
23 |
|
24 // ============================ MEMBER FUNCTIONS =============================== |
|
25 |
|
26 |
|
27 // ----------------------------------------------------------------------------- |
|
28 // CDevASR::CDevASR |
|
29 // C++ default constructor can NOT contain any code, that |
|
30 // might leave. |
|
31 // ----------------------------------------------------------------------------- |
|
32 // |
|
33 CDevASR::CDevASR() : iSRSAlgorithmManager( NULL ), |
|
34 iReserved1( NULL ), |
|
35 iReserved2( NULL ) |
|
36 { |
|
37 // Nothing |
|
38 } |
|
39 |
|
40 |
|
41 // ----------------------------------------------------------------------------- |
|
42 // CDevASR::ConstructL |
|
43 // Symbian 2nd phase constructor can leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void CDevASR::ConstructL( MDevASRObserver& aObserver ) |
|
47 { |
|
48 iSRSAlgorithmManager = CSRSAlgorithmManager::NewL( aObserver ); |
|
49 } |
|
50 |
|
51 |
|
52 // ----------------------------------------------------------------------------- |
|
53 // CDevASR::NewL |
|
54 // Two-phased constructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 EXPORT_C CDevASR* CDevASR::NewL( MDevASRObserver& aObserver ) |
|
58 { |
|
59 CDevASR* self = NewLC( aObserver ); |
|
60 CleanupStack::Pop(); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 // ----------------------------------------------------------------------------- |
|
66 // CDevASR::NewLC |
|
67 // Two-phased constructor. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 EXPORT_C CDevASR* CDevASR::NewLC( MDevASRObserver& aObserver ) |
|
71 { |
|
72 CDevASR* self = new ( ELeave ) CDevASR; |
|
73 CleanupStack::PushL( self ); |
|
74 self->ConstructL( aObserver ); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // CDevASR::~CDevASR |
|
81 // The destructor. |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 EXPORT_C CDevASR::~CDevASR() |
|
85 { |
|
86 delete iSRSAlgorithmManager; |
|
87 } |
|
88 |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CDevASR::ActivateGrammarL |
|
92 // Passes the function call to CSRSAlgorithmManager. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C void CDevASR::ActivateGrammarL( TSIGrammarID aGrammarID ) |
|
96 { |
|
97 iSRSAlgorithmManager->ActivateGrammarL( aGrammarID ); |
|
98 } |
|
99 |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CDevASR::AdaptL |
|
103 // Passes the function call to CSRSAlgorithmManager. |
|
104 // ----------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C void CDevASR::AdaptL( const CSIResultSet& aResultSet, TInt aResultIndex ) |
|
107 { |
|
108 // Adaptation |
|
109 iSRSAlgorithmManager->AdaptL( aResultSet, aResultIndex ); |
|
110 } |
|
111 |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CDevASR::Cancel |
|
115 // Cancels the current and any on going requests/tasks. Forwards call to |
|
116 // CSRSAlgorithmManager. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 EXPORT_C void CDevASR::Cancel() |
|
120 { |
|
121 iSRSAlgorithmManager->Cancel(); |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CDevASR::Cancel |
|
127 // Compiles SI grammar. Forwards call to CSRSAlgorithmManager. |
|
128 // ----------------------------------------------------------------------------- |
|
129 // |
|
130 EXPORT_C void CDevASR::CompileGrammarL( CSICompiledGrammar& aGrammar/*, |
|
131 CSIModelBank& aModelBank*/ ) |
|
132 { |
|
133 iSRSAlgorithmManager->CompileGrammarL( aGrammar/*, aModelBank*/ ); |
|
134 } |
|
135 |
|
136 |
|
137 // ----------------------------------------------------------------------------- |
|
138 // CDevASR::ComputeNewGrammarSizeL |
|
139 // Passes the function call to CSRSAlgorithmManager. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 EXPORT_C void CDevASR::ComputeNewGrammarSizeL( const CSIGrammar& aGrammar, |
|
143 const TUint32 aTargetNRuleVariants, |
|
144 const TUint32 aMaxNRuleVariants, |
|
145 const RArray<TUint>& aNewRuleScores, |
|
146 RArray<TUint>& aNewRuleVariants, |
|
147 TUint32& aNPrune ) |
|
148 { |
|
149 iSRSAlgorithmManager->ComputeNewGrammarSizeL( aGrammar, |
|
150 aTargetNRuleVariants, |
|
151 aMaxNRuleVariants, |
|
152 aNewRuleScores, |
|
153 aNewRuleVariants, |
|
154 aNPrune ); |
|
155 } |
|
156 |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // CDevASR::CustomInterface |
|
160 // Send a command to the implementation that the DevASR API doesn't currently |
|
161 // supports. Now returns NULL every time, no custom operations. |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 EXPORT_C TAny* CDevASR::CustomInterface( TUid /*aCustomInterfaceId*/ ) |
|
165 { |
|
166 return NULL; |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CDevASR::DeactivateGrammarL |
|
172 // Passes the function call to CSRSAlgorithmManager. |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 EXPORT_C void CDevASR::DeactivateGrammarL( TSIGrammarID aGrammarID ) |
|
176 { |
|
177 iSRSAlgorithmManager->DeactivateGrammarL( aGrammarID ); |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CDevASR::EndRecord |
|
183 // Requests to end recording and a result will be resolved. Passes the function |
|
184 // call to CSRSAlgorithmManager. |
|
185 // ----------------------------------------------------------------------------- |
|
186 // |
|
187 EXPORT_C void CDevASR::EndRecord() |
|
188 { |
|
189 iSRSAlgorithmManager->StopRecognition(); |
|
190 } |
|
191 |
|
192 |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CDevASR::EndRecSession |
|
195 // Signal the end of a recognition session. Passes the function call to |
|
196 // CSRSAlgorithmManager. |
|
197 // ----------------------------------------------------------------------------- |
|
198 // |
|
199 EXPORT_C void CDevASR::EndRecSession() |
|
200 { |
|
201 iSRSAlgorithmManager->EndRecSession(); |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CDevASR::GetEnginePropertiesL |
|
207 // Retreive the properties of the underlying speech recognition engine. |
|
208 // An array of values corresponding to the querried identifiers will be populated. |
|
209 // The function may leave with KErrArgument. Passes the function call to |
|
210 // CSRSAlgorithmManager. |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 EXPORT_C void CDevASR::GetEnginePropertiesL( const RArray<TInt>& aPropertyId, |
|
214 RArray<TInt>& aPropertyValue) |
|
215 { |
|
216 iSRSAlgorithmManager->GetEnginePropertiesL( aPropertyId, aPropertyValue ); |
|
217 } |
|
218 |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CDevASR::GetUtteranceData |
|
222 // Get the recorded audio data accumulated during training. Passes the function |
|
223 // call to CSRSAlgorithmManager. |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 EXPORT_C void CDevASR::GetUtteranceData( TDes8* aBuffer, |
|
227 TTimeIntervalMicroSeconds32& aDuration ) |
|
228 { |
|
229 iSRSAlgorithmManager->GetUtteranceData( aBuffer, aDuration ); |
|
230 } |
|
231 |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CDevASR::InitFrontEnd |
|
235 // Forwards call to CSRSAlgorithmManager. |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 EXPORT_C void CDevASR::InitFrontEnd( TRecognizerMode aMode ) |
|
239 { |
|
240 iSRSAlgorithmManager->InitFrontEnd( aMode ); |
|
241 } |
|
242 |
|
243 |
|
244 // ----------------------------------------------------------------------------- |
|
245 // CDevASR::InitRecognizerBE |
|
246 // Initializes the recognition back-end. The module responsible for recognition |
|
247 // function is started as a result. Forwards call to CSRSAlgorithmManager. |
|
248 // ----------------------------------------------------------------------------- |
|
249 // |
|
250 EXPORT_C void CDevASR::InitRecognizerBE( CSIResultSet& aResult ) |
|
251 { |
|
252 iSRSAlgorithmManager->InitRecognizerBE( aResult ); |
|
253 } |
|
254 |
|
255 |
|
256 // ----------------------------------------------------------------------------- |
|
257 // CDevASR::LoadEngineParametersL |
|
258 // Load the specified recognizer parameter(s). |
|
259 // Forwards call to CSRSAlgorithmManager. |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 EXPORT_C void CDevASR::LoadEngineParametersL( const RArray<TInt>& aParameterId, |
|
263 const RArray<TInt>& aParameterValue ) |
|
264 { |
|
265 iSRSAlgorithmManager->LoadEnginePropertiesL( aParameterId, aParameterValue ); |
|
266 } |
|
267 |
|
268 |
|
269 // ----------------------------------------------------------------------------- |
|
270 // CDevASR::LoadGrammar |
|
271 // Load the specified SI grammar into the recognizer. |
|
272 // Forwards call to CSRSAlgorithmManager. |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C void CDevASR::LoadGrammar( const CSIGrammar& aGrammar ) |
|
276 { |
|
277 TRAPD( error, iSRSAlgorithmManager->LoadGrammarL( aGrammar ) ); |
|
278 // No way to process or send the error upwards. |
|
279 error = error; |
|
280 } |
|
281 |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CDevASR::LoadGrammar |
|
285 // Load the specified compiled SI grammar into the recognizer. |
|
286 // Forwards call to CSRSAlgorithmManager. |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 EXPORT_C void CDevASR::LoadGrammar( const CSICompiledGrammar& aGrammar ) |
|
290 { |
|
291 TRAPD( error, iSRSAlgorithmManager->LoadGrammarL( aGrammar ) ); |
|
292 // No way to process or send the error upwards. |
|
293 error = error; |
|
294 } |
|
295 |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CDevASR::UnloadGrammar |
|
299 // Unloads the specified SI grammar from the recognizer. |
|
300 // Forwards call to CSRSAlgorithmManager. |
|
301 // ----------------------------------------------------------------------------- |
|
302 // |
|
303 EXPORT_C void CDevASR::UnloadGrammar( const CSIGrammar& aGrammar ) |
|
304 { |
|
305 TRAPD( error, iSRSAlgorithmManager->UnloadGrammarL( aGrammar ) ); |
|
306 // No way to process or send the error upwards. |
|
307 error = error; |
|
308 } |
|
309 |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CDevASR::LoadGrammar |
|
313 // Unloads the specified compiled SI grammar from the recognizer. |
|
314 // Forwards call to CSRSAlgorithmManager. |
|
315 // ----------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C void CDevASR::UnloadGrammar( const CSICompiledGrammar& aGrammar ) |
|
318 { |
|
319 TRAPD( error, iSRSAlgorithmManager->UnloadGrammarL( aGrammar ) ); |
|
320 // No way to process or send the error upwards. |
|
321 error = error; |
|
322 } |
|
323 |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // CDevASR::LoadLexicon |
|
327 // Load the specified SI lexicion into the recognizer. |
|
328 // Forwards call to CSRSAlgorithmManager. |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 EXPORT_C void CDevASR::LoadLexicon( const CSILexicon& aLexicon ) |
|
332 { |
|
333 TRAPD( error, iSRSAlgorithmManager->LoadLexiconL( aLexicon ) ); |
|
334 // No way to process or send the error upwards. |
|
335 error = error; |
|
336 } |
|
337 |
|
338 |
|
339 // ----------------------------------------------------------------------------- |
|
340 // CDevASR::LoadModels |
|
341 // Load the specified SI models into the recognizer. |
|
342 // Forwards call to CSRSAlgorithmManager. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 EXPORT_C void CDevASR::LoadModels( const CSIModelBank& aModels ) |
|
346 { |
|
347 TRAPD( error, iSRSAlgorithmManager->LoadModelsL( aModels ) ); |
|
348 // No way to process or send the error upwards. |
|
349 error = error; |
|
350 } |
|
351 |
|
352 |
|
353 // ----------------------------------------------------------------------------- |
|
354 // CDevASR::PruneGrammar |
|
355 // Passes the function call to CSRSAlgorithmManager. |
|
356 // ----------------------------------------------------------------------------- |
|
357 // |
|
358 EXPORT_C TBool CDevASR::PruneGrammar( const CSIGrammar& aGrammar, |
|
359 const TUint32 aMinNumber, |
|
360 RArray<TSIRuleVariantInfo>& aPrunedRuleVariants ) |
|
361 { |
|
362 return iSRSAlgorithmManager->PruneGrammar( aGrammar, |
|
363 aMinNumber, |
|
364 aPrunedRuleVariants ); |
|
365 } |
|
366 |
|
367 |
|
368 // ----------------------------------------------------------------------------- |
|
369 // CDevASR::Record |
|
370 // Request to begin recording. Passes the function call to CVMAlgorithmManager. |
|
371 // ----------------------------------------------------------------------------- |
|
372 // |
|
373 EXPORT_C void CDevASR::Record( TTimeIntervalMicroSeconds32 aRecordDuration ) |
|
374 { |
|
375 iSRSAlgorithmManager->StartRecognition( aRecordDuration ); |
|
376 } |
|
377 |
|
378 |
|
379 // ----------------------------------------------------------------------------- |
|
380 // CDevASR::PreStartSamplingL |
|
381 // Begins sampling before Record() call |
|
382 // ----------------------------------------------------------------------------- |
|
383 // |
|
384 EXPORT_C void CDevASR::PreStartSamplingL() |
|
385 { |
|
386 iSRSAlgorithmManager->PreStartSamplingL(); |
|
387 } |
|
388 |
|
389 |
|
390 // ----------------------------------------------------------------------------- |
|
391 // CDevASR::SendSpeechData |
|
392 // Passes the function call to CSRSAlgorithmManager. |
|
393 // ----------------------------------------------------------------------------- |
|
394 // |
|
395 EXPORT_C void CDevASR::SendSpeechData( TPtrC8& aBuffer, TBool aEnd ) |
|
396 { |
|
397 iSRSAlgorithmManager->SendSpeechData( aBuffer, aEnd ); |
|
398 } |
|
399 |
|
400 |
|
401 // ----------------------------------------------------------------------------- |
|
402 // CDevASR::SetPrioritySettings |
|
403 // Set the priority of the sound device |
|
404 // Passes the function call to CSRSAlgorithmManager. |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 EXPORT_C void CDevASR::SetPrioritySettings( const TMMFPrioritySettings& aPrioritySettings ) |
|
408 { |
|
409 iSRSAlgorithmManager->SetPrioritySettings( aPrioritySettings ); |
|
410 } |
|
411 |
|
412 |
|
413 // ----------------------------------------------------------------------------- |
|
414 // CDevASR::StartRecSession |
|
415 // Signal the start of a recognition session. |
|
416 // Passes the function call to CSRSAlgorithmManager. |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C TInt CDevASR::StartRecSession( TRecognizerMode aMode ) |
|
420 { |
|
421 return iSRSAlgorithmManager->StartRecSession( aMode ); |
|
422 } |
|
423 |
|
424 |
|
425 // ----------------------------------------------------------------------------- |
|
426 // CDevASR::StartTrainFromText |
|
427 // Passes the function call to CSRSAlgorithmManager. |
|
428 // ----------------------------------------------------------------------------- |
|
429 // |
|
430 EXPORT_C void CDevASR::StartTrainingFromTextL( CSITtpWordList& aWordList, |
|
431 const RArray<TLanguage>& aDefaultLanguage, |
|
432 const RArray<TUint32>& aMaxNPronunsForWord ) |
|
433 |
|
434 { |
|
435 iSRSAlgorithmManager->StartTrainingFromTextL( aWordList, aDefaultLanguage, |
|
436 aMaxNPronunsForWord ); |
|
437 } |
|
438 |
|
439 |
|
440 // ----------------------------------------------------------------------------- |
|
441 // CDevASR::UnloadRule |
|
442 // Unload the specified rule from the grammar. |
|
443 // Passes the function call to CSRSAlgorithmManager. |
|
444 // ----------------------------------------------------------------------------- |
|
445 // |
|
446 EXPORT_C void CDevASR::UnloadRule( TSIGrammarID aGrammarID, |
|
447 TSIRuleID aRuleID ) |
|
448 { |
|
449 iSRSAlgorithmManager->UnloadRule( aGrammarID, aRuleID ); |
|
450 } |
|
451 |
|
452 |
|
453 // ----------------------------------------------------------------------------- |
|
454 // CDevASR::IsGrammarLoaded |
|
455 // Passes the function call to CSRSAlgorithmManager. |
|
456 // ----------------------------------------------------------------------------- |
|
457 // |
|
458 EXPORT_C TBool CDevASR::IsGrammarLoaded( TSIGrammarID aGrammarID ) |
|
459 { |
|
460 return iSRSAlgorithmManager->IsGrammarLoaded( aGrammarID ); |
|
461 } |
|
462 |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CDevASR::IsGrammarActive |
|
466 // Passes the function call to CSRSAlgorithmManager. |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 EXPORT_C TBool CDevASR::IsGrammarActive( TSIGrammarID aGrammarID ) |
|
470 { |
|
471 return iSRSAlgorithmManager->IsGrammarActive( aGrammarID ); |
|
472 } |
|
473 |
|
474 // End of File |