Search code examples
xamarinxamarin.iosaccessibilityavspeechsynthesizer

iOS what is the value of accessibilitySpeechIPANotation


Based on this WWDC2018 video, we can dynamically change how words are pronounced in AVSpeechSynthesizer. enter image description here

I'm trying to do that in my Xamarin App, but I can't find the accessibilitySpeechIPANotation constant.

In the doc of NSMutableAttributedString.AddAttribute(...) it says that the constants can be found here: UIKit.UIStringAttributeKey. Yet the one I'm looking for isn't there.

Does anyone know what the actual string value of the constant is? Or even better, where I can find in in Xamarin.iOS?

(My app uses xamarin.ios v4.0.30319, if the constant is in a newer version of the framework, I'll update it, but google doesn't seem to give me any result when I search for it.)


Solution

  • Cause: Xamarin for iOS is based on Objective-C.And there are some differences between swift and Objective-C.

    Solution: The code is just like the following :

    var attriStrng = new NSMutableAttributedString(new NSString("hello iPhone"));
    // you can set the voice here ,a͡͡a͡͡a͡͡a͡͡a͡͡ is just for testing
    attriStrng.AddAttribute(new NSString("AVSpeechSynthesisIPANotationAttribute"), new NSString("ˈa͡͡a͡͡a͡͡a͡͡a͡͡a͡͡a͡͡.ˈfo͡ʊn"),new NSRange(6,6));
    
    var voice = new AVSpeechUtterance(attriStrng);
    
    AVSpeechSynthesizer synthesizer = new AVSpeechSynthesizer();
    synthesizer.SpeakUtterance(voice);