IOS Swift : UIAccessibilitySpeechAttributeIPANotation

筅森魡賤 提交于 2019-12-02 05:55:42

Try the code snippet hereafter (iOS 12 - Swift 5.0) :

let attrStr = NSMutableAttributedString(string: "hello my little ")

let pronunciationKey = NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute)
let attrStr2 = NSMutableAttributedString(string: "blablabla",
                                         attributes: [pronunciationKey: "ˈa͡ɪ.ˈfo͡ʊn"])

let finalAttrStr = NSMutableAttributedString()
finalAttrStr.append(attrStr)
finalAttrStr.append(attrStr2)

let utterance = AVSpeechUtterance(attributedString: finalAttrStr)
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")

let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)

This is not perfect but it makes the IPA notation work using AVSpeechSynthesizer.

Another example is also available to figure out how to get the phonemes and put them into the code.

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