iOS三句话实现文本转语音:AVSpeechSynthesizer
一、介绍
从iOS5开始,iOS系统已经在siri上集成了语音合成的功能,但是是私有API。但是在iOS7,新增了一个简单的API----AVSpeechSynthesizer来做这件事情。
二、案例
将AVFoundation.framework导入到你的工程里面;
#import "SpeechSynthesisViewController.h"
#import <AVFoundation/AVFoundation.h>
@property (nonatomic, strong) AVSpeechSynthesizer *synthesizer;
@implementation SpeechSynthesisViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
} - (IBAction)say
{ AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:"iOS7新特性"];
//设置语言类别(不能被识别,返回值为nil)
AVSpeechSynthesisVoice *voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
utterance.voice = voiceType;
//设置语速快慢
utterance.rate *= 0.5;
//语音合成器会生成音频
[self.synthesizer speakUtterance:utterance]; }
语言类别
iOS7包含了一组可以用来合成的声音的嗓音,你可以自定义多种嗓音来合成。
"[AVSpeechSynthesisVoice 0x978a0b0] Language: th-TH",
"[AVSpeechSynthesisVoice 0x977a450] Language: pt-BR",
"[AVSpeechSynthesisVoice 0x977a480] Language: sk-SK",
"[AVSpeechSynthesisVoice 0x978ad50] Language: fr-CA",
"[AVSpeechSynthesisVoice 0x978ada0] Language: ro-RO",
"[AVSpeechSynthesisVoice 0x97823f0] Language: no-NO",
"[AVSpeechSynthesisVoice 0x978e7b0] Language: fi-FI",
"[AVSpeechSynthesisVoice 0x978af50] Language: pl-PL",
"[AVSpeechSynthesisVoice 0x978afa0] Language: de-DE",
"[AVSpeechSynthesisVoice 0x978e390] Language: nl-NL",
"[AVSpeechSynthesisVoice 0x978b030] Language: id-ID",
"[AVSpeechSynthesisVoice 0x978b080] Language: tr-TR",
"[AVSpeechSynthesisVoice 0x978b0d0] Language: it-IT",
"[AVSpeechSynthesisVoice 0x978b120] Language: pt-PT",
"[AVSpeechSynthesisVoice 0x978b170] Language: fr-FR",
"[AVSpeechSynthesisVoice 0x978b1c0] Language: ru-RU",
"[AVSpeechSynthesisVoice 0x978b210]Language: es-MX",
"[AVSpeechSynthesisVoice 0x978b2d0] Language: zh-HK",
"[AVSpeechSynthesisVoice 0x978b320] Language: sv-SE",
"[AVSpeechSynthesisVoice 0x978b010] Language: hu-HU",
"[AVSpeechSynthesisVoice 0x978b440] Language: zh-TW",
"[AVSpeechSynthesisVoice 0x978b490] Language: es-ES",
"[AVSpeechSynthesisVoice 0x978b4e0] Language: zh-CN",
"[AVSpeechSynthesisVoice 0x978b530] Language: nl-BE",
"[AVSpeechSynthesisVoice 0x978b580] Language: en-GB",
"[AVSpeechSynthesisVoice 0x978b5d0] Language: ar-SA",
"[AVSpeechSynthesisVoice 0x978b620] Language: ko-KR",
"[AVSpeechSynthesisVoice 0x978b670] Language: cs-CZ",
"[AVSpeechSynthesisVoice 0x978b6c0] Language: en-ZA",
"[AVSpeechSynthesisVoice 0x978aed0] Language: en-AU",
"[AVSpeechSynthesisVoice 0x978af20] Language: da-DK",
"[AVSpeechSynthesisVoice 0x978b810] Language: en-US",
"[AVSpeechSynthesisVoice 0x978b860] Language: en-IE",
"[AVSpeechSynthesisVoice 0x978b8b0] Language: hi-IN",
"[AVSpeechSynthesisVoice 0x978b900] Language: el-GR",
"[AVSpeechSynthesisVoice 0x978b950] Language: ja-JP"
三、总结
在iOS7,语音合成器非常简单,多语言方便使用,可以提高应用的访问性,而不用时刻用你的手和眼来操作应用。
iOS三句话实现文本转语音:AVSpeechSynthesizer的更多相关文章
- 三句话看明白jdk收费吗
对于从oracle下载的jdk8:JDK8u200(含)以下版本不收费. 对于从oracle下载的jdk11:JDK 11.0.0不收费,JDK 11.0.1不收费. 对于openjdk:免费 ——— ...
- iOS7 文本转语音 AVSpeechSynthesizer
OS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xcode 5.0 工程建好后首先把AVFoundation.framework 加入到工程 AVSp ...
- iOS7 文本转语音 AVSpeechSynthesizer -转载-
http://www.cnblogs.com/qingjoin/p/3160945.html iOS7 的这个功能确实不错.我刚试了下,用官方提供的API ,简单的几句代码就能实现文本转语音! Xco ...
- 【Hadoop】三句话告诉你 mapreduce 中MAP进程的数量怎么控制?
1.果断先上结论 1.如果想增加map个数,则设置mapred.map.tasks 为一个较大的值. 2.如果想减小map个数,则设置mapred.min.split.size 为一个较大的值. 3. ...
- 【干货!!】三句话搞懂 Redis 缓存穿透、击穿、雪崩
前言 如何有效的理解并且区分 Reids 穿透.击穿和雪崩之间的区别,一直以来都挺困扰我的.特别是穿透和击穿,过一段时间就稀里糊涂的分不清了. 为了有效的帮助笔者自己,以及拥有同样烦恼的朋友们区分这三 ...
- UESTC - 1172 三句话题意
题目链接 记一个集合的gcd为该集合内所有数的最大公约数, 求一个给定集合的非空子集的gcd的k次方的期望~ Input 第一行有一个数t,表示数据组数 接下去每组数据两行,第一行两个数n,k(0 & ...
- iOS: 两句话给UILabel添加下划线
1. 将UILabel控件的Text属性设为Attributed 2. 在viewDidLoad方法中添加如下语句: NSDictionary *underlineAttribute = @{NSUn ...
- 三句话告诉你break、return、continue!
break:终止循环执行循环体下面的代码 return:终止循环并且退出循环所在的方法 continue:终止当前循环,进行下一次循环
- 三句话搞定FireDAC连接池
form上拖入: FDManager1: TFDManager; FDConnection1: TFDConnection; //初始化连接池procedure TForm1.InitDBPool;b ...
随机推荐
- spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
项目加入FeignClient后再启动就报错,具体报错信息如下: org.springframework.core.annotation.AnnotationConfigurationExceptio ...
- KMP 、扩展KMP、Manacher算法 总结
一. KMP 1 找字符串x是否存在于y串中,或者存在了几次 HDU1711 Number Sequence HDU1686 Oulipo HDU2087 剪花布条 2.求多个字符串的最长公共子串 P ...
- Hibernate写hql语句与不写hql语句的区别?
写hql语句与不写hql语句的区别? 写hql语句:书写HQL语句,所有的查询与投影的设计均使用HQL语句完成. 不写hql语句:没有任何查询语句,所有的查询与投影的设计使用面向对象格式完成. 二者选 ...
- codeforces 448B. Suffix Structures 解题报告
题目链接:http://codeforces.com/problemset/problem/448/B 题目意思:给出两种操作automaton:可以删除字符串中任意一个字符: array:交换字符串 ...
- codeforces 441B. Valera and Fruits 解题报告
题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...
- hdu-5721 Palace(最近点对)
题目链接: Palace Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- Linux下使用pip安装keras
Keras是一个底层使用Theano或TensorFlow的深度学习框架,它的设计参考了Torch,用Python语言编写,也很方便使用Python调用,是一个高度模块化的神经网络库,支持使用GPU和 ...
- windows下编译调试nginx
typora-copy-images-to: image windows下编译调试nginx linux使用gdb跟踪代码效率不高,在通过跟踪代码进行源码分析,与定位复杂逻辑问题时,如果有一个简单易用 ...
- GridFS大文件的添加、获取、查看、删除
GridFS是一种在MongoDB中存储大二进制文件的机制,使用GridFS的原因有以下几种: 存储巨大的文件,比如视频.高清图片等. 利用GridFS可以简化需求. GridFS会直接利用已经建立的 ...
- CoreGpaphics
CoreGpaphics基本应用 CGAffineTransformMake开头的函数 是基于最初始的位置来变化的 带有CGAffineTransform参数是基于CGAffineTransform的 ...