0

I am using Xamarin.Mac, and I am writing a text to speech project.

In Xamarin.Mac, the class NSSpeechSynthesizer does not provide the event DidFinishSpeaking. May I know how I can get notified when the speaking is finished?

Thank you very much

SushiHangover
  • 73,120
  • 10
  • 106
  • 165

1 Answers1

0

NSSpeechSynthesizer provides a delegate in the form of an interface (INSSpeechSynthesizerDelegate) that contains the DidFinishSpeaking method:

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");
    }

    ~~~~~~
}
SushiHangover
  • 73,120
  • 10
  • 106
  • 165