iOS语音播报文字
2016-02-19 14:39
609 查看
记得大学的时候学微软Window Phone时,有语音识别类似苹果的嘿,Siri.今天无聊百度搜了一下,搜到苹果语音播报文字。自己试了下还挺好玩。
1.引入框架#import <AVFoundation/AVFoundation.h>
2.获取系统当前语言
3.播放文字内容
4.注意: 在模拟器好像试实现不了,在真机测试很有意思,很好玩。
收集的一些AVFoundation资料:
http://www.cocoachina.com/ios/20150528/11966.html
1.引入框架#import <AVFoundation/AVFoundation.h>
2.获取系统当前语言
//获取当前系统语音 NSString *m_strLang=[[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
3.播放文字内容
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"我是谁? who is it?"];
utterance.rate *= 0.8;
AVSpeechSynthesizer *synth = [[AVSpeechSynthesizer alloc] init];
//获取当前系统语音 NSString *m_strLang=[[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
NSLog(@"%@",m_strLang);
NSString *preferredLang = @"";
if ([m_strLang isEqual: @"zh-Hans-CN"])
{
preferredLang = @"zh-CN";
}else{
preferredLang = @"en-US";
}
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:[NSString stringWithFormat:@"%@",preferredLang]];
utterance.voice = voice;
[synth speakUtterance:utterance];
4.注意: 在模拟器好像试实现不了,在真机测试很有意思,很好玩。
收集的一些AVFoundation资料:
http://www.cocoachina.com/ios/20150528/11966.html
相关文章推荐
- iOS 工程功能实现之好用的第三方
- iOS开发-事件处理
- iOS学习之Socket使用简明教程- AsyncSocket
- iOS类别(Category)与扩展(Extension)
- iOS开发中模糊效果的实现方案
- IOS NSPredicate 查询、搜索
- iOS8Extension之Today插件
- iOS 不规则的ImageView
- iOS 复杂动画的简单原理(一)
- iOS 斯坦福大学公开课地址
- ios AFNetworking 有用篇
- 关于苹果开发证书失效的解决方案(2016年2月14日Failed to locate or generate matching signing assets)
- iOS 此证书签发者无效 解决办法
- iOS @Strongify @Weakify
- iOS APP开发集成Apple Pay与银联SDK开发教程(附示例代码)
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)
- IOS中 Block简介与用法
- Missing iOS Distribution signing identity for XXXXXX
- iOS上传语音到服务器
- IOS开发基础知识--碎片34