The implementation of TTS technology in iOS is voice broadcast and iostts.
Text-To-Speech technology, also known as TTS, is short for Text To Speech. This technology is used when iOS wants To implement functions such as voicebooks.
I. Notes for using TTS in iOS:
Ii. code example: Play voice
// Voice broadcast AVSpeechUtterance * utterance = [AVSpeechUtterance speechUtteranceWithString: @ "Moonlight in front of the bed, suspected to be frost on the ground. "]; Utterance. pitchMultiplier = 0.8; // Chinese pronunciation: audio * voice = [AVSpeechSynthesisVoice voiceWithLanguage: @ "zh-CN"]; // english pronunciation // AVSpeechSynthesisVoice * voice = [audio voiceWithLanguage: @ "en-GB"]; utterance. voice = voice; NSLog (@ "% @", [descrispeechvoices]); AVSpeechSynthesizer * synth = [[AVSpeechSynthesizer alloc] init]; [synth speakUtterance: utterance];
3. AVSpeechSynthesizer Introduction
This class is like a talking person. He can "speak", "pause", and "continue". He can judge whether he is talking. there are the following methods or attributes:
- Speaker: speakUtterance
- Control: continueSpeaking, pauseSpeakingAtBoundary, paused, speaking, stopSpeakingAtBoundary)
- Delegate: delegate
4. AVSpeechBoundary Introduction
This is an enumeration. When you pause or stop talking, you can use this enumeration to mark the stop. There are two types:
- AVSpeechBoundaryImmediate: stop now
- AVSpeechBoundaryWord
V. AVSpeechSynthesizerDelegate
Synthesizer delegation provides Response interfaces for some events.
- DidCancelSpeechUtterance: the message has been canceled.
- DidContinueSpeechUtterance: continue talking
- DidFinishSpeechUtterance: Completed
- DidPauseSpeechUtterance: paused
- DidStartSpeechUtterance: started
- WillSpeakRangeOfSpeechString: to say something
Vi. AVSpeechSynthesisVoice Introduction
AVSpeechSynthesisVoice defines a series of sounds, mainly in different languages and regions.
- VoiceWithLanguage: gets a sound based on the language.
- SpeechVoices: Voice supported by the current device
- CurrentLanguageCode: gets the language string of the current sound, such as "ZH-cn"
- Language: Obtain the current language.
VII. AVSpeechUtterance
The main attributes and methods are as follows:
- PitchMultiplier: Pitch
- PostUtteranceDelay: The pause time after reading a paragraph
- PreUtteranceDelay: The pause before reading a paragraph
- Rate: read speed. The system provides three speeds: AVSpeechUtteranceMinimumSpeechRate, AVSpeechUtteranceMaximumSpeechRate, avspeechutterancedefaspeechrate
- SpeechString: the string to be read
- Voice: the voice used. It is an AVSpeechSynthesisVoice object.
- Volume: volume
8. UML Relationship Diagram
The relationships between these classes are as follows: