各位大俠幫菜鳥看個問題吧,謝謝大俠們了
想在speech sdk上先寫個控制臺的語音識別但在設定識別訊息函式出錯了,不知道為啥額,求大師幫忙看下吧 #include<sapi.h>
#include<atlbase.h>
#include<sphelper.h>
#include<windef.h>
#include<Tchar.h>
void main()
{
::CoInitialize(NULL);
char str[100];
GetConsoleTitle(str,sizeof(str));
HWND hwnd=FindWindow(NULL,str);
CComPtr<ISpRecognizer> ir;
HRESULT hr=ir.CoCreateInstance(CLSID_SpInprocRecognizer);
if(SUCCEEDED(hr))
{
CComPtr<ISpObjectToken> ia;
hr=SpGetDefaultTokenFromCategoryId(SPCAT_AUDIOIN, &ia,TRUE);
if(SUCCEEDED(hr))
{
hr = ir->SetInput(ia, TRUE);
CComPtr<ISpRecoContext> ic;
if(SUCCEEDED(hr))
{
hr=ir->CreateRecoContext(&ic);
CComPtr<ISpEventSource> ie;
hr=ie->SetNotifyWindowMessage(hwnd,WM_LBUTTONDOWN,0,0);
}
}
}
::CoUninitialize();
}
ie->SetNotifyWindowMessage(hwnd,WM_LBUTTONDOWN,0,0);為啥運行到這會有問題啊
uj5u.com熱心網友回復:
不懂speech,不過你倒是得說說有啥問題啊,如果是錯誤有啥錯誤提示
uj5u.com熱心網友回復:
ISpNotifySource::SetNotifyWindowMessage告訴Windows哪個是我們的識別訊息
HRESULT SetNotifyWindowMessage(
HWND hWnd,
UINT Msg,
WPARAM wParam,
LPARAM lParam
);
引數:
hWnd:是主視窗(或者接收訊息的視窗)句柄。
Msg:是用戶自定義訊息。
wParam:[in] wParam that will be passed into the message handler function of the window hWnd.
lParam:[in] lParam that will be passed into the message handler function of the window hWnd.
回傳值:
Value Description
S_OK Function completed successfully.
E_INVALIDARG hWnd is an invalid window handle.
FAILED (hr) Appropriate error message.
uj5u.com熱心網友回復:

除錯到這步就出現圖中情況了,hwnd是我之前已經得到的控制臺句柄,第二引數我設為了按滑鼠的左鍵的訊息id了。但是為什么這個情況不懂啊。謝謝了
uj5u.com熱心網友回復:
p!=0 斷言失敗,這個p不知是啥你檢查下CComPtr<ISpEventSource> ie 是否為null,或 hwnd 是否為0
uj5u.com熱心網友回復:
謝謝大俠。
ie用ccomptr建立貌似不成功,原因不明白,其他的一些spai的介面貌似可以成功建立。看了speech sdk的幫助檔案貌似沒有對ispeventsource實體化的說明,或許是我理解的膚淺,謝謝大師了。
ISpNotifySource
In both speech synthesis and speech recognition, applications receive notifications when words have been spoken or when phrases have been recognized. SAPI components that generate notifications implement an ISpNotifySource.
The ISpNotifySource and ISpNotifySink interfaces alone only provide a mechanism for a notification but no information on the events that caused the notification. With an ISpEventSource object, an application can retrieve information about the events that caused the notification.
Applications will not typically use the free-threaded ISpNotifySink mechanism for receiving SAPI event notifications. They will use one of the simplified methods of either a window message, callback or Win32 event.
Note that both variations of callbacks as well as the window message notification require a window message pump to run on the thread that initialized the notification source. Callback will only be called as the result of window message processing, and will always be called on the same thread that initialized the notify source. However, using Win32 events for SAPI event notification does not require a window message pump.
uj5u.com熱心網友回復:
或許是Note that both variations of callbacks as well as the window message notification require a window message pump to run on the thread that initialized the notification source.?但是不太明白和ispeventsource的建立問題。
uj5u.com熱心網友回復:
學習一下哈哈uj5u.com熱心網友回復:
你本機裝speech的安裝檔案了嗎?轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/133521.html
上一篇:請教一個ADO遠程查詢資料庫的問題:一條SQL查詢有10萬條記錄,請問這個結果是如何放回的?
下一篇:如何判斷缺少運行時DLL
