I'm trying to figure out how to use AVSpeechUtterance's attributed-string initializer with the AVSpeechSynthesisIPANotationAttribute attribute. These were added in iOS 10 but not fully documented.
I'm doing this in an iOS playground in Xcode 8.3:
import AVFoundation
import PlaygroundSupport
PlaygroundPage.current.needsIndefiniteExecution = true
let str = "North Lake Street"
let utterance = AVSpeechUtterance(string: str)
let synthesizer = AVSpeechSynthesizer()
synthesizer.speak(utterance)
let attrs: [String: Any] = [AVSpeechSynthesisIPANotationAttribute: NSNumber(value: 0)]
let ipa = "ˈnɔrθ ˈlek ˈstrit"
let ipaAttrib = NSMutableAttributedString(string: ipa, attributes: attrs)
let ipaUtterance = AVSpeechUtterance(attributedString: ipaAttrib)
synthesizer.speak(ipaUtterance)I was hoping that the second version would sound similar to the first, but it really doesn't sound very good.
Is there any guidance on what value to give the AVSpeechSynthesisIPANotationAttribute attribute? I've experimented with numbers and strings like "en" but haven't gotten good results.
`AVSpeechSynthesisIPANotationAttribute` has a simple header doc.
//NSString, containing International Phonetic Alphabet (IPA) symbols. Controls pronunciation of a certain word or phrase, e.g. a proper name.
So, its value needs to be a String, and the attribute needs to be added to a certain word or phrase.
You can write something like this.
let str = "North Lake Street"
let synthesizer = AVSpeechSynthesizer()
let ipaAttrib = NSMutableAttributedString(string: str)
ipaAttrib.addAttribute(AVSpeechSynthesisIPANotationAttribute, value: "laki", range: NSRange(6..<10))
let ipaUtterance = AVSpeechUtterance(attributedString: ipaAttrib)
synthesizer.speak(ipaUtterance)