I'm trying to use AVSpeechSynthesizer with AVSpeechSynthesisIPANotationAttribute but it doesn't seem to work properly.
Here is the IPA notation for the pronunciation of the word "participation" taken from Wiktionary: pɑɹˌtɪsɪˈpeɪʃən. But AVSpeechSynthesizer does not read it correctly.
When I add a custom pronunciation using Settings -> Accessibility -> Spoken Content -> Pronunciations on my iPhone, it gives me this notation: pəɻ.ˈtɪ.sɪ.ˈpe͡ɪ.ʃən, which the iPhone reads correctly.
Why does "pəɻ.ˈtɪ.sɪ.ˈpe͡ɪ.ʃən" work but a string like "pɑɹˌtɪsɪˈpeɪʃən" that is taken from a dictionary does not?
Here is a sample code you can try:
import UIKit
import AVKit
class ViewController: UIViewController {
let synthesizer = AVSpeechSynthesizer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func buttonPressed(_ sender: Any) {
let pronunciationKey = NSAttributedString.Key(rawValue: AVSpeechSynthesisIPANotationAttribute)
let attrStr = NSMutableAttributedString(string: "foo",
attributes: [pronunciationKey: "pɑɹˌtɪsɪˈpeɪʃən"])
let utterance = AVSpeechUtterance(attributedString: attrStr)
synthesizer.speak(utterance)
}
}