iOS provides a class Avspeechsynthesizer for text-to-speech functions, i.e., reading text
Directly on the code:
Avspeechsynthesizer *synthesizer =[[Avspeechsynthesizer alloc] init]; Nsarray*speechstrings = @[@"Hello AV Foundation. How is it?", @"I'm fine, thanks!", @"is excited about the book ?", @"Yes, I like this book very much.", @"What ' s your favourite feature?", @"I love it!", @"It was great to speak with you!", @"me too, wish you a happy"]; Nsarray*voices = @[[avspeechsynthesisvoice Voicewithlanguage:@"en -US"], [avspeechsynthesisvoice voicewithlanguage:@"ZH-CN"]]; for(inti =0; i < Speechstrings.count; i + +) {avspeechutterance*utterance =[[Avspeechutterance alloc] initwithstring:speechstrings[i]; Utterance.voice= voices[i%2];//languageUtterance.rate =0.4f;//speed of voice playbackUtterance.pitchmultiplier =0.8f;//TonesUtterance.postutterancedelay =0.1f;//next sentence time interval//pronunciation[synthesizer speakutterance:utterance]; }
ios-Text To Speech