本文整理汇总了C++中CComPtr::AddWordTransition方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::AddWordTransition方法的具体用法?C++ CComPtr::AddWordTransition怎么用?C++ CComPtr::AddWordTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComPtr
的用法示例。
在下文中一共展示了CComPtr::AddWordTransition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: refreshFromVocabulories
bool SpeechRecognizerModule::refreshFromVocabulories(CComPtr<ISpRecoGrammar> grammarToModify)
{
//return true;
bool everythingIsFine = true;
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_DISABLED));
//Build a rule for each vocabulory
for(map<string, list<string> >::iterator vIt = m_vocabulories.begin(); vIt != m_vocabulories.end(); vIt++)
{
//Get the rule name from the key in the dictionary (i.e Agent, Action, etc...)
string removedSharp =vIt->first;
removedSharp.erase(0,1);
std::wstring tmp = s2ws(removedSharp);
LPCWSTR cwRuleName = tmp.c_str();
SPSTATEHANDLE hinit,hstate;
HRESULT hr;
//Get the rule or create it
everythingIsFine &= SUCCEEDED(hr = grammarToModify->GetRule(cwRuleName, NULL, SPRAF_Dynamic, false, &hinit));
everythingIsFine &= SUCCEEDED(hr = grammarToModify->ClearRule(hinit));
for(list<string>::iterator wordIt = vIt->second.begin() ; wordIt != vIt->second.end(); wordIt++)
{
std::wstring wordTmp = s2ws(*wordIt);
LPCWSTR cwWord = wordTmp.c_str();
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(hinit, NULL, cwWord, NULL, SPWT_LEXICAL, 1, NULL) );
}
}
everythingIsFine &= SUCCEEDED(grammarToModify->Commit(NULL));
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_ENABLED));
everythingIsFine &= SUCCEEDED(grammarToModify->SetRuleState(NULL, NULL, SPRS_ACTIVE));
yInfo() << "Grammar is paused, DO NOT SPEAK! (if next message is coming after too long, check your microphone level and lower it!" ;
everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->Resume(NULL));
yInfo() << "Grammar is resumed : everything is fine = " << everythingIsFine;
return everythingIsFine;
}
示例2: test
//.........这里部分代码省略.........
//Release the stream and voice object
cpStream.Release();
cpVoice.Release();
CComPtr<ISpGrammarBuilder> cpGrammarBuilder;
SPSTATEHANDLE hStateTravel;
// Create (if rule does not already exist)
// top-level Rule, defaulting to Active.
hr = cpGrammarBuilder->GetRule(L"Travel", 0, SPRAF_TopLevel | SPRAF_Active, TRUE, &hStateTravel);
// Approach 1: List all possible phrases.
// This is the most intuitive approach, and it does not sacrifice efficiency
// because the grammar builder will merge shared sub-phrases when possible.
// There is only one root state, hStateTravel, and the terminal NULL state,
// and there are six unique transitions between root state and NULL state.
/* XML Approximation:
<rule id="Travel">
<item> fly to Seattle </item>
<item> fly to New York </item>
<item> fly to Washington DC </item>
<item> drive to Seattle </item>
<item> drive to New York </item>
<item> drive to Washington DC </item>
</rule>
*/
// Create set of peer phrases, each containing complete phrase.
// Note: the word delimiter is set as " ", so that the text we
// attach to the transition can be multiple words (for example,
// "fly to Seattle" is implicitly "fly" + "to" + "Seattle"):
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"fly to Seattle", L" ", SPWT_LEXICAL, 1, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"fly to New York", L" ", SPWT_LEXICAL, 1, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"fly to Washington DC", L" ", SPWT_LEXICAL, 1, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"drive to Seattle", L" ", SPWT_LEXICAL, 1, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"drive to New York", L" ", SPWT_LEXICAL, 1, NULL);
}
if (SUCCEEDED(hr))
{
hr = cpGrammarBuilder->AddWordTransition(hStateTravel, NULL, L"drive to Washington DC", L" ", SPWT_LEXICAL, 1, NULL);
}
// Find the best matching installed en-US recognizer.
//CComPtr<ISpObjectToken> cpRecognizerToken;
if (SUCCEEDED(hr))
{
hr = SpFindBestToken(SPCAT_RECOGNIZERS, L"language=409", NULL, &cpRecognizerToken);
}
// Create the in-process recognizer and immediately set its state to inactive.
//CComPtr<ISpRecognizer> cpRecognizer;
示例3: setGrammarCustom
bool SpeechRecognizerModule::setGrammarCustom(CComPtr<ISpRecoGrammar> grammarToModify, string grammar, bool append)
{
//Clear the existing runtime grammar
SPSTATEHANDLE runtimeRootRule;
bool everythingIsFine = true;
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_DISABLED));
everythingIsFine &= SUCCEEDED(grammarToModify->GetRule(L"rootRule", NULL, SPRAF_TopLevel | SPRAF_Active, TRUE, &runtimeRootRule));
if(!append)
everythingIsFine &= SUCCEEDED(grammarToModify->ClearRule(runtimeRootRule));
//Build a rule for each vocabulory
map<string, SPSTATEHANDLE> vocabRules;
for(map<string, list<string> >::iterator vIt = m_vocabulories.begin(); vIt != m_vocabulories.end(); vIt++)
{
//Get the rule name from the key in the dictionary (i.e Agent, Action, etc...)
std::wstring tmp = s2ws(vIt->first);
LPCWSTR cwRuleName = tmp.c_str();
//Get the rule or create it
everythingIsFine &= SUCCEEDED(grammarToModify->GetRule(cwRuleName, NULL, SPRAF_Dynamic, TRUE, &vocabRules[vIt->first]));
everythingIsFine &= SUCCEEDED(grammarToModify->ClearRule(vocabRules[vIt->first]));
for(list<string>::iterator wordIt = vIt->second.begin() ; wordIt != vIt->second.end(); wordIt++)
{
std::wstring wordTmp = s2ws(*wordIt);
LPCWSTR cwWord = wordTmp.c_str();
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(vocabRules[vIt->first], NULL, cwWord, NULL, SPWT_LEXICAL, 1, NULL) );
}
}
//Go through the given string and build the according grammar
//Split the choices
vector<string> sentences = split(grammar,'|');
for(vector<string>::iterator it = sentences.begin() ; it != sentences.end() ; it++)
{
//Split the words
vector<string> words = split(*it,' ');
SPSTATEHANDLE beforeWordHandle = runtimeRootRule;
SPSTATEHANDLE afterWordHandle;
for(vector<string>::iterator itWord = words.begin() ; itWord != words.end() ; itWord++)
{
if((*itWord)=="")
continue;
everythingIsFine &= SUCCEEDED(grammarToModify->CreateNewState(beforeWordHandle, &afterWordHandle));
//Check if the current word is the name of a vocabulory
if ( (*itWord)[0] == '#' && m_vocabulories.find(*itWord) != m_vocabulories.end())
{
everythingIsFine &= SUCCEEDED(grammarToModify->AddRuleTransition(beforeWordHandle, afterWordHandle, vocabRules[*itWord], 1, NULL));
}
else
{
std::wstring wordTmp = s2ws(*itWord);
LPCWSTR cwWord = wordTmp.c_str();
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(beforeWordHandle, afterWordHandle, cwWord, NULL, SPWT_LEXICAL, 1, NULL) );
}
beforeWordHandle = afterWordHandle;
}
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(beforeWordHandle, NULL, NULL, NULL, SPWT_LEXICAL, 1, NULL) );
}
everythingIsFine &= SUCCEEDED(grammarToModify->Commit(NULL));
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_ENABLED));
everythingIsFine &= SUCCEEDED(grammarToModify->SetRuleState(NULL, NULL, SPRS_ACTIVE));
everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->Resume(0));
return everythingIsFine;
}