Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 29e420f

Browse files
author
Ian Macphail
committed
[[ Bug 21471 ]] Fix revIsSpeaking function on Windows
This patch updates the implementation of revIsSpeaking on Windows to replace the use of ISpVoice::GetStatus which does not return correct values when streaming speech to an audio output device. Instead, we now process speech events to determine when speaking starts & stops.
1 parent df34a44 commit 29e420f

File tree

2 files changed

+47
-8
lines changed

2 files changed

+47
-8
lines changed

revspeech/src/w32sapi5speech.cpp

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -390,19 +390,55 @@ bool WindowsSAPI5Narrator::Busy(void)
390390
if (!bInited)
391391
return false;
392392

393-
SPVOICESTATUS spstat;
394-
HRESULT hr = m_cpVoice->GetStatus(&spstat,NULL);
393+
if (!ProcessEvents())
394+
return false;
395395

396-
if( SUCCEEDED( hr ) )
396+
return isspeaking;
397+
}
398+
399+
inline void free_speech_event(SPEVENT &p_event)
400+
{
401+
switch (p_event.elParamType)
397402
{
398-
isspeaking = (spstat.dwRunningState & SPRS_IS_SPEAKING) != 0;
399-
400-
return isspeaking;
403+
case SPET_LPARAM_IS_POINTER:
404+
case SPET_LPARAM_IS_STRING:
405+
CoTaskMemFree(reinterpret_cast<void*>(p_event.lParam));
406+
break;
407+
case SPET_LPARAM_IS_TOKEN:
408+
case SPET_LPARAM_IS_OBJECT:
409+
reinterpret_cast<IUnknown*>(p_event.lParam)->Release();
410+
break;
401411
}
402-
else
403-
{
412+
MCMemoryClear(&p_event, sizeof(SPEVENT));
413+
}
414+
415+
bool WindowsSAPI5Narrator::ProcessEvents(void)
416+
{
417+
if (!bInited)
404418
return false;
419+
420+
SPEVENT t_event;
421+
ULONG t_fetched;
422+
HRESULT t_result = S_OK;
423+
while (t_result == S_OK)
424+
{
425+
t_result = m_cpVoice->GetEvents(1, &t_event, &t_fetched);
426+
if (t_result == S_OK)
427+
{
428+
switch (t_event.eEventId)
429+
{
430+
case SPEI_START_INPUT_STREAM:
431+
isspeaking = true;
432+
break;
433+
case SPEI_END_INPUT_STREAM:
434+
isspeaking = false;
435+
break;
436+
}
437+
free_speech_event(t_event);
438+
}
405439
}
440+
441+
return SUCCEEDED(t_result);
406442
}
407443

408444
// Parameters

revspeech/src/w32sapi5speech.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class WindowsSAPI5Narrator: public INarrator
6262
// Last Error Message
6363
char m_strLastError[256];
6464

65+
// Process events to track speech output status
66+
bool ProcessEvents(void);
67+
6568
// Internal Error Message
6669
void Error( WCHAR* pText ){wcscpy((WCHAR *)m_strLastError, pText); };
6770
void Error( WCHAR* pText, HRESULT hr){ sprintf(m_strLastError,"%s Error Code:0x%x", pText, hr); };

0 commit comments

Comments
 (0)