spai中LoadCmdFromFile总是失败!

amatuer_feier 2009-11-12 11:45:27
我用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的,帮忙解答一下,谢谢了!
...全文
465 19 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
nixius 2012-02-28
  • 打赏
  • 举报
回复
跟lz同样的问题,纠结中~~~~~
chenbo197797 2012-01-17
  • 打赏
  • 举报
回复
一样的问题,谁知道啊?
pingpopo 2011-09-27
  • 打赏
  • 举报
回复
一样的问题,求解。
qpzmwsxedcrfvtgb 2011-04-28
  • 打赏
  • 举报
回复
同问题,求解答
hongh520 2011-01-01
  • 打赏
  • 举报
回复
我的问题跟楼主的一样~ 找不出什么原因··
jcf0372 2010-10-02
  • 打赏
  • 举报
回复
没看懂…………
chendanche 2010-09-29
  • 打赏
  • 举报
回复
是啊,为什么呢?我也愁啊。
zgsdzhaolanxiang1 2010-09-29
  • 打赏
  • 举报
回复
帮顶,每天回复可以增加10可用分。
panpengpeng 2010-09-29
  • 打赏
  • 举报
回复
同错
同问
同顶
dns007 2009-12-21
  • 打赏
  • 举报
回复
路过 ,学习!
whodewho 2009-12-21
  • 打赏
  • 举报
回复
顶起来
amatuer_feier 2009-11-13
  • 打赏
  • 举报
回复
很无语,facility code里面都没有出现跟我这里对应的值。。。
啊,我要崩溃了!
MoXiaoRab 2009-11-13
  • 打赏
  • 举报
回复
去MSDN查各个位的对应

MoXiaoRab 2009-11-13
  • 打赏
  • 举报
回复
On 32-bit platforms, the HRESULT data type is the same as the SCODE data type. On 16-bit platforms, an SCODE value is used to generate an HRESULT value.

An HRESULT value is made up of the following fields:

A 1-bit code indicating severity, where zero represents success and 1 represents failure.


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.
amatuer_feier 2009-11-13
  • 打赏
  • 举报
回复
再顶
amatuer_feier 2009-11-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 tr0j4n 的回复:]
放到同一目录下,然后直接调用

Like this

C/C++ code
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
...
[/Quote]
还是在hr = cpRecoGrammar->LoadCmdFromFile(L"email.xml", SPLO_DYNAMIC);
这个地方不通过,返回值hr为-2146697211(0x800c0005)
搞不懂这个返回值是什么意义
MoXiaoRab 2009-11-12
  • 打赏
  • 举报
回复
放到同一目录下,然后直接调用

Like this


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

amatuer_feier 2009-11-12
  • 打赏
  • 举报
回复
光顶没有,有人解答没?
qq14923349 2009-11-12
  • 打赏
  • 举报
回复

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧