iOS develops TTS technology that is text to voice
implementation of text-to-speech for iOS system
Before iOS7, it may be necessary for a third-party repository to implement voice broadcast text content. Now after iOS, the system provides us with the function of voice broadcast text, we can not only broadcast English content, can also broadcast the implementation of Chinese characters.
Tts[text to Speech]:
Rely primarily on avspeechsynthesizer,avspeechutterance,avspeechsynthesisvoice, and to use these classes you must first join the Avfoundation framework:
Avspeechsynthesisvoice: Used to configure pronunciation, support pronunciation is very much;
The [Avspeechsynthesisvoicespeechvoices] class method can be used to see the type of pronunciation supported;
Avspeechutterance: This class is used to make the string synthesis for the speech object to provide to the avspeechsynthesizer to play, this class also has some instance method to control the speed, the tone and so on.
Implementation code: The system implementation method is relatively simple, but need to be above iOS7, IOS7 before the general speech recognition is relying on some third-party libraries, or using Google Voice interface (described below)
Create a TextField, enter the text that will be played, create a button, and implement the text-to-speech
Self.textfield = [[Uitextfield alloc] Initwithframe:cgrectmake (M, M,)];
[Self.view AddSubview:self.textField]; Self.textField.borderStyle = 3;
Self.textField.placeholder = @ "Please enter text";
Self.button = [UIButton Buttonwithtype:uibuttontypesystem];
[Self.view AddSubview:self.button];
Self.button.frame = CGRectMake (M, 180, MB);
[Self.button settitle:@ "Voice playback" forstate:uicontrolstatenormal];
[Self.button addtarget:self Action: @selector (playstring:) forcontrolevents:uicontroleventtouchupinside];
Text To Speech method implementation code:
-(void) playstring: (UIButton *) button
{
if (![ Self.textField.text isequaltostring:@ ""]) {
avspeechutterance *utterance = [avspeechutterance SpeechUtteranceWithString:self.textField.text];
Avspeechsynthesisvoice *voice = [avspeechsynthesisvoice voicewithlanguage:@ ' ZH-CN '];//set language
Utterance.voice = Voice;
NSLog (@ "%@", [Avspeechsynthesisvoice speechvoices]);
Utterance.volume= 1; Set Volume (0.0~1.0) defaults to 1.0
utterance.rate= 0.01; Set speed
utterance.pitchmultiplier= 1.1; Set intonation
Avspeechsynthesizer *synth = [[Avspeechsynthesizer alloc]init];
[Synth speakutterance:utterance];
}
As far as I'm testing, iOS provides an interface that is more blunt and does not pause