Text-to- speech technology , also known as TTS, is the abbreviation for text to speech. iOS uses this technique when it wants to do features like audio books .
One, there are several points to note when using iOS to bring TTS:
- This function is only after iOS7
- Need Avfoundation Library
- Avspeechsynthesizer: Speech synthesizer, can be imagined as a person can speak, is the most important interface
- Avspeechsynthesisvoice: Can imagine an adult's voice
- Avspeechutterance: Can be imagined as a word to say
Two, code example, play voice
//Voice BroadcastAvspeechutterance *utterance = [avspeechutterance speechutterancewithstring:@"The moonlight before the bed, is suspected to be ground frost. "]; Utterance.pitchmultiplier=0.8; //Chinese pronunciationAvspeechsynthesisvoice *voice = [Avspeechsynthesisvoice voicewithlanguage:@"ZH-CN"]; //English pronunciation//avspeechsynthesisvoice *voice = [Avspeechsynthesisvoice voicewithlanguage:@ "EN-GB"];Utterance.voice=Voice; NSLog (@"%@", [Avspeechsynthesisvoice speechvoices]); Avspeechsynthesizer*synth =[[Avspeechsynthesizer alloc]init]; [Synth speakutterance:utterance];
Three, Avspeechsynthesizer introduction
This class is like a talking person, can "speak", can "pause" to speak, can "continue" to speak, you can determine whether he is currently speaking. The following methods or properties are available:
- Talk: Speakutterance
- Control: Continuespeaking (continued), Pausespeakingatboundary (Pause speaking), paused (properties of the paused state), speaking (speaking state), Stopspeakingatboundary ( Stop talking)
- Commissioned by: Delegate
Four, Avspeechboundary Introduction
This is an enumeration. In the pause, or stop talking, the way to stop is marked with this enumeration. Two types are included:
- Avspeechboundaryimmediate: Stop Now
- Avspeechboundaryword: Say an entire word and stop.
Five, Avspeechsynthesizerdelegate Introduction
The delegate for the synthesizer, for some events, provides the interface for the response.
- Didcancelspeechutterance: I've canceled my speech.
- Didcontinuespeechutterance: has continued to speak
- Didfinishspeechutterance: Already finished.
- Didpausespeechutterance: Already paused
- Didstartspeechutterance: Already started
- Willspeakrangeofspeechstring: Going to say a word
Six, Avspeechsynthesisvoice Introduction
Avspeechsynthesisvoice defines a range of sounds, mainly in different languages and regions.
- Voicewithlanguage: Get a voice based on the language you've developed.
- Speechvoices: Get the sound supported by the current device
- Currentlanguagecode: Gets the language string of the current sound, such as "ZH-CN"
- Language: Getting the current language
Seven, Avspeechutterance Introduction
This class is the one thing to say. The main properties and methods are:
- Pitchmultiplier: Pitch
- Postutterancedelay: Pause time after reading a paragraph
- Preutterancedelay: Pause before reading a passage
- Rate: Reading speed, the system offers three speeds: avspeechutteranceminimumspeechrate, avspeechutterancemaximumspeechrate, Avspeechutterancedefaultspeechrate
- Speechstring: the string to read
- Voice: The sound used is the Avspeechsynthesisvoice object
- Volume: Volume
Eight, UML diagram
The relationships of these classes are as follows:
Implementation of iOS Self-TTS technology: Voice broadcast