2

I’m trying to integrate text to speech functionality in my iOS app.

For this I’m using AVSpeechUtterance and AVSpeechSynthesisVoice classes of AVFoundation framework.

extension String {
    func speech(with pronunciation: String) {
        let utterance = AVSpeechUtterance(attributedString: NSAttributedString(string: self, attributes: [.accessibilitySpeechIPANotation : pronunciation]))
        utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
        let synth = AVSpeechSynthesizer()
        DispatchQueue.main.async {
            synth.speak(utterance)
        }
    }
}

The problem I’m facing is with the pronunciation of wind word as verb and noun, i.e.

  1. wind as a verb is pronounced: waɪnd
  2. and wind as a noun is pronounced: wɪnd

The above pronunciation strings follow the International Phonetic Alphabet (IPA).

But, I’m not getting the expected results.