在MFC中,用微软的SPEECH SDK开发一个语音识别加控制的程序,
那个用OnRecoEvent(WPARAM wParam, LPARAM lParam)消息函数进行语音识别之后
用mouse_event控制鼠标的时候,不能继续识别语音了,就是不能让鼠标停止移动了!
关于这个应该怎么弄啊?
附语音控制部分代码:(红色部分为鼠标控制方面的,有问题!)
void CMainDlg::OnRecoEvent(WPARAM wParam, LPARAM lParam)
{
USES_CONVERSION;
CSpEvent event;
HRESULT hr = S_OK;
if(m_SREngine.m_cpRecoContext)
{
while(event.GetFrom(m_SREngine.m_cpRecoContext) == S_OK)
{
//Get the ID
switch(event.eEventId)
{
case SPEI_FALSE_RECOGNITION:
break;
case SPEI_HYPOTHESIS:
case SPEI_RECOGNITION:
{
CComPtr <ISpRecoResult> cpResult; CSpDynamicString dstrText;
CString strResult;
cpResult = event.RecoResult();
{
cpResult ->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &dstrText, NULL);
}
strResult = W2T(dstrText);
//::MessageBox(NULL, strResult, "teXT", MB_OK);
if(strResult == CString("关闭"))
{
OnOK();
}
else if(strResult == CString("向右") )
{
while(1)
{
mouse_event(MOUSEEVENTFMOVE,1,0,0,0);
Sleep(100);
if(strResult == CString("停止") )
{break;}
else continue;
} }
else if(strResult == CString("电脑") )
{
::MessageBox(NULL, "computer", "识别结果", MB_OK);
}
else if(strResult == CString("计算器") )
{
ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOWNORMAL);
}
cpResult.Release();
}
break;
default:
break;
}
}
}
}
那个用OnRecoEvent(WPARAM wParam, LPARAM lParam)消息函数进行语音识别之后
用mouse_event控制鼠标的时候,不能继续识别语音了,就是不能让鼠标停止移动了!
关于这个应该怎么弄啊?
附语音控制部分代码:(红色部分为鼠标控制方面的,有问题!)
void CMainDlg::OnRecoEvent(WPARAM wParam, LPARAM lParam)
{
USES_CONVERSION;
CSpEvent event;
HRESULT hr = S_OK;
if(m_SREngine.m_cpRecoContext)
{
while(event.GetFrom(m_SREngine.m_cpRecoContext) == S_OK)
{
//Get the ID
switch(event.eEventId)
{
case SPEI_FALSE_RECOGNITION:
break;
case SPEI_HYPOTHESIS:
case SPEI_RECOGNITION:
{
CComPtr <ISpRecoResult> cpResult; CSpDynamicString dstrText;
CString strResult;
cpResult = event.RecoResult();
{
cpResult ->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &dstrText, NULL);
}
strResult = W2T(dstrText);
//::MessageBox(NULL, strResult, "teXT", MB_OK);
if(strResult == CString("关闭"))
{
OnOK();
}
else if(strResult == CString("向右") )
{
while(1)
{
mouse_event(MOUSEEVENTFMOVE,1,0,0,0);
Sleep(100);
if(strResult == CString("停止") )
{break;}
else continue;
} }
else if(strResult == CString("电脑") )
{
::MessageBox(NULL, "computer", "识别结果", MB_OK);
}
else if(strResult == CString("计算器") )
{
ShellExecute(NULL,"open","calc.exe",NULL,NULL,SW_SHOWNORMAL);
}
cpResult.Release();
}
break;
default:
break;
}
}
}
}
解决方案 »
- 怎样让主线程在等待一个事情的同时(waitforsingleobject),还能够处理消息
- 紧急求救:CListView的三角箭头?
- 如何通过Class ID来访问象Edit,GroupBox这样的控件?
- GDI中關于分辨率﹑像素尺寸﹑字體大小的疑惑?????
- VC/MFC连库的简单问题?
- 关于组件的几个很菜的问题
- 怎样在一个线程中等待某一窗口的指定消息,并继续!在线等待。
- 生成bitmap文件
- 100分求可编译成功的myie源代码!谢谢![email protected]
- OpenGL矩形旋转时有一部分图形不见了
- 问两个activex 控件问题(tab和tooltip)
- TrackPopupMenuEx第一级菜单怎么没显示啊
这里面又是怎么处理的呢?
mouse_event是系统自带的WINAPI吧,具体原理不知道哦!
还有程序那个参数打错了,应该是MOUSEEVENTF_MOVE!
{
while(1)
{
mouse_event(MOUSEEVENTFMOVE,1,0,0,0);
Sleep(100); 在这里插入重新检测语音的
CComPtr <ISpRecoResult> cpResult; CSpDynamicString dstrText;
CString strResult;
cpResult = event.RecoResult();
{
cpResult ->GetText(SP_GETWHOLEPHRASE, SP_GETWHOLEPHRASE, TRUE, &dstrText, NULL);
}
strResult = W2T(dstrText);
if(strResult == CString("停止") )
{break;}
else continue;
} }
while循环会导致其他消息阻塞
建议 启动一个定时器 使用定时器消息来移动鼠标 很好的非阻塞操作方式