Dhanesh Dhanesh - 1 year ago 56
HTML Question

is it possible to make "HTML to speech" same like "Text to speech"?

I have one wired requirement that in my exiting app I have

and for that I have used
to speech text, but now my client requirement he wants to speech
file as he has many
file in his

My Suggestion :

parsing and get all text from HTML and use same framework
for Text2Speech.

But client don't want that type of parsing and he wants any
or framework which is providing directly

Any suggestion or help will be highly appreciated.

Answer Source

As I have worked with HTML parsing and text2speech here you can go with 2 steps 1.get Attribute string from HTML file with below code works in iOS7+

As per your client perspective : if there is any API in market for HTML2Speech may be its Paid or you are depended on that API if you use any. While Native framework will help same what you/client wants.

Step 1:

[[NSAttributedString alloc] initWithData:[htmlString dataUsingEncoding:NSUTF8StringEncoding] 
                                 options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                           NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} 
                      documentAttributes:nil error:nil];

Then you can pass this Attributed String in AVSpeechUtterance

Step 2: use below method to get HTML2String:

 *  "ConvertHTMLtoStrAndPlay" : This method will convert the HTML to String 
 *  @param aURLHtmlFilePath : "object of html file path"

    if (synthesizer.speaking == NO && speechPaused == NO) {

        AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:aStrWithHTMLAttributes.string];
        //utterance.rate = AVSpeechUtteranceMinimumSpeechRate;

        if (IS_ARABIC) {
            utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"ar-au"];
            utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-au"];

        [synthesizer speakUtterance:utterance];
        [synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];

    if (speechPaused == NO) {
        [synthesizer continueSpeaking];
    } else {
        [synthesizer pauseSpeakingAtBoundary:AVSpeechBoundaryImmediate];


and as usual while you need to stop use below code to stop Speech.

 *  "StopPlayWithAVSpeechSynthesizer" : this method will stop the playing of audio on the application.

    // Do any additional setup after loading the view, typically from a nib.
    [synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];

Hope This will help you to get HTML2Speech feature.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download