您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页iOS_简单语音播报

iOS_简单语音播报

来源:二三四教育网

iOS 7之后,苹果新增了一个简单的 API ---- AVSpeechSynthesizer 来实现语音播报功能。

第一步:导入 AVFoundation/AVFoundation.h 系统库

#import <AVFoundation/AVFoundation.h>

第二步:设置播报参数


//初始化语音播报
AVSpeechSynthesizer * av = [[AVSpeechSynthesizer alloc]init];
//设置播报的内容
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc]initWithString:@"语音播报"];
//设置语言类别
AVSpeechSynthesisVoice * voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
utterance.voice = voiceType;
//设置播报语速
utterance.rate = 0.5;
[av speakUtterance:utterance];

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务