首先
#import <AVFoundation/AVFoundation.h>
于viewDidLoad中初始化
- (void)viewDidLoad {
[super viewDidLoad];
av = [[AVSpeechSynthesizer alloc]init];
aaa = [[AVSpeechUtterance alloc]init];
// Do any additional setup after loading the view.
}
实现方法
- (IBAction)Abtn:(id)sender {
NSString * astring = self.AField.text;
aaa = [AVSpeechUtterance speechUtteranceWithString:astring];
aaa.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CH"]; //语言
aaa.rate = 0.2; //语速
[av speakUtterance:aaa];
}
-(IBAction)backgroundTap:(id)sender {
[self.AField resignFirstResponder];
}
- (IBAction)yueyu:(id)sender {
[self seapkstring:@"zh-HK"];
}
- (IBAction)guoyu:(id)sender {
[self seapkstring:@"zh-CH"];
}
-(void)seapkstring:(NSString *)language {
NSString * astring = self.AField.text;
aaa = [AVSpeechUtterance speechUtteranceWithString:astring];
aaa.voice = [AVSpeechSynthesisVoice voiceWithLanguage:language]; //语言
aaa.rate = 0.2; //语速
[av speakUtterance:aaa];
}
本文详细记录了在iOS开发中使用AVSpeechSynthesizer和AVSpeechUtterance进行文本转语音操作的过程,包括设置发音者、调整语速和音调等关键步骤,帮助开发者实现自定义的语音合成功能。
690

被折叠的 条评论
为什么被折叠?



