i have 1 wired requirement in exiting app have text2speech
, have used avspeechsynthesizer
speech text, client requirement wants speech html
file has many html
file in db
.
my suggestion :
use
html
parsing , text html , use same framework text2speech.
but client don't want type of parsing , wants api
or framework providing directly html2speech
feature.
any suggestion or highly appreciated.
as have worked html parsing , text2speech here can go 2 steps 1.get attribute string html file below code works in ios7+
as per client perspective : if there api in market html2speech may paid or depended on api if use any. while native framework same you/client wants.
step 1:
[[nsattributedstring alloc] initwithdata:[htmlstring datausingencoding:nsutf8stringencoding] options:@{nsdocumenttypedocumentattribute: nshtmltextdocumenttype, nscharacterencodingdocumentattribute: @(nsutf8stringencoding)} documentattributes:nil error:nil];
then can pass attributed string in avspeechutterance
step 2: use below method html2string:
/** * "converthtmltostrandplay" : method convert html string synthesizer. * * @param aurlhtmlfilepath : "object of html file path" */ -(void)converthtmltostrandplay:(uibutton*)abtnplaypause isspeechpaused:(bool)speechpaused stringwithhtmlattributes:(nsattributedstring*)astrwithhtmlattributes { 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"]; }else{ utterance.voice = [avspeechsynthesisvoice voicewithlanguage:@"en-au"]; } [synthesizer speakutterance:utterance]; } else{ [synthesizer pausespeakingatboundary:avspeechboundaryimmediate]; } if (speechpaused == no) { [synthesizer continuespeaking]; } else { [synthesizer pausespeakingatboundary:avspeechboundaryimmediate]; } }
and usual while need stop use below code stop speech.
/** * "stopplaywithavspeechsynthesizer" : method stop playing of audio on application. */ -(void)stopplaywithavspeechsynthesizer{ // additional setup after loading view, typically nib. [synthesizer stopspeakingatboundary:avspeechboundaryimmediate]; }
hope html2speech feature.
Comments
Post a Comment