I have one weird requirement that in my existing app I have Text2Speech
and for that, I have used AVSpeechSynthesizer
to speech text, but now my client
There's two parts to a solution here...
Presumably you don't care about the formatting in the HTML--after all, by the time it gets to the speech synthesizer, this text is to be spoken, not viewed. AVSpeechSynthesizer
takes plain text, so you just need to get rid of the HTML markup. One easy way to do that is to create an NSAttributedString
from the HTML, then ask that attributed string for its underlying plain-text string to pass text to the synthesizer.
In iOS 10 you don't even have to extract the string from an attributed string — you can pass an attributed string directly to AVSpeechUtterance.