iOS语音合成
苹果公司在iOS7中推出了语音合成的技术,无需网络环境也可以实现语音合成。
iOS7语音合成的主要的API如下:
1、AVSpeechUtterance,是语音合成的基本单位,它封装影响语音合成的需要的一些参数:语音、语调、语速和延迟等。
2、AVSpeechSynthesisVoice,是语音合成中的Voice对象,它主要包括语音和地区两个方面。
3、AVSpeechSynthesizer,语音合成器的管理类,通过speakUtterance:方法管理AVSpeechSynthesizer。
4、AVSpeechSynthesizerDelegate,是AVSpeechSynthesizer的委托协议。
代码如下:
#import "DemoVC36.h"
#import
@interface DemoVC36 ()@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UISlider *slider;
@property (nonatomic, strong) AVSpeechSynthesizer *speechSynthesizer;
@end
@implementation DemoVC36
- (void)viewDidLoad {
[super viewDidLoad];
//为TextView
[self.textView.layer setBorderWidth:0.5f];
[self.textView.layer setBorderColor:[UIColor grayColor].CGColor];
[self.textView setDelegate:self];
self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
self.speechSynthesizer.delegate = self;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
BOOL retval = TRUE;
if ([text isEqualToString:@"\n"]) {
[self.textView resignFirstResponder];
retval = FALSE;
}
return retval;
}
- (IBAction)speakButtonWasPressed:(UIButton *)sender {
NSString *str = @"wei fang is a handsome man";
AVSpeechUtterance *utt = [AVSpeechUtterance speechUtteranceWithString:str];
utt.rate = [self.slider value];
[self.speechSynthesizer speakUtterance:utt];
}
- (IBAction)speechSpeedShouldChange:(id)sender {
UISlider *slider = (UISlider *)sender;
NSInteger val = round(slider.value);
NSLog(@"%@",[NSString stringWithFormat:@"%ld",val]);
}
#pragma mark--AVSpeechSynthesizerDelegate
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didStartSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"语音合成开始");
}
-(void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer didFinishSpeechUtterance:(AVSpeechUtterance *)utterance{
NSLog(@"语音合成完成");
}
@end
iOS语音合成的更多相关文章
- iOS语音识别,语音播报,文字变语音播报,语音变文字
首先使用的是科大讯飞的sdk 1.语音识别部分 AppDelegate.m #import "AppDelegate.h" #import <iflyMSC/iflyMSC. ...
- IOS开发之语音合成(科大讯飞)详解
1.注册讯飞账号,申请APPID(注意选择IOS平台) 2.加载所需要的类库 3.导入所需要的类库文件头 4.调用申请的APPID以及所需函数,完成语音合成(需要参考官方给出的SDK文件) 详细步 ...
- [iOS]AVSpeechSynthesizer语音合成
#import <AVFoundation/AVFoundation.h> // 初始化方法 AVSpeechSynthesizer *speech = [[AVSpeechSynthes ...
- ios项目里扒出来的json文件
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...
- Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...
- IOS语音集成
1.注册讯飞账号,申请APPID(注意选择IOS平台) 2.加载所需要的类库 3.导入所需要的类库文件头 4.调用申请的APPID以及所需函数,完成语音合成(需要参考官方给出的SDK文件) 详细步 ...
- iOS及Mac开源项目和学习资料【超级全面】
UI 下拉刷新 EGOTableViewPullRefresh – 最早的下拉刷新控件. SVPullToRefresh – 下拉刷新控件. MJRefresh – 仅需一行代码就可以为UITable ...
- iOS 7新功能例子
参考https://github.com/shu223/iOS7-Sampler Code examples for the new functions of iOS 7. Contents Dyna ...
- iOS:iOS开发非常全的三方库、插件等等
iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...
随机推荐
- 新建虚拟目录使用UNC共享文件夹(即:虚拟目录使用UNC共享文件夹)的方法 -摘自网络
新建虚拟目录使用UNC共享文件夹(即:虚拟目录使用UNC共享文件夹)的方法1.UNC路径:\\192.168.1.2\test\,假设连接该UNC路径的用户名为:web,密码为:123 2.在原web ...
- voip的会议服务器Conference Servers
http://openmcu.ru/eng.htm openmcu: http://h323plus.cvs.sourceforge.net/viewvc/h323plus/application ...
- 优秀android开源项目与解决方案推荐
后来加上的,因为太强大了,android上百个可立即使用的开源库介绍:https://github.com/Trinea/android-open-project Android上的FTP服务器 S ...
- Apache Spark GraphX的简介
简单地说,GraphX是大规模图计算框架. GraphX 是 Spark 中的一个重要子项目,它利用 Spark 作为计算引擎,实现了大规模图计算的功能,并提供了类似 Pregel 的编程接口. Gr ...
- Ubuntu 下安装 Oracle Java
这只是一篇流水帐,记录如何安装Java. 在Ubuntu 下管理软件很方便,但安装的Java是opensdk.如果在某些条件下,需要安装Sun (Oracle)的Java,则需要自己手工安装. 一般情 ...
- CodeForces 689A Mike and Cellphone (模拟+水题)
Mike and Cellphone 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/E Description While sw ...
- Spring Autowiring @Qualifier example
In Spring, @Qualifier means, which bean is qualify to autowired on a field. See following scenario : ...
- 删除MySQL重复数据
删除MySQL重复数据 项目背景 在最近做的一个linux性能采集项目中,发现线程的程序入库很慢,再仔细定位,发现数据库里面很多冗余数据.因为在采集中,对于同一台设备,同一个时间点应该只有一个数据,然 ...
- FORTRAN程序设计权威指南
<FORTRAN程序设计权威指南> 基本信息 作者: 白海波 出版社:机械工业出版社 ISBN:9787111421146 上架时间:2013-7-23 出版日期:2013 年7月 ...
- Junit使用教程(二)
二.核心——断言 断言是编写测试用例的核心实现方式,即期望值是多少,测试的结果是多少,以此来判断测试是否通过. 1. 断言核心方法 assertArrayEquals(expecteds, actua ...