AVSpeechSynthesizer language synthesizer,
The speech synthesizer technology is launched by iOS7, which can implement the non-network speech function and support multiple languages.
1. import <AVFoundation/AVFoundation. h>
Define a member variable AVSpeechSynthesizer * _ synthesizer for language synthesis;
Define a member variable AVSpeechSynthesisVoice * _ voice, instantiate the language of speech (Chinese and English)
2. instantiate the language and initialize the language synthesizer.
// If the text content is Chinese, useZh_CN; if the text content is English, use en-US
;
_voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"]; //
Zh_CN Chinese
En-US English
// To recite the speech, a speech synthesizer is required to initialize the language synthesizer.
_synthesizer = [[AVSpeechSynthesizer alloc] init];
3. instantiate the voice object AVSpeechUtterance and specify the content to be read.
// Instantiate the AVSpeechUtterance object and specify the read content
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:_textView.text];
4. Specify the language and recitation speed
// Specify the language
Utterance. voice = _ voice;
// Speech speed
Utterance. rate = 0.3; // 0.1 Chinese characters. The English version is 0.3. The actual version prevails.
5. Start
[_synthesizer speakUtterance:utterance];