Stop AudioUnit speech

别等时光非礼了梦想. 提交于 2019-12-11 05:02:12

问题


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.

来源:https://stackoverflow.com/questions/44730756/stop-audiounit-speech

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!