sl@0
|
1 |
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// SpeechRecognitionUtility.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <e32base.h>
|
sl@0
|
19 |
#include <mmf/common/mmfcontroller.h>
|
sl@0
|
20 |
#include <mmf/common/speechrecognitioncustomcommands.h>
|
sl@0
|
21 |
#include <mmf/common/speechrecognitiondatacommon.h>
|
sl@0
|
22 |
|
sl@0
|
23 |
#include <speechrecognitionutility.h>
|
sl@0
|
24 |
#include "SpeechRecognitionUtilityBody.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
//_LIT(KMMFSpeechRecognitionUtilityPanic,"Speech Recognition Utility Bad State");
|
sl@0
|
27 |
enum ASRPanics
|
sl@0
|
28 |
{
|
sl@0
|
29 |
KMMFSpeechRecognitionUtilityPanicBadState,
|
sl@0
|
30 |
KMMFSpeechRecognitionUtilityPanicUnrecognisedEvent
|
sl@0
|
31 |
};
|
sl@0
|
32 |
|
sl@0
|
33 |
CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewL( TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
|
sl@0
|
34 |
{
|
sl@0
|
35 |
CSpeechRecognitionUtility::CBody* self = CSpeechRecognitionUtility::CBody::NewLC(aClientUid, aSpeechRecognitionUtilityObserver);
|
sl@0
|
36 |
CleanupStack::Pop(self);
|
sl@0
|
37 |
return self;
|
sl@0
|
38 |
}
|
sl@0
|
39 |
|
sl@0
|
40 |
CSpeechRecognitionUtility::CBody* CSpeechRecognitionUtility::CBody::NewLC(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
|
sl@0
|
41 |
{
|
sl@0
|
42 |
CSpeechRecognitionUtility::CBody* self = new(ELeave) CSpeechRecognitionUtility::CBody(aClientUid, aSpeechRecognitionUtilityObserver);
|
sl@0
|
43 |
CleanupStack::PushL(self);
|
sl@0
|
44 |
self->ConstructL();
|
sl@0
|
45 |
return self;
|
sl@0
|
46 |
}
|
sl@0
|
47 |
|
sl@0
|
48 |
void CSpeechRecognitionUtility::CBody::ConstructL()
|
sl@0
|
49 |
{
|
sl@0
|
50 |
iAudioPriority = EMdaPriorityNormal;
|
sl@0
|
51 |
iTrainPreference = EMdaPriorityPreferenceNone;
|
sl@0
|
52 |
iRecognitionPreference = EMdaPriorityPreferenceNone;
|
sl@0
|
53 |
iPlaybackPreference = EMdaPriorityPreferenceNone;
|
sl@0
|
54 |
|
sl@0
|
55 |
iPrioritySettings.iPriority = iAudioPriority;
|
sl@0
|
56 |
iPrioritySettings.iPref = iTrainPreference;
|
sl@0
|
57 |
|
sl@0
|
58 |
iControllerEventMonitor = CMMFControllerEventMonitor::NewL(*this, iMMFController);
|
sl@0
|
59 |
|
sl@0
|
60 |
RMMFControllerImplInfoArray controllers;
|
sl@0
|
61 |
CleanupResetAndDestroyPushL(controllers);
|
sl@0
|
62 |
|
sl@0
|
63 |
CMMFControllerPluginSelectionParameters* cSelect = CMMFControllerPluginSelectionParameters::NewLC();
|
sl@0
|
64 |
|
sl@0
|
65 |
// Select the media IDs to allow
|
sl@0
|
66 |
RArray<TUid> mediaIds;
|
sl@0
|
67 |
CleanupClosePushL(mediaIds);
|
sl@0
|
68 |
User::LeaveIfError(mediaIds.Append(KUidMediaTypeASR));
|
sl@0
|
69 |
cSelect->SetMediaIdsL(mediaIds,CMMFPluginSelectionParameters::EAllowOnlySuppliedMediaIds);
|
sl@0
|
70 |
CleanupStack::PopAndDestroy(&mediaIds);
|
sl@0
|
71 |
|
sl@0
|
72 |
cSelect->ListImplementationsL(controllers);
|
sl@0
|
73 |
|
sl@0
|
74 |
//[ Open and configure a controller]
|
sl@0
|
75 |
iControllerEventMonitor->Cancel();
|
sl@0
|
76 |
iMMFController.Close();
|
sl@0
|
77 |
//[check controller array is not empty]
|
sl@0
|
78 |
if( ! controllers.Count() )
|
sl@0
|
79 |
User::Leave( KErrNotFound );
|
sl@0
|
80 |
|
sl@0
|
81 |
//[ simply open the first controller in the array ]
|
sl@0
|
82 |
User::LeaveIfError( iMMFController.Open(controllers[0]->Uid(), iPrioritySettings));
|
sl@0
|
83 |
iControllerEventMonitor->Start();
|
sl@0
|
84 |
|
sl@0
|
85 |
iSrCustomCommands.SetClientUid(iClientUid);
|
sl@0
|
86 |
|
sl@0
|
87 |
CleanupStack::PopAndDestroy(2, &controllers);//controllers, cSelect
|
sl@0
|
88 |
|
sl@0
|
89 |
}
|
sl@0
|
90 |
|
sl@0
|
91 |
CSpeechRecognitionUtility::CBody::CBody(TUid aClientUid, MSpeechRecognitionUtilityObserver& aSpeechRecognitionUtilityObserver)
|
sl@0
|
92 |
: iSrCustomCommands(iMMFController),
|
sl@0
|
93 |
iSpeechRecognitionUtilityObserver(&aSpeechRecognitionUtilityObserver),
|
sl@0
|
94 |
iClientUid(aClientUid)
|
sl@0
|
95 |
{
|
sl@0
|
96 |
}
|
sl@0
|
97 |
|
sl@0
|
98 |
CSpeechRecognitionUtility::CBody::~CBody()
|
sl@0
|
99 |
{
|
sl@0
|
100 |
if (iControllerEventMonitor)
|
sl@0
|
101 |
{
|
sl@0
|
102 |
iControllerEventMonitor->Cancel();
|
sl@0
|
103 |
delete iControllerEventMonitor;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
iMMFController.Close();
|
sl@0
|
106 |
}
|
sl@0
|
107 |
|
sl@0
|
108 |
TInt CSpeechRecognitionUtility::CBody::GetEngineProperties(const RArray<TInt>& aPropertyIDs, RArray<TInt>& aPropertyValues)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
aPropertyValues.Reset();
|
sl@0
|
111 |
return iSrCustomCommands.GetEngineProperties(aPropertyIDs, aPropertyValues);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
|
sl@0
|
114 |
TInt CSpeechRecognitionUtility::CBody::AddPronunciation(TLexiconID aLexiconID, TModelBankID aModelBankID, TModelID aModelID, TPronunciationID& aPronunciationID)
|
sl@0
|
115 |
{
|
sl@0
|
116 |
if (iAsyncCallBusy)
|
sl@0
|
117 |
return KErrInUse;
|
sl@0
|
118 |
|
sl@0
|
119 |
TInt err = iSrCustomCommands.AddPronunciation(aLexiconID, aModelBankID, aModelID, aPronunciationID);
|
sl@0
|
120 |
|
sl@0
|
121 |
if (err == KErrNone)
|
sl@0
|
122 |
iAsyncCallBusy=ETrue;
|
sl@0
|
123 |
return err;
|
sl@0
|
124 |
}
|
sl@0
|
125 |
|
sl@0
|
126 |
TInt CSpeechRecognitionUtility::CBody::AddRule(TGrammarID aGrammarID, TLexiconID aLexiconID, TPronunciationID aPronunciationID, TRuleID& aRuleID)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
if (iAsyncCallBusy)
|
sl@0
|
129 |
return KErrInUse;
|
sl@0
|
130 |
|
sl@0
|
131 |
TInt err = iSrCustomCommands.AddRule(aGrammarID, aLexiconID, aPronunciationID, aRuleID);
|
sl@0
|
132 |
|
sl@0
|
133 |
if (err == KErrNone)
|
sl@0
|
134 |
iAsyncCallBusy=ETrue;
|
sl@0
|
135 |
return err;
|
sl@0
|
136 |
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
void CSpeechRecognitionUtility::CBody::Cancel()
|
sl@0
|
140 |
{
|
sl@0
|
141 |
iSrCustomCommands.Cancel();
|
sl@0
|
142 |
// Now cancel has been called, so remove any pointers storing references to arrays to be filled
|
sl@0
|
143 |
// These arrays are not owned by this object, so they must not be destroyed
|
sl@0
|
144 |
iPronunciationIDs = NULL;
|
sl@0
|
145 |
iRuleIDs = NULL;
|
sl@0
|
146 |
iModelIDs = NULL;
|
sl@0
|
147 |
iAsyncCallBusy = EFalse;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
TInt CSpeechRecognitionUtility::CBody::CommitChanges()
|
sl@0
|
151 |
{
|
sl@0
|
152 |
if (iAsyncCallBusy)
|
sl@0
|
153 |
return KErrInUse;
|
sl@0
|
154 |
|
sl@0
|
155 |
return iSrCustomCommands.CommitChanges();
|
sl@0
|
156 |
}
|
sl@0
|
157 |
|
sl@0
|
158 |
TInt CSpeechRecognitionUtility::CBody::CreateGrammar(TGrammarID& aGrammarID)
|
sl@0
|
159 |
{
|
sl@0
|
160 |
if (iAsyncCallBusy)
|
sl@0
|
161 |
return KErrInUse;
|
sl@0
|
162 |
TInt err = iSrCustomCommands.CreateGrammar(aGrammarID);
|
sl@0
|
163 |
|
sl@0
|
164 |
if (err == KErrNone)
|
sl@0
|
165 |
iAsyncCallBusy=ETrue;
|
sl@0
|
166 |
return err;
|
sl@0
|
167 |
}
|
sl@0
|
168 |
|
sl@0
|
169 |
TInt CSpeechRecognitionUtility::CBody::CreateLexicon(TLexiconID& aLexiconID)
|
sl@0
|
170 |
{
|
sl@0
|
171 |
if (iAsyncCallBusy)
|
sl@0
|
172 |
return KErrInUse;
|
sl@0
|
173 |
TInt err = iSrCustomCommands.CreateLexicon(aLexiconID);
|
sl@0
|
174 |
|
sl@0
|
175 |
if (err == KErrNone)
|
sl@0
|
176 |
iAsyncCallBusy=ETrue;
|
sl@0
|
177 |
return err;
|
sl@0
|
178 |
}
|
sl@0
|
179 |
|
sl@0
|
180 |
TInt CSpeechRecognitionUtility::CBody::LoadModels(TModelBankID aModelBankID)
|
sl@0
|
181 |
{
|
sl@0
|
182 |
if (iAsyncCallBusy)
|
sl@0
|
183 |
return KErrInUse;
|
sl@0
|
184 |
|
sl@0
|
185 |
TInt err = iSrCustomCommands.LoadModels(aModelBankID);
|
sl@0
|
186 |
|
sl@0
|
187 |
if (err == KErrNone)
|
sl@0
|
188 |
iAsyncCallBusy=ETrue;
|
sl@0
|
189 |
|
sl@0
|
190 |
return err;
|
sl@0
|
191 |
}
|
sl@0
|
192 |
|
sl@0
|
193 |
TInt CSpeechRecognitionUtility::CBody::LoadGrammar(TGrammarID aGrammarID)
|
sl@0
|
194 |
{
|
sl@0
|
195 |
if (iAsyncCallBusy)
|
sl@0
|
196 |
return KErrInUse;
|
sl@0
|
197 |
|
sl@0
|
198 |
TInt err = iSrCustomCommands.LoadGrammar(aGrammarID);
|
sl@0
|
199 |
|
sl@0
|
200 |
if (err == KErrNone)
|
sl@0
|
201 |
iAsyncCallBusy=ETrue;
|
sl@0
|
202 |
|
sl@0
|
203 |
return err;
|
sl@0
|
204 |
|
sl@0
|
205 |
}
|
sl@0
|
206 |
|
sl@0
|
207 |
TInt CSpeechRecognitionUtility::CBody::LoadLexicon(TLexiconID aLexiconID)
|
sl@0
|
208 |
{
|
sl@0
|
209 |
if (iAsyncCallBusy)
|
sl@0
|
210 |
return KErrInUse;
|
sl@0
|
211 |
|
sl@0
|
212 |
TInt err = iSrCustomCommands.LoadLexicon(aLexiconID);
|
sl@0
|
213 |
|
sl@0
|
214 |
if (err == KErrNone)
|
sl@0
|
215 |
iAsyncCallBusy=ETrue;
|
sl@0
|
216 |
|
sl@0
|
217 |
return err;
|
sl@0
|
218 |
|
sl@0
|
219 |
}
|
sl@0
|
220 |
|
sl@0
|
221 |
|
sl@0
|
222 |
TInt CSpeechRecognitionUtility::CBody::GetUtteranceDuration(TModelBankID aModelBankID, TModelID aModelID, TTimeIntervalMicroSeconds32& aDuration)
|
sl@0
|
223 |
{
|
sl@0
|
224 |
if (iAsyncCallBusy)
|
sl@0
|
225 |
return KErrInUse;
|
sl@0
|
226 |
|
sl@0
|
227 |
TInt err = iSrCustomCommands.GetUtteranceDuration(aModelBankID, aModelID, aDuration);
|
sl@0
|
228 |
|
sl@0
|
229 |
if (err == KErrNone)
|
sl@0
|
230 |
iAsyncCallBusy=ETrue;
|
sl@0
|
231 |
|
sl@0
|
232 |
return err;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
|
sl@0
|
236 |
TInt CSpeechRecognitionUtility::CBody::PlayUtterance(TModelBankID aModelBankID, TModelID aModelID)
|
sl@0
|
237 |
{
|
sl@0
|
238 |
if (iAsyncCallBusy)
|
sl@0
|
239 |
return KErrInUse;
|
sl@0
|
240 |
|
sl@0
|
241 |
iPrioritySettings.iPriority = iAudioPriority;
|
sl@0
|
242 |
iPrioritySettings.iPref = iPlaybackPreference;
|
sl@0
|
243 |
|
sl@0
|
244 |
TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
|
sl@0
|
245 |
|
sl@0
|
246 |
if (err == KErrNone)
|
sl@0
|
247 |
err = iSrCustomCommands.PlayUtterance(aModelBankID, aModelID);
|
sl@0
|
248 |
|
sl@0
|
249 |
if (err == KErrNone)
|
sl@0
|
250 |
iAsyncCallBusy=ETrue;
|
sl@0
|
251 |
|
sl@0
|
252 |
return err;
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
TInt CSpeechRecognitionUtility::CBody::GetModelCount(TModelBankID aModelBankID, TInt& aModelCount)
|
sl@0
|
256 |
{
|
sl@0
|
257 |
if (iAsyncCallBusy)
|
sl@0
|
258 |
return KErrInUse;
|
sl@0
|
259 |
|
sl@0
|
260 |
TInt err = iSrCustomCommands.GetModelCount(aModelBankID, aModelCount);
|
sl@0
|
261 |
|
sl@0
|
262 |
if (err == KErrNone)
|
sl@0
|
263 |
iAsyncCallBusy=ETrue;
|
sl@0
|
264 |
|
sl@0
|
265 |
return err;
|
sl@0
|
266 |
}
|
sl@0
|
267 |
|
sl@0
|
268 |
TInt CSpeechRecognitionUtility::CBody::StartRecSession(TRecognitionMode aMode)
|
sl@0
|
269 |
{
|
sl@0
|
270 |
if (iAsyncCallBusy)
|
sl@0
|
271 |
return KErrInUse;
|
sl@0
|
272 |
|
sl@0
|
273 |
return iSrCustomCommands.StartRecSession(aMode);
|
sl@0
|
274 |
}
|
sl@0
|
275 |
|
sl@0
|
276 |
TInt CSpeechRecognitionUtility::CBody::EndRecSession()
|
sl@0
|
277 |
{
|
sl@0
|
278 |
if (iAsyncCallBusy)
|
sl@0
|
279 |
return KErrInUse;
|
sl@0
|
280 |
|
sl@0
|
281 |
return iSrCustomCommands.EndRecSession();
|
sl@0
|
282 |
}
|
sl@0
|
283 |
|
sl@0
|
284 |
TInt CSpeechRecognitionUtility::CBody::Recognize(CSDClientResultSet& aResultSet)
|
sl@0
|
285 |
{
|
sl@0
|
286 |
if (iAsyncCallBusy)
|
sl@0
|
287 |
return KErrInUse;
|
sl@0
|
288 |
|
sl@0
|
289 |
ASSERT(iResultSet==NULL); // this should be NULL unless we have problems
|
sl@0
|
290 |
|
sl@0
|
291 |
iPrioritySettings.iPriority = iAudioPriority;
|
sl@0
|
292 |
iPrioritySettings.iPref = iRecognitionPreference;
|
sl@0
|
293 |
TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
|
sl@0
|
294 |
|
sl@0
|
295 |
if (err == KErrNone)
|
sl@0
|
296 |
err = iSrCustomCommands.Recognize(aResultSet);
|
sl@0
|
297 |
|
sl@0
|
298 |
if (err == KErrNone)
|
sl@0
|
299 |
{
|
sl@0
|
300 |
iResultSet = &aResultSet;
|
sl@0
|
301 |
iAsyncCallBusy = ETrue;
|
sl@0
|
302 |
}
|
sl@0
|
303 |
return err;
|
sl@0
|
304 |
}
|
sl@0
|
305 |
|
sl@0
|
306 |
TInt CSpeechRecognitionUtility::CBody::Record(TTimeIntervalMicroSeconds32 aRecordTime)
|
sl@0
|
307 |
{
|
sl@0
|
308 |
if (iAsyncCallBusy)
|
sl@0
|
309 |
return KErrInUse;
|
sl@0
|
310 |
|
sl@0
|
311 |
TInt err = iSrCustomCommands.Record(aRecordTime);
|
sl@0
|
312 |
|
sl@0
|
313 |
if (err == KErrNone)
|
sl@0
|
314 |
iAsyncCallBusy=ETrue;
|
sl@0
|
315 |
|
sl@0
|
316 |
return err;
|
sl@0
|
317 |
}
|
sl@0
|
318 |
|
sl@0
|
319 |
TInt CSpeechRecognitionUtility::CBody::RemoveGrammar(TGrammarID aGrammarID)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
if (iAsyncCallBusy)
|
sl@0
|
322 |
return KErrInUse;
|
sl@0
|
323 |
|
sl@0
|
324 |
TInt err = iSrCustomCommands.RemoveGrammar(aGrammarID);
|
sl@0
|
325 |
|
sl@0
|
326 |
if (err == KErrNone)
|
sl@0
|
327 |
iAsyncCallBusy = ETrue;
|
sl@0
|
328 |
return err;
|
sl@0
|
329 |
}
|
sl@0
|
330 |
|
sl@0
|
331 |
TInt CSpeechRecognitionUtility::CBody::RemovePronunciation(TLexiconID aLexiconID, TPronunciationID aPronunciationID)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
if (iAsyncCallBusy)
|
sl@0
|
334 |
return KErrInUse;
|
sl@0
|
335 |
|
sl@0
|
336 |
TInt err = iSrCustomCommands.RemovePronunciation(aLexiconID, aPronunciationID);
|
sl@0
|
337 |
|
sl@0
|
338 |
if (err == KErrNone)
|
sl@0
|
339 |
iAsyncCallBusy = ETrue;
|
sl@0
|
340 |
return err;
|
sl@0
|
341 |
}
|
sl@0
|
342 |
|
sl@0
|
343 |
TInt CSpeechRecognitionUtility::CBody::RemoveLexicon(TLexiconID aLexiconID)
|
sl@0
|
344 |
{
|
sl@0
|
345 |
if (iAsyncCallBusy)
|
sl@0
|
346 |
return KErrInUse;
|
sl@0
|
347 |
|
sl@0
|
348 |
TInt err = iSrCustomCommands.RemoveLexicon(aLexiconID);
|
sl@0
|
349 |
|
sl@0
|
350 |
if (err == KErrNone)
|
sl@0
|
351 |
iAsyncCallBusy = ETrue;
|
sl@0
|
352 |
return err;
|
sl@0
|
353 |
}
|
sl@0
|
354 |
|
sl@0
|
355 |
TInt CSpeechRecognitionUtility::CBody::RemoveModel(TModelBankID aModelBankID, TModelID aModelID)
|
sl@0
|
356 |
{
|
sl@0
|
357 |
if (iAsyncCallBusy)
|
sl@0
|
358 |
return KErrInUse;
|
sl@0
|
359 |
|
sl@0
|
360 |
TInt err = iSrCustomCommands.RemoveModel(aModelBankID, aModelID);
|
sl@0
|
361 |
|
sl@0
|
362 |
if (err == KErrNone)
|
sl@0
|
363 |
iAsyncCallBusy = ETrue;
|
sl@0
|
364 |
|
sl@0
|
365 |
return err;
|
sl@0
|
366 |
}
|
sl@0
|
367 |
|
sl@0
|
368 |
TInt CSpeechRecognitionUtility::CBody::RemoveRule(TGrammarID aGrammarID, TRuleID aRuleID)
|
sl@0
|
369 |
{
|
sl@0
|
370 |
if (iAsyncCallBusy)
|
sl@0
|
371 |
return KErrInUse;
|
sl@0
|
372 |
|
sl@0
|
373 |
TInt err = iSrCustomCommands.RemoveRule(aGrammarID, aRuleID);
|
sl@0
|
374 |
|
sl@0
|
375 |
if (err == KErrNone)
|
sl@0
|
376 |
iAsyncCallBusy = ETrue;
|
sl@0
|
377 |
|
sl@0
|
378 |
return err;
|
sl@0
|
379 |
|
sl@0
|
380 |
}
|
sl@0
|
381 |
TInt CSpeechRecognitionUtility::CBody::Train(TModelBankID aModelBankID, TModelID& aModelID)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
if (iAsyncCallBusy)
|
sl@0
|
384 |
return KErrInUse;
|
sl@0
|
385 |
|
sl@0
|
386 |
iPrioritySettings.iPriority = iAudioPriority;
|
sl@0
|
387 |
iPrioritySettings.iPref = iTrainPreference;
|
sl@0
|
388 |
TInt err = iMMFController.SetPrioritySettings(iPrioritySettings);
|
sl@0
|
389 |
|
sl@0
|
390 |
if (err == KErrNone)
|
sl@0
|
391 |
err = iSrCustomCommands.Train(aModelBankID, aModelID);
|
sl@0
|
392 |
|
sl@0
|
393 |
if (err == KErrNone)
|
sl@0
|
394 |
iAsyncCallBusy = ETrue;
|
sl@0
|
395 |
|
sl@0
|
396 |
return err;
|
sl@0
|
397 |
}
|
sl@0
|
398 |
|
sl@0
|
399 |
TInt CSpeechRecognitionUtility::CBody::UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
if (iAsyncCallBusy)
|
sl@0
|
402 |
return KErrInUse;
|
sl@0
|
403 |
|
sl@0
|
404 |
TInt err = iSrCustomCommands.UnloadRule(aGrammarID, aRuleID);
|
sl@0
|
405 |
|
sl@0
|
406 |
if (err == KErrNone)
|
sl@0
|
407 |
iAsyncCallBusy = ETrue;
|
sl@0
|
408 |
|
sl@0
|
409 |
return err;
|
sl@0
|
410 |
|
sl@0
|
411 |
}
|
sl@0
|
412 |
|
sl@0
|
413 |
void CSpeechRecognitionUtility::CBody::SetEventHandler(MSpeechRecognitionUtilityObserver* aSpeechRecognitionUtilityObserver)
|
sl@0
|
414 |
{
|
sl@0
|
415 |
iSpeechRecognitionUtilityObserver = aSpeechRecognitionUtilityObserver;
|
sl@0
|
416 |
}
|
sl@0
|
417 |
|
sl@0
|
418 |
|
sl@0
|
419 |
TInt CSpeechRecognitionUtility::CBody::GetAllPronunciationIDs(TLexiconID aLexiconID, RArray <TPronunciationID>& aPronunciationIDs)
|
sl@0
|
420 |
{
|
sl@0
|
421 |
if (iAsyncCallBusy)
|
sl@0
|
422 |
return KErrInUse;
|
sl@0
|
423 |
|
sl@0
|
424 |
ASSERT(iPronunciationIDs==NULL);
|
sl@0
|
425 |
|
sl@0
|
426 |
TInt err = iSrCustomCommands.GetAllPronunciationIDs(aLexiconID);
|
sl@0
|
427 |
|
sl@0
|
428 |
if (err==KErrNone)
|
sl@0
|
429 |
{
|
sl@0
|
430 |
iPronunciationIDs = &aPronunciationIDs;
|
sl@0
|
431 |
iPronunciationIDs->Reset();
|
sl@0
|
432 |
iAsyncCallBusy = ETrue;
|
sl@0
|
433 |
}
|
sl@0
|
434 |
|
sl@0
|
435 |
return err;
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
TInt CSpeechRecognitionUtility::CBody::GetAllModelIDs(TModelBankID aModelBankID, RArray <TModelID>& aModelIDs)
|
sl@0
|
439 |
{
|
sl@0
|
440 |
if (iAsyncCallBusy)
|
sl@0
|
441 |
return KErrInUse;
|
sl@0
|
442 |
|
sl@0
|
443 |
ASSERT(iModelIDs==NULL);
|
sl@0
|
444 |
|
sl@0
|
445 |
TInt err = iSrCustomCommands.GetAllModelIDs(aModelBankID);
|
sl@0
|
446 |
|
sl@0
|
447 |
if (err==KErrNone)
|
sl@0
|
448 |
{
|
sl@0
|
449 |
iModelIDs = &aModelIDs;
|
sl@0
|
450 |
iModelIDs->Reset();
|
sl@0
|
451 |
iAsyncCallBusy = ETrue;
|
sl@0
|
452 |
}
|
sl@0
|
453 |
return err;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
|
sl@0
|
457 |
TInt CSpeechRecognitionUtility::CBody::GetAllRuleIDs(TGrammarID aGrammarID, RArray <TRuleID>& aRuleIDs)
|
sl@0
|
458 |
{
|
sl@0
|
459 |
if (iAsyncCallBusy)
|
sl@0
|
460 |
return KErrInUse;
|
sl@0
|
461 |
|
sl@0
|
462 |
ASSERT(iRuleIDs==NULL);
|
sl@0
|
463 |
|
sl@0
|
464 |
TInt err = iSrCustomCommands.GetAllRuleIDs(aGrammarID);
|
sl@0
|
465 |
|
sl@0
|
466 |
if (err==KErrNone)
|
sl@0
|
467 |
{
|
sl@0
|
468 |
iRuleIDs = &aRuleIDs;
|
sl@0
|
469 |
iRuleIDs->Reset();
|
sl@0
|
470 |
iAsyncCallBusy = ETrue;
|
sl@0
|
471 |
}
|
sl@0
|
472 |
return err;
|
sl@0
|
473 |
}
|
sl@0
|
474 |
|
sl@0
|
475 |
|
sl@0
|
476 |
TInt CSpeechRecognitionUtility::CBody::GetAllClientLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
|
sl@0
|
477 |
{
|
sl@0
|
478 |
if (iAsyncCallBusy)
|
sl@0
|
479 |
return KErrInUse;
|
sl@0
|
480 |
|
sl@0
|
481 |
ASSERT(iLexiconIDs==NULL);
|
sl@0
|
482 |
|
sl@0
|
483 |
TInt err = iSrCustomCommands.GetAllClientLexiconIDs();
|
sl@0
|
484 |
|
sl@0
|
485 |
if (err==KErrNone)
|
sl@0
|
486 |
{
|
sl@0
|
487 |
iLexiconIDs = &aLexiconIDs;
|
sl@0
|
488 |
iLexiconIDs->Reset();
|
sl@0
|
489 |
iAsyncCallBusy = ETrue;
|
sl@0
|
490 |
}
|
sl@0
|
491 |
|
sl@0
|
492 |
return err;
|
sl@0
|
493 |
}
|
sl@0
|
494 |
|
sl@0
|
495 |
TInt CSpeechRecognitionUtility::CBody::GetAllClientModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
if (iAsyncCallBusy)
|
sl@0
|
498 |
return KErrInUse;
|
sl@0
|
499 |
|
sl@0
|
500 |
ASSERT(iModelBankIDs==NULL);
|
sl@0
|
501 |
|
sl@0
|
502 |
TInt err = iSrCustomCommands.GetAllClientModelBankIDs();
|
sl@0
|
503 |
|
sl@0
|
504 |
if (err==KErrNone)
|
sl@0
|
505 |
{
|
sl@0
|
506 |
iModelBankIDs = &aModelBankIDs;
|
sl@0
|
507 |
iModelBankIDs->Reset();
|
sl@0
|
508 |
iAsyncCallBusy = ETrue;
|
sl@0
|
509 |
}
|
sl@0
|
510 |
return err;
|
sl@0
|
511 |
}
|
sl@0
|
512 |
|
sl@0
|
513 |
|
sl@0
|
514 |
TInt CSpeechRecognitionUtility::CBody::GetAllClientGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
|
sl@0
|
515 |
{
|
sl@0
|
516 |
if (iAsyncCallBusy)
|
sl@0
|
517 |
return KErrInUse;
|
sl@0
|
518 |
|
sl@0
|
519 |
ASSERT(iGrammarIDs==NULL);
|
sl@0
|
520 |
|
sl@0
|
521 |
TInt err = iSrCustomCommands.GetAllClientGrammarIDs();
|
sl@0
|
522 |
|
sl@0
|
523 |
if (err==KErrNone)
|
sl@0
|
524 |
{
|
sl@0
|
525 |
iGrammarIDs = &aGrammarIDs;
|
sl@0
|
526 |
iGrammarIDs->Reset();
|
sl@0
|
527 |
iAsyncCallBusy = ETrue;
|
sl@0
|
528 |
}
|
sl@0
|
529 |
return err;
|
sl@0
|
530 |
}
|
sl@0
|
531 |
|
sl@0
|
532 |
|
sl@0
|
533 |
TInt CSpeechRecognitionUtility::CBody::GetAllLexiconIDs(RArray <TLexiconID>& aLexiconIDs)
|
sl@0
|
534 |
{
|
sl@0
|
535 |
if (iAsyncCallBusy)
|
sl@0
|
536 |
return KErrInUse;
|
sl@0
|
537 |
|
sl@0
|
538 |
ASSERT(iLexiconIDs==NULL);
|
sl@0
|
539 |
|
sl@0
|
540 |
TInt err = iSrCustomCommands.GetAllLexiconIDs();
|
sl@0
|
541 |
|
sl@0
|
542 |
if (err==KErrNone)
|
sl@0
|
543 |
{
|
sl@0
|
544 |
iLexiconIDs = &aLexiconIDs;
|
sl@0
|
545 |
iLexiconIDs->Reset();
|
sl@0
|
546 |
iAsyncCallBusy = ETrue;
|
sl@0
|
547 |
}
|
sl@0
|
548 |
|
sl@0
|
549 |
return err;
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
TInt CSpeechRecognitionUtility::CBody::GetAllModelBankIDs(RArray <TModelBankID>& aModelBankIDs)
|
sl@0
|
553 |
{
|
sl@0
|
554 |
if (iAsyncCallBusy)
|
sl@0
|
555 |
return KErrInUse;
|
sl@0
|
556 |
|
sl@0
|
557 |
ASSERT(iModelBankIDs==NULL);
|
sl@0
|
558 |
|
sl@0
|
559 |
TInt err = iSrCustomCommands.GetAllModelBankIDs();
|
sl@0
|
560 |
|
sl@0
|
561 |
if (err==KErrNone)
|
sl@0
|
562 |
{
|
sl@0
|
563 |
iModelBankIDs = &aModelBankIDs;
|
sl@0
|
564 |
iModelBankIDs->Reset();
|
sl@0
|
565 |
iAsyncCallBusy = ETrue;
|
sl@0
|
566 |
}
|
sl@0
|
567 |
return err;
|
sl@0
|
568 |
}
|
sl@0
|
569 |
|
sl@0
|
570 |
|
sl@0
|
571 |
TInt CSpeechRecognitionUtility::CBody::GetAllGrammarIDs(RArray <TGrammarID>& aGrammarIDs)
|
sl@0
|
572 |
{
|
sl@0
|
573 |
if (iAsyncCallBusy)
|
sl@0
|
574 |
return KErrInUse;
|
sl@0
|
575 |
|
sl@0
|
576 |
ASSERT(iGrammarIDs==NULL);
|
sl@0
|
577 |
|
sl@0
|
578 |
TInt err = iSrCustomCommands.GetAllGrammarIDs();
|
sl@0
|
579 |
|
sl@0
|
580 |
if (err==KErrNone)
|
sl@0
|
581 |
{
|
sl@0
|
582 |
iGrammarIDs = &aGrammarIDs;
|
sl@0
|
583 |
iGrammarIDs->Reset();
|
sl@0
|
584 |
iAsyncCallBusy = ETrue;
|
sl@0
|
585 |
}
|
sl@0
|
586 |
return err;
|
sl@0
|
587 |
}
|
sl@0
|
588 |
|
sl@0
|
589 |
|
sl@0
|
590 |
TInt CSpeechRecognitionUtility::CBody::GetRuleValidity(TGrammarID aGrammarID, TRuleID aRuleID, TBool& aValid)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
if (iAsyncCallBusy)
|
sl@0
|
593 |
return KErrInUse;
|
sl@0
|
594 |
|
sl@0
|
595 |
TInt err = iSrCustomCommands.GetRuleValidity(aGrammarID, aRuleID, aValid);
|
sl@0
|
596 |
|
sl@0
|
597 |
if (err == KErrNone)
|
sl@0
|
598 |
iAsyncCallBusy = ETrue;
|
sl@0
|
599 |
return err;
|
sl@0
|
600 |
}
|
sl@0
|
601 |
|
sl@0
|
602 |
|
sl@0
|
603 |
TInt CSpeechRecognitionUtility::CBody::CreateModelBank(TModelBankID& aModelBankID)
|
sl@0
|
604 |
{
|
sl@0
|
605 |
if (iAsyncCallBusy)
|
sl@0
|
606 |
return KErrInUse;
|
sl@0
|
607 |
TInt err = iSrCustomCommands.CreateModelBank(aModelBankID);
|
sl@0
|
608 |
if (err == KErrNone)
|
sl@0
|
609 |
iAsyncCallBusy = ETrue;
|
sl@0
|
610 |
return err;
|
sl@0
|
611 |
}
|
sl@0
|
612 |
|
sl@0
|
613 |
TInt CSpeechRecognitionUtility::CBody::RemoveModelBank(TModelBankID aModelBankID)
|
sl@0
|
614 |
{
|
sl@0
|
615 |
if (iAsyncCallBusy)
|
sl@0
|
616 |
return KErrInUse;
|
sl@0
|
617 |
|
sl@0
|
618 |
TInt err = iSrCustomCommands.RemoveModelBank(aModelBankID);
|
sl@0
|
619 |
if (err == KErrNone)
|
sl@0
|
620 |
iAsyncCallBusy = ETrue;
|
sl@0
|
621 |
return err;
|
sl@0
|
622 |
}
|
sl@0
|
623 |
|
sl@0
|
624 |
TInt CSpeechRecognitionUtility::CBody::GetAvailableStorage(TInt& aAvailableStorage)
|
sl@0
|
625 |
{
|
sl@0
|
626 |
if (iAsyncCallBusy)
|
sl@0
|
627 |
return KErrInUse;
|
sl@0
|
628 |
|
sl@0
|
629 |
TInt err = iSrCustomCommands.GetAvailableStorage(aAvailableStorage);
|
sl@0
|
630 |
|
sl@0
|
631 |
if (err == KErrNone)
|
sl@0
|
632 |
iAsyncCallBusy = ETrue;
|
sl@0
|
633 |
|
sl@0
|
634 |
return err;
|
sl@0
|
635 |
}
|
sl@0
|
636 |
|
sl@0
|
637 |
TInt CSpeechRecognitionUtility::CBody::LoadEngineParameters(const RArray<TInt>& aParameterId, const RArray<TInt>& aParameterValue)
|
sl@0
|
638 |
{
|
sl@0
|
639 |
if (iAsyncCallBusy)
|
sl@0
|
640 |
return KErrInUse;
|
sl@0
|
641 |
|
sl@0
|
642 |
return iSrCustomCommands.LoadEngineParameters(aParameterId, aParameterValue);
|
sl@0
|
643 |
}
|
sl@0
|
644 |
|
sl@0
|
645 |
TInt CSpeechRecognitionUtility::CBody::SetAudioPriority(TInt aPriority, TInt aTrainPreference, TInt aPlaybackPreference, TInt aRecognitionPreference)
|
sl@0
|
646 |
{
|
sl@0
|
647 |
iAudioPriority = aPriority;
|
sl@0
|
648 |
iTrainPreference = (TMdaPriorityPreference)aTrainPreference;
|
sl@0
|
649 |
iPlaybackPreference = (TMdaPriorityPreference)aPlaybackPreference;
|
sl@0
|
650 |
iRecognitionPreference = (TMdaPriorityPreference)aRecognitionPreference;
|
sl@0
|
651 |
|
sl@0
|
652 |
return KErrNone;
|
sl@0
|
653 |
}
|
sl@0
|
654 |
|
sl@0
|
655 |
void CSpeechRecognitionUtility::CBody::HandleEvent(const TMMFEvent& aEvent)
|
sl@0
|
656 |
{
|
sl@0
|
657 |
TBool cancelled = EFalse;
|
sl@0
|
658 |
TBool asyncCallComplete = ETrue;
|
sl@0
|
659 |
|
sl@0
|
660 |
TUid event = aEvent.iEventType;
|
sl@0
|
661 |
TInt errorCode = aEvent.iErrorCode;
|
sl@0
|
662 |
|
sl@0
|
663 |
|
sl@0
|
664 |
switch (event.iUid)
|
sl@0
|
665 |
{
|
sl@0
|
666 |
case KUidAsrEventGetAllPronunciationIDsVal :
|
sl@0
|
667 |
{
|
sl@0
|
668 |
if (iPronunciationIDs)
|
sl@0
|
669 |
{
|
sl@0
|
670 |
if (errorCode==KErrNone)
|
sl@0
|
671 |
TRAP(errorCode, iSrCustomCommands.GetPronunciationIDArrayL(*iPronunciationIDs));
|
sl@0
|
672 |
// async operation complete, so get rid of reference to array
|
sl@0
|
673 |
iPronunciationIDs = NULL;
|
sl@0
|
674 |
}
|
sl@0
|
675 |
else
|
sl@0
|
676 |
cancelled = ETrue;
|
sl@0
|
677 |
}
|
sl@0
|
678 |
break;
|
sl@0
|
679 |
case KUidAsrEventGetAllRuleIDsVal :
|
sl@0
|
680 |
{
|
sl@0
|
681 |
if (iRuleIDs)
|
sl@0
|
682 |
{
|
sl@0
|
683 |
if (errorCode==KErrNone)
|
sl@0
|
684 |
TRAP(errorCode, iSrCustomCommands.GetRuleIDArrayL(*iRuleIDs));
|
sl@0
|
685 |
// async operation complete, so get rid of reference to array
|
sl@0
|
686 |
iRuleIDs = NULL;
|
sl@0
|
687 |
}
|
sl@0
|
688 |
else
|
sl@0
|
689 |
cancelled = ETrue;
|
sl@0
|
690 |
}
|
sl@0
|
691 |
break;
|
sl@0
|
692 |
case KUidAsrEventGetAllModelIDsVal :
|
sl@0
|
693 |
{
|
sl@0
|
694 |
if (iModelIDs)
|
sl@0
|
695 |
{
|
sl@0
|
696 |
if (errorCode==KErrNone)
|
sl@0
|
697 |
TRAP(errorCode, iSrCustomCommands.GetModelIDArrayL(*iModelIDs));
|
sl@0
|
698 |
// async operation complete, so get rid of reference to array
|
sl@0
|
699 |
iModelIDs = NULL;
|
sl@0
|
700 |
}
|
sl@0
|
701 |
else
|
sl@0
|
702 |
cancelled = ETrue;
|
sl@0
|
703 |
}
|
sl@0
|
704 |
break;
|
sl@0
|
705 |
case KUidAsrEventGetAllClientModelBankIDsVal :
|
sl@0
|
706 |
case KUidAsrEventGetAllModelBankIDsVal :
|
sl@0
|
707 |
{
|
sl@0
|
708 |
if (iModelBankIDs)
|
sl@0
|
709 |
{
|
sl@0
|
710 |
if (errorCode==KErrNone)
|
sl@0
|
711 |
TRAP(errorCode, iSrCustomCommands.GetModelBankIDArrayL(*iModelBankIDs));
|
sl@0
|
712 |
// async operation complete, so get rid of reference to array
|
sl@0
|
713 |
iModelBankIDs = NULL;
|
sl@0
|
714 |
}
|
sl@0
|
715 |
else
|
sl@0
|
716 |
cancelled = ETrue;
|
sl@0
|
717 |
}
|
sl@0
|
718 |
break;
|
sl@0
|
719 |
case KUidAsrEventGetAllClientGrammarIDsVal :
|
sl@0
|
720 |
case KUidAsrEventGetAllGrammarIDsVal :
|
sl@0
|
721 |
{
|
sl@0
|
722 |
if (iGrammarIDs)
|
sl@0
|
723 |
{
|
sl@0
|
724 |
if (errorCode==KErrNone)
|
sl@0
|
725 |
TRAP(errorCode, iSrCustomCommands.GetGrammarIDArrayL(*iGrammarIDs));
|
sl@0
|
726 |
// async operation complete, so get rid of reference to array
|
sl@0
|
727 |
iGrammarIDs = NULL;
|
sl@0
|
728 |
}
|
sl@0
|
729 |
else
|
sl@0
|
730 |
cancelled = ETrue;
|
sl@0
|
731 |
}
|
sl@0
|
732 |
break;
|
sl@0
|
733 |
case KUidAsrEventGetAllClientLexiconIDsVal :
|
sl@0
|
734 |
case KUidAsrEventGetAllLexiconIDsVal :
|
sl@0
|
735 |
{
|
sl@0
|
736 |
if (iLexiconIDs)
|
sl@0
|
737 |
{
|
sl@0
|
738 |
if (errorCode==KErrNone)
|
sl@0
|
739 |
TRAP(errorCode, iSrCustomCommands.GetLexiconIDArrayL(*iLexiconIDs));
|
sl@0
|
740 |
// async operation complete, so get rid of reference to array
|
sl@0
|
741 |
iLexiconIDs = NULL;
|
sl@0
|
742 |
}
|
sl@0
|
743 |
else
|
sl@0
|
744 |
cancelled = ETrue;
|
sl@0
|
745 |
}
|
sl@0
|
746 |
break;
|
sl@0
|
747 |
|
sl@0
|
748 |
case KUidAsrEventRecognitionVal :
|
sl@0
|
749 |
{
|
sl@0
|
750 |
if (iResultSet)
|
sl@0
|
751 |
{
|
sl@0
|
752 |
if (errorCode==KErrNone)
|
sl@0
|
753 |
TRAP(errorCode, iSrCustomCommands.GetResultSetL(*iResultSet));
|
sl@0
|
754 |
iResultSet = NULL;
|
sl@0
|
755 |
}
|
sl@0
|
756 |
else
|
sl@0
|
757 |
cancelled = ETrue;
|
sl@0
|
758 |
}
|
sl@0
|
759 |
break;
|
sl@0
|
760 |
case KUidAsrEventTrainVal:
|
sl@0
|
761 |
break;
|
sl@0
|
762 |
case KUidAsrEventPlayStartedVal:
|
sl@0
|
763 |
case KUidAsrEventRecordStartedVal:
|
sl@0
|
764 |
asyncCallComplete = EFalse;
|
sl@0
|
765 |
break;
|
sl@0
|
766 |
default:
|
sl@0
|
767 |
break;
|
sl@0
|
768 |
|
sl@0
|
769 |
}
|
sl@0
|
770 |
if (event == KMMFErrorCategoryControllerGeneralError)
|
sl@0
|
771 |
{
|
sl@0
|
772 |
// clear these, as the error callback
|
sl@0
|
773 |
iPronunciationIDs = NULL;
|
sl@0
|
774 |
iRuleIDs = NULL;
|
sl@0
|
775 |
iModelIDs = NULL;
|
sl@0
|
776 |
iLexiconIDs = NULL;
|
sl@0
|
777 |
iGrammarIDs = NULL;
|
sl@0
|
778 |
iModelBankIDs = NULL;
|
sl@0
|
779 |
}
|
sl@0
|
780 |
if (asyncCallComplete)
|
sl@0
|
781 |
iAsyncCallBusy = EFalse;
|
sl@0
|
782 |
|
sl@0
|
783 |
if (iSpeechRecognitionUtilityObserver && !cancelled)
|
sl@0
|
784 |
iSpeechRecognitionUtilityObserver->MsruoEvent(event, errorCode);
|
sl@0
|
785 |
|
sl@0
|
786 |
}
|
sl@0
|
787 |
|