iOS - iOS系统API创建文本到语言功能
来源:互联网 发布:网络统考成绩查询 编辑:程序博客网 时间:2024/06/18 08:43
首先导入#import <AVFoundation/AVFoundation.h>
使用其中的 AVSpeechSynthesizer 和 AVSpeechUtterance。
实现起来没有难度,下面贴.m文件代码
//// XYZfourViewController.m// leaf//// Created by command.Zi on 14/12/17.// Copyright (c) 2014年 command.Zi. All rights reserved.//#import "XYZfourViewController.h"@interface XYZfourViewController () { AVSpeechSynthesizer *av; AVSpeechUtterance * aaa;}@property (strong, nonatomic) IBOutlet UITextField *AField;- (IBAction)Abtn:(id)sender;- (IBAction)guoyu:(id)sender;- (IBAction)yueyu:(id)sender;@end@implementation XYZfourViewController- (void)viewDidLoad { [super viewDidLoad]; av = [[AVSpeechSynthesizer alloc]init]; aaa = [[AVSpeechUtterance alloc]init]; // Do any additional setup after loading the view. }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}/*#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller.}*/- (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];}@end
0 0
- iOS - iOS系统API创建文本到语言功能
- iOS文本@功能
- iOS 系统富文本
- iOS调用系统功能与跳转到系统设置
- iOS之利用系统自带API实现录音功能
- iOS 复制文本到剪切板
- IOS 系统常用功能
- iOS调用系统功能
- iOS调用系统功能
- iOS调用系统功能
- iOS调用系统功能
- iOS开发如何跳转到系统设置或功能?
- IOS系统原生富文本
- iOS创建系统TabBar
- iOS获取系统语言
- ios 判断系统语言
- 获取iOS系统语言
- ios富文本功能/文字特性设置
- Block声明,定义, 最基础的用法学习,很好的一篇文章
- EXT 设置样式
- UITextField,UITextView,UILabel 根据内容来计算高度
- 同步/异步,阻塞/非阻塞的个人小总结
- MapReduce二次排序
- iOS - iOS系统API创建文本到语言功能
- HTML5网络视频webm格式制作
- 【需求分析】jQuery EasyUI之Tabs
- 挑选商家
- 自构建工具TeamCity的安装及使用
- IOS在真机调试无法全屏显示,模拟器正常
- block使用小结、在arc中使用block、如何防止循环引用
- Swift 控制流
- 《刀塔传奇》付费设计分析