NSSpeechSynthesizer讲完后如何收到通知?

时间:2017-07-03 04:22:35

标签: xamarin text-to-speech xamarin.mac

我正在使用Xamarin.Mac,我正在编写一个文本到语音项目。

Xamarin.Mac中,班级NSSpeechSynthesizer不提供事件DidFinishSpeaking。我可以知道如何在发言结束时收到通知吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

NSSpeechSynthesizer以接口(delegate)的形式提供INSSpeechSynthesizerDelegate,其中包含DidFinishSpeaking方法:

public partial class ViewController : NSViewController, INSSpeechSynthesizerDelegate
{
    ~~~~~~

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        var s = new NSSpeechSynthesizer(NSSpeechSynthesizer.DefaultVoice)
        {
            Delegate = this
        };
        s.StartSpeakingString("StackOverflow");
    }

    [Export("speechSynthesizer:didFinishSpeaking:")]
    public void DidFinishSpeaking(NSSpeechSynthesizer sender, bool finishedSpeaking)
    {
        Console.WriteLine("Done speaking");
    }

    ~~~~~~
}