博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
语音播报库AVFoundation
阅读量:3730 次
发布时间:2019-05-22

本文共 2321 字,大约阅读时间需要 7 分钟。

iOS7.0之后新添加了一些新的功能,里面就有系统自带的语音播报库, 需要 导入系统的AVFoundation 库

#import "ViewController.h" #import 
@interface ViewController ()
/** 播报的内容 */@property (nonatomic, readwrite , strong) AVSpeechSynthesizer *synth;/** 负责播放 */@property (nonatomic, readwrite , strong) AVSpeechUtterance *utterance; @end

基本使用

NSString *str = @"支付宝 到账 100万 元";self.utterance = [AVSpeechUtterance speechUtteranceWithString:str];//成功集成语音播报			//pitchMultiplier: 音高		//		//postUtteranceDelay: 读完一段后的停顿时间		//		//preUtteranceDelay: 读一段话之前的停顿		//rate: 读地速度, 系统提供了三个速度: AVSpeechUtteranceMinimumSpeechRate, AVSpeechUtteranceMaximumSpeechRate, AVSpeechUtteranceDefaultSpeechRate	self.utterance.rate = AVSpeechUtteranceDefaultSpeechRate;// 播报的语速			//	中式发音	AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];		//英式发音		//	AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-GB"];		self.utterance.voice = voice;		self.synth = [[AVSpeechSynthesizer alloc] init];	self.synth.delegate = self;// 设置代理	[self.synth speakUtterance:self.utterance];

代理方法

//已经开始- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) {	}//已经说完- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) { }//已经暂停- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didPauseSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) { }//已经继续说话- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didContinueSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) { }//已经取消说话- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didCancelSpeechUtterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) { }//将要说某段话- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance API_AVAILABLE(ios(7.0), watchos(1.0), tvos(7.0), macos(10.14)) { }

参考:https://blog.csdn.net/zjpjay/article/details/92840463

你可能感兴趣的文章
汇编语言 内部中断
查看>>
汇编语言 标志位
查看>>
汇编语言 ADC指令和SBB指令
查看>>
汇编语言 8086+8255A仿真中断控制
查看>>
汇编语言 CMP指令
查看>>
汇编语言 pushf 和 popf指令
查看>>
Java Set接口
查看>>
汇编语言 实现一个数字的平方
查看>>
Java 类反射
查看>>
汇编 SHL指令和SHR指令
查看>>
汇编 输入输出指令
查看>>
汇编语言 外部中断
查看>>
汇编语言 判断学生成绩是否及格
查看>>
汇编语言 ORG伪指令
查看>>
Xshell 连接 Ubuntu
查看>>
智能指针学习笔记
查看>>
MySQL8.0.19 Windows10安装
查看>>
Centos7 Docker安装
查看>>
SpringBoot2.x整合MyBatis
查看>>
Linux安装JDK1.8
查看>>