The text-to-speech that comes with iOS is only available after iOS7 and requires the AVFoundation library.
AVSpeechSynthesizer: Speech synthesizer, which can be imagined as a person who can speak, is the main interface
AVSpeechSynthesisVoice: imaginary adult voice
AVSpeechUtterance: It can be imagined as a paragraph to say
Language Type : Language
ar-SA Saudi Arabia (Arabic)
en-ZA, South Africa (English)
nl-BE, Belgium (Dutch)
en-AU, Australia (English)
th-TH, Thailand (Thai)
de-DE, Germany (German)
en-US, United States (English)
pt-BR, Brazil (Portuguese)
pl-PL, Poland (Polish)
en-IE, Ireland (English)
el-GR, Greece (Greek)
id-ID, Indonesia (Indonesian)
sv-SE, Sweden (Swedish)
tr-TR, Turkey (Turkish)
pt-PT, Portugal (Portuguese)
ja-JP, Japan (Japanese)
ko-KR, South Korea (Korean)
hu-HU, Hungary (Hungarian)
cs-CZ, Czech Republic (Czech)
da-DK, Denmark (Danish)
es-MX, Mexico (Spanish)
fr-CA, Canada (French)
nl-NL, Netherlands (Dutch)
fi-FI, Finland (Finnish)
es-ES, Spain (Spanish)
it-IT, Italy (Italian)
he-IL, Israel (Hebrew, Arabic)
no-NO, Norway (Norwegian)
ro-RO, Romania (Romanian)
zh-HK, Hong Kong (Chinese)
zh-TW, Taiwan (Chinese)
sk-SK, Slovakia (Slovak)
zh-CN, China (Chinese)
ru-RU, Russia (Russian)
en-GB, United Kingdom (English)
fr-FR, France (French)
hi-IN India (Indic)
NSString *language = @"en-US"; AVSpeechSynthesizer *speechSynthesizer = [[AVSpeechSynthesizer alloc]init]; AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:language]; AVSpeechUtterance *utterance =[AVSpeechUtterance speechUtteranceWithString:text]; //Text to read utterance.voice = voice; utterance.rate = 0.5; //Speaking rate 0~1 utterance.pitchMultiplier = 0.5; //Pitch 0.5~2 utterance.volume =1.0; [speechSynthesizer speakUtterance:utterance];
There are also some methods provided by the proxy.
@protocol AVSpeechSynthesizerDelegate <NSObject> @optional - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance; - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance; - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance; - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance; - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance; - (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance; @end
iOS text-to-speech is relatively simple. It is worth noting that if you want to read a string of English letters such as dunnage alone, you need to add characters between each letter to separate them. "_" will separate letters and will not be read out, " ," will have a noticeable pause, but adding characters at the beginning will be read. Some letters may be recognized as words, such as qa, but cannot read qa, so just convert to uppercase QA.