C ++ MSAPI 5: SetNotifyCallbackFunction no funciona
Así que he probado elMSAPI 5.4 TTS con ejemplo de evento. Ahora creo una aplicación de solicitud de cmd que utiliza SetNotifyCallbackFunction pero no se está llamando a la función que he pasado. No soy un experto en C ++, así que tengo dificultades para resolver esto. ¿Puede alguien dirigirme en la dirección correcta o al menos darme un buen ejemplo de SetNotifyCallbackFunction?
Aquí hay una versión simplificada de mi código:
typedef void __stdcall SPNOTIFYCALLBACK(WPARAM wParam, LPARAM lParam);
void __stdcall outsideeventFunction(WPARAM, LPARAM);
void __stdcall outsideeventFunction(WPARAM wParam, LPARAM lParam){
std::cout << "Event called::wParam: " << wParam << " lParam: " << lParam << std::endl;
SPEVENT eventItem;
memset(&eventItem, 0, sizeof(SPEVENT));
while (SUCCEEDED(pV->GetEvents(1, &eventItem, NULL)))
{
bool exitNa = false;
switch (eventItem.eEventId)
{
case SPEI_WORD_BOUNDARY:
SPVOICESTATUS eventStatus;
pV->GetStatus(&eventStatus, NULL);
ULONG start, end;
start = eventStatus.ulInputWordPos;
end = eventStatus.ulInputWordLen;
std::cout << "From event Test: " << start << ", " << end << std::endl;
std::cout << "From event Length: " << theString.length() - 1 << ", " << start + end << std::endl;
if (theString.length() - 1 <= start + end){
std::cout << "From event Exit!" << std::endl;
exitNa = true;
}
break;
}
SpClearEvent(&eventItem);
if (exitNa){
break;
}
}
return;
}
int _tmain(int argc, TCHAR* argv [], TCHAR* envp [])
{
pV = NULL;
std::string nativeString("Hello world, this is a test! For the purpose of a longer message, I'll add another sentence. And here comes the new sentence.");
SPNOTIFYCALLBACK *cb = &outsideeventFunction;
if (FAILED(::CoInitialize(NULL)))
return FALSE;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **) &pV);
if (SUCCEEDED(hr))
{
if (SUCCEEDED(pV->SetNotifyCallbackFunction(cb, 0, 0))){
std::cout << "Success adding callback" << std::endl;
}
ULONGLONG ullMyEvents = SPFEI(SPEI_WORD_BOUNDARY);
pV->SetInterest(ullMyEvents, ullMyEvents);
}
theString = std::wstring(nativeString.begin(), nativeString.end());
printf("Speak: %s\n", nativeString.c_str());
hr = pV->Speak(theString.c_str(), SPF_ASYNC, NULL);
pV->WaitUntilDone(INFINITE);
std::system("pause");
pV->Release();
pV = NULL;
::CoUninitialize();
return TRUE;
}
El resultado de esta aplicación es que la síntesis de palabras se realiza sin problemas, pero nunca se ha llamado a la función externa de evento. Como puede ver, el SetInterest está correctamente configurado. ¿Cómo puedo solucionar esto?