我用sapi5.1,想做个语音识别的小程序但是总是出问题
if (FAILED(m_pRecoContext->CreateGrammar(101, &m_pCMDGrammar)))
{
MessageBox(_T("Failed to create instance of ISpRecoGrammar!"));
return FALSE;
}
HRESULT hr = S_OK;
hr = m_pCMDGrammar->LoadCmdFromFile(_T("E:\\MyProject\\SpeechTest\\Debug\\email.xml"), SPLO_DYNAMIC);
if (FAILED(hr))
{
int e = GetLastError();
MessageBox(_T("Failed to Load CMD!"));
return FALSE;
}
if (E_INVALIDARG == hr)
{
MessageBox(_T("Invalid File Name or param"));
}
这个地方,总是弹出"Failed to Load CMD!",但是不会弹出"Invalid File Name or param",找不到原因。
GetLastError返回的也是0,说明是正常返回
有谁用过sapi的,帮忙解答一下,谢谢了!
if (FAILED(m_pRecoContext->CreateGrammar(101, &m_pCMDGrammar)))
{
MessageBox(_T("Failed to create instance of ISpRecoGrammar!"));
return FALSE;
}
HRESULT hr = S_OK;
hr = m_pCMDGrammar->LoadCmdFromFile(_T("E:\\MyProject\\SpeechTest\\Debug\\email.xml"), SPLO_DYNAMIC);
if (FAILED(hr))
{
int e = GetLastError();
MessageBox(_T("Failed to Load CMD!"));
return FALSE;
}
if (E_INVALIDARG == hr)
{
MessageBox(_T("Invalid File Name or param"));
}
这个地方,总是弹出"Failed to Load CMD!",但是不会弹出"Invalid File Name or param",找不到原因。
GetLastError返回的也是0,说明是正常返回
有谁用过sapi的,帮忙解答一下,谢谢了!
HRESULT hr = S_OK; // create a new grammar object
hr = cpRecoContext->CreateGrammar(GRAM_ID, &cpRecoGrammar);
// Check hr // deactivate the grammar to prevent premature recognitions to an "under-construction" grammar
hr = cpRecoGrammar->SetGrammarState(SPGS_DISABLED);
// Check hr // load the email grammar dynamically, so changes can be made at runtime
hr = cpRecoGrammar->LoadCmdFromFile(L"email.xml", SPLO_DYNAMIC);
// Check hr SPSTATEHANDLE hRule; // first retrieve the dynamic rule ADDRESS_BOOK
hr = cpRecoGrammar->GetRule(L"ADDRESS_BOOK", NULL, SPRAF_Dynamic, FALSE, &hRule);
// Check hr // clear the placeholder text, and everything else in the dynamic ADDRESS_BOOK rule
hr = cpRecoGrammar->ClearRule(hRule);
// Check hr // add the real address book (e.g. "Frank Lee", "self", "SAPI beta", etc.).
// Note that ISpRecoGrammar inherits from ISpGrammarBuilder,
// so application gets the grammar compiler and ::AddWordTransition for free! hr = cpRecoGrammar->AddWordTransition(hRule, NULL, L"Frank Lee", NULL, SPWT_LEXICAL, 1, NULL);
// Check hr
hr = cpRecoGrammar->AddWordTransition(hRule, NULL, L"self", NULL, SPWT_LEXICAL, 1, NULL);
// Check hr
hr = cpRecoGrammar->AddWordTransition(hRule, NULL, L"SAPI beta", NULL, SPWT_LEXICAL, 1, NULL);
// Check hr
// ... add rest of address book // commit the grammar changes, which updates the grammar inside SAPI,
// and notifies the SR Engine about the rule change (i.e. "ADDRESS_BOOK"
hr = cpRecoGrammar->Commit(NULL);
// Check hr // activate the grammar since "construction" is finished,
// and ready for receiving recognitions
hr = cpRecoGrammar->SetGrammarState(SPGS_ENABLED);
// Check hr
这个地方不通过,返回值hr为-2146697211(0x800c0005)
搞不懂这个返回值是什么意义
A 4-bit reserved value.
An 11-bit code indicating responsibility for the error or warning, also known as a facility code.
A 16-bit code describing the error or warning.
啊,我要崩溃了!