I'm implementing a speech synthesizer using Audio Unit, based on the Core Audio examples. Everything works as expected, except that StopSpeech and StopSpeechAt appear to do nothing.
Here are the speak and stop methods:
void
Synthesizer::speak( const string &text )
{
mIsSpeaking = true;
mLastText = text;
NSString *ns_text = [NSString stringWithCString:text.c_str()
encoding:[NSString defaultCStringEncoding]];
CFStringRef cf_text = (__bridge CFStringRef)ns_text;
CheckError( SpeakCFString( mAuChannel, cf_text, NULL ), "SpeakCFString failed" );
}
void
Synthesizer::stop()
{
if ( isSpeaking() ) {
mStopRequested = true;
CheckError( StopSpeech( mAuChannel ), "StopSpeech failed" );
}
else {
mIsSpeaking = false;
}
}
I've verified that StopSpeech is called on the same thread as SpeakCFString. Oddly, when I try to step into the StopSpeech call with the debugger, it skips right over it. Really weirdly, the Speech Done callback is fired when StopSpeech is called, but the speech continues regardless.
Any idea what might be going on, or things I can do to debug? Is there some workaround I could use to disable the Audio Unit node temporarily?
This is on MacOS 10.12.5.