IOS Swift: UIAccessibilitySpeechAttributeIPANotation - PullRequest
0 голосов
/ 29 ноября 2018

Я пытаюсь заставить мое приложение говорить на IPANotation с использованием AVSpeechSynthesizer, но ниже не работает мой фрагмент кода,

let synthesizer = AVSpeechSynthesizer()

let attributedStr = NSMutableAttributedString(string: "Hello iPhone")
attributedStr.addAttribute(NSAttributedString.Key(UIAccessibilitySpeechAttributeIPANotation), value: "ˈa͡ɪ.ˈfo͡ʊn", range: NSRange(location: 6, length: 6))

let utterance = AVSpeechUtterance(attributedString: attributedString)
synthesizer.speak(utterence)

Спасибо

1 Ответ

0 голосов
/ 07 мая 2019

Попробуйте фрагмент кода здесь и далее (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)

Это не идеально, но заставляет нотацию IPA работать с использованием AVSpeechSynthesizer.

Другой пример также позволяет выяснить, как получить фонемы и ввести их в код.

...