diff -r 000000000000 -r b8ed18f6c07b mmdevicefw/speechrecogsupport/ASR/src/SpeechRecognitionCustomCommands.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mmdevicefw/speechrecogsupport/ASR/src/SpeechRecognitionCustomCommands.cpp Thu Oct 07 22:34:12 2010 +0100 @@ -0,0 +1,771 @@ +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + +// INCLUDES +#include +#include "SpeechRecognitionCustomCommandCommon.h" + +const TInt KExpandSize = 10; + + +EXPORT_C RSpeechRecognitionCustomCommands::RSpeechRecognitionCustomCommands(RMMFController& aController) + :RMMFCustomCommandsBase(aController, KUidInterfaceSpeechRecognition) + { + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::AddPronunciation(TLexiconID aLexiconID, + TModelBankID aModelBankID, TModelID aModelID, + TPronunciationID& aPronunciationID) + { + TSrsAddPronunciationPckg pckg(TSrsAddPronunciation(aLexiconID,aModelBankID,aModelID,&aPronunciationID)); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrAddPronunciation, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::SetClientUid(TUid aClientUid) + { + TSrsUidPckg pckg(aClientUid); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrSetClientUid, + pckg, + KNullDesC8); + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::AddRule(TGrammarID aGrammarID, TLexiconID aLexiconID, + TPronunciationID aPronunciationID, TRuleID& aRuleID) + + { + TSrsAddRulePckg pckg(TSrsAddRule(aGrammarID, aLexiconID, aPronunciationID, &aRuleID)); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrAddRule, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C void RSpeechRecognitionCustomCommands::Cancel() + { + iController.CustomCommandSync(iDestinationPckg, + ESrCancel, + KNullDesC8, + KNullDesC8); + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::CommitChanges() + { + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrCommitChanges, + KNullDesC8, + KNullDesC8); + + return err; + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::CreateGrammar(TGrammarID& aGrammarID) + { + TSrsGrammarIDPtrPckg pckg(&aGrammarID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrCreateGrammar, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::CreateLexicon(TLexiconID& aLexiconID) + { + TSrsLexiconIDPtrPckg pckg(&aLexiconID); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrCreateLexicon, + pckg, + KNullDesC8); + + return err; + + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::CreateModelBank(TModelBankID& aModelBankID) + { + TSrsModelBankIDPtrPckg pckg(&aModelBankID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrCreateModelBank, + pckg, + KNullDesC8); + + return err; + + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::EndRecSession() + + { + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrEndRecSession, + KNullDesC8, + KNullDesC8); + + return err; + + + } +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetAllModelIDs(TModelBankID aModelBankID) + { + TSrsModelBankIDPckg pckg(aModelBankID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetAllModelIDs, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetAllPronunciationIDs(TLexiconID aLexiconID) + { + TSrsLexiconIDPckg pckg(aLexiconID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetAllPronunciationIDs, + pckg, + KNullDesC8); + return err; + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetAllRuleIDs(TGrammarID aGrammarID) + { + TSrsGrammarIDPckg pckg(aGrammarID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetAllRuleIDs, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetAvailableStorage(TInt& aAvailableStorage) + + { + TSrsIntPtrPckg pckg(&aAvailableStorage); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetAvailableStorage, + pckg, + KNullDesC8); + + return err; + + } +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetEngineProperties(const RArray& aPropertyId, + RArray& aPropertyValue) + { + + TRAPD(err, DoGetEnginePropertiesL(aPropertyId, aPropertyValue)); + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetModelCount(TModelBankID aModelBankID, + TInt& aModelCount) + { + TSrsModelBankIDPckg pckg(aModelBankID); + TSrsIntPtrPckg resultpckg(&aModelCount); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetModelCount, + pckg, + resultpckg); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetRuleValidity(TGrammarID aGrammarID, TRuleID aRuleID, + TBool& aValid) + { + TSrsRuleValidityPckg pckg(TSrsRuleValidity(aGrammarID, aRuleID, &aValid)); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrGetRuleValidity, + pckg, + KNullDesC8); + return err; + + } +EXPORT_C TInt RSpeechRecognitionCustomCommands::GetUtteranceDuration(TModelBankID aModelBankID, + TModelID aModelID, TTimeIntervalMicroSeconds32& aDuration) + { + TSrsGetUtteranceDurationPckg pckg(TSrsGetUtteranceDuration(aModelBankID, aModelID, &aDuration)); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrUtteranceDuration, + pckg, + KNullDesC8); + return err; + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::LoadGrammar(TGrammarID aGrammarID) + { + TSrsGrammarIDPckg pckg(aGrammarID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrLoadGrammar, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::LoadLexicon(TLexiconID aLexiconID) + { + TSrsLexiconIDPckg pckg(aLexiconID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrLoadLexicon, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::LoadModels(TModelBankID aModelBankID) + { + TSrsModelBankIDPckg pckg(aModelBankID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrLoadModels, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::PlayUtterance(TModelBankID aModelBankID, + TModelID aModelID) + { + TSrsPlayUtterancePckg pckg(TSrsPlayUtterance(aModelBankID, aModelID)); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrPlayUtterance, + pckg, + KNullDesC8); + return err; + + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::Recognize(CSDClientResultSet& aResultSet) + { + TRAPD(err, DoRecognizeL(aResultSet)); + return err; + } + + +EXPORT_C TInt RSpeechRecognitionCustomCommands::Record(TTimeIntervalMicroSeconds32 aRecordTime) + { + TSrsTimeIntervalMicroSeconds32Pckg pckg(aRecordTime); + + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRecord, + pckg, + KNullDesC8); + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemoveGrammar(TGrammarID aGrammarID) + { + TSrsGrammarIDPckg pckg(aGrammarID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemoveGrammar, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemoveLexicon(TLexiconID aLexiconID) + { + TSrsLexiconIDPckg pckg(aLexiconID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemoveLexicon, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemoveModelBank(TModelBankID aModelBankID) + { + TSrsModelBankIDPckg pckg(aModelBankID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemoveModelBank, + pckg, + KNullDesC8); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemoveModel(TModelBankID aModelBankID, + TModelID aModelID) + { + TSrsModelBankIDPckg pckgModelBankID(aModelBankID); + TSrsModelIDPckg pckgModelID(aModelID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemoveModel, + pckgModelBankID, + pckgModelID); + + return err; + } +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemovePronunciation(TLexiconID aLexiconID, + TPronunciationID aPronunciationID) + { + TSrsLexiconIDPckg pckgLexiconID(aLexiconID); + TSrsPronunciationIDPckg pckgPronunciationID(aPronunciationID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemovePronunciation, + pckgLexiconID, + pckgPronunciationID); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::RemoveRule(TGrammarID aGrammarID, TRuleID aRuleID) + { + TSrsGrammarIDPckg pckgGrammarID(aGrammarID); + TSrsRuleIDPckg pckgRuleID(aRuleID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrRemoveRule, + pckgGrammarID, + pckgRuleID); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::StartRecSession(TRecognitionMode aMode) + { + TSrsRecognitionModePckg pckg(aMode); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrStartRecSession, + pckg, + KNullDesC8); + + return err; + + } + + +EXPORT_C TInt RSpeechRecognitionCustomCommands::Train(TModelBankID aModelBankID, TModelID& aModelID) + { + TSrsModelBankIDPckg pckgModelBankID(aModelBankID); + TSrsModelIDPtrPckg pckgModelID(&aModelID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrTrain, + pckgModelBankID, + pckgModelID); + + return err; + } +EXPORT_C TInt RSpeechRecognitionCustomCommands::UnloadRule(TGrammarID aGrammarID, TRuleID aRuleID) + { + TSrsGrammarIDPckg pckgGrammarID(aGrammarID); + TSrsRuleIDPckg pckgRuleID(aRuleID); + TInt err = iController.CustomCommandSync(iDestinationPckg, + ESrUnloadRule, + pckgGrammarID, + pckgRuleID); + + return err; + } + +EXPORT_C TInt RSpeechRecognitionCustomCommands::LoadEngineParameters(const RArray& aParameterId, + const RArray& aParameterValue) + { + TRAPD(err, DoLoadEngineParametersL(aParameterId, aParameterValue)); + return err; + } + +void RSpeechRecognitionCustomCommands::DoLoadEngineParametersL(const RArray& aParameterId, + const RArray& aParameterValue) + { + CBufFlat* param1 = ExternalizeIntArrayL(aParameterId); + CleanupStack::PushL(param1); + CBufFlat* param2 = ExternalizeIntArrayL(aParameterValue); + CleanupStack::PushL(param2); + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrLoadEngineParameters, + param1->Ptr(0), + param2->Ptr(0))); + + CleanupStack::PopAndDestroy(2,param1); //param1, param2 + } + + + +EXPORT_C void RSpeechRecognitionCustomCommands::GetPronunciationIDArrayL(RArray& aPronunciationIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetPronunciationIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TPronunciationID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetPronunciationIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i& aRuleIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetRuleIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TRuleID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetRuleIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i& aModelIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetModelIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TModelID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetModelIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetClientResultSetSize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetClientResultSet, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + aResultSet.InternalizeL(stream); + CleanupStack::PopAndDestroy(2, buf);//buf, stream + } + +void RSpeechRecognitionCustomCommands::DoRecognizeL(CSDClientResultSet& aResultSet) + { + CBufFlat* dataCopyBuffer = CBufFlat::NewL(KExpandSize); + CleanupStack::PushL(dataCopyBuffer); + RBufWriteStream stream; + stream.Open(*dataCopyBuffer); + CleanupClosePushL(stream); + + aResultSet.ExternalizeL(stream); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrRecognize, + dataCopyBuffer->Ptr(0), + KNullDesC8)); + + CleanupStack::PopAndDestroy(2); //stream,dataCopyBuffer + } + + +void RSpeechRecognitionCustomCommands::DoGetEnginePropertiesL(const RArray& aPropertyId, + RArray& aPropertyValue) + { + CBufFlat* param1 = ExternalizeIntArrayL(aPropertyId); + CleanupStack::PushL(param1); + + TInt aNumberResults = aPropertyId.Count(); // same number of values as properties + + HBufC8* buf = HBufC8::NewLC(aNumberResults *sizeof(TInt)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetEngineProperties, + param1->Ptr(0), + KNullDesC8, + ptr)); + + InternalizeIntArrayL(ptr,aNumberResults,aPropertyValue); + + CleanupStack::PopAndDestroy(2,param1);//param1, buf + } + +CBufFlat* RSpeechRecognitionCustomCommands::ExternalizeIntArrayL(const RArray& aArray) + { + CBufFlat* dataCopyBuffer = CBufFlat::NewL(KExpandSize); + CleanupStack::PushL(dataCopyBuffer); + RBufWriteStream stream; + stream.Open(*dataCopyBuffer); + CleanupClosePushL(stream); + + stream.WriteInt32L(aArray.Count()); + + for (TInt i=0;i& aArray) + { + RDesReadStream stream(aDes); + CleanupClosePushL(stream); + + for (TInt i=0; i& aModelBankIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetModelBankIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TModelID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetModelBankIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i& aGrammarIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetGrammarIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TGrammarID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetGrammarIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i& aLexiconIDs) + { + TPckgBuf pckgSize; + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetLexiconIDArraySize, + KNullDesC8, + KNullDesC8, + pckgSize)); + + HBufC8* buf = HBufC8::NewLC(pckgSize()*sizeof(TLexiconID)); + TPtr8 ptr = buf->Des(); + + User::LeaveIfError(iController.CustomCommandSync(iDestinationPckg, + ESrGetLexiconIDArrayContents, + KNullDesC8, + KNullDesC8, + ptr)); + + RDesReadStream stream(ptr); + CleanupClosePushL(stream); + + for (TInt i=0; i