导入框架:
#import <AVFoundation/AVFoundation.h>
#import <QuartzCore/QuartzCore.h>
.m 文件代码
NSString *str = @"Hello friend, how are you?";
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
AVSpeechUtterance *speechutt = [AVSpeechUtterance speechUtteranceWithString:strtext];
speechutt.volume=90.0f;
speechutt.rate=0.50f;
speechutt.pitchMultiplier=0.80f;
[speechutt setRate:0.3f];
speechutt.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-us"];
[synthesizer speakUtterance:speechutt];
任何语言的voiceWithLanguage 选项都支持这一点。
Arabic (Saudi Arabia) - ar-SA
Chinese (China) - zh-CN
Chinese (Hong Kong SAR China) - zh-HK
Chinese (Taiwan) - zh-TW
Czech (Czech Republic) - cs-CZ
Danish (Denmark) - da-DK
Dutch (Belgium) - nl-BE
Dutch (Netherlands) - nl-NL
English (Australia) - en-AU
English (Ireland) - en-IE
English (South Africa) - en-ZA
English (United Kingdom) - en-GB
English (United States) - en-US
French (Canada) - fr-CA
French (France) - fr-FR
Finnish (Finland) - fi-FI
German (Germany) - de-DE
Hindi (India) - hi-IN
Hungarian (Hungary) - hu-HU
Indonesian (Indonesia) - id-ID
Italian (Italy) - it-IT
Japanese (Japan) - ja-JP
Korean (South Korea) - ko-KR
Norwegian (Norway) - no-NO
Romanian (Romania) - ro-RO
Russian (Russia) - ru-RU
Slovak (Slovakia) - sk-SK
Spanish (Mexico) - es-MX
Swedish (Sweden) - sv-SE
Turkish (Turkey) - tr-TR