1、首先下载讯飞sdk及文档:http://open.voicecloud.cn/

2、学习里面的demo简单实现了一个小的语音识别功能

先做一个简单demo,看看识别效果。注:语音识别必须联网。

所有接口必需在联网状态下才能正常使用。

效果图:

#import <UIKit/UIKit.h>
#import "iflyMSC/IFlySpeechRecognizer.h"
#import "iflyMSC/IFlyDataUploader.h" @protocol SpeechAlertViewDelegate <NSObject>
@optional
- (void)getResultText:(NSString *)text;
@end @interface SpeechAlertView : UIAlertView<IFlySpeechRecognizerDelegate>
{
UIImageView *speechImage;//声音图片 IFlySpeechRecognizer * _iFlySpeechRecognizer;//语音识别对象
UIView *backgroundView;
}
@property (assign, nonatomic)id<SpeechAlertViewDelegate> speechDelegate;
@end
#import "SpeechAlertView.h"
#define APPID @"51de5743"
#define TIMEOUT @"20000"
// timeout 连接超时的时间,以ms为单位,毫秒,符号ms ,1000 毫秒 = 1秒,30000=30秒
//timeout:网络超时时间,单位:ms,默认为20000,范围0-30000
@implementation SpeechAlertView -(id)init
{
self = [super initWithFrame:CGRectMake(0, 0, 300, 220)];
if (self) {
// Initialization code
}
return self;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} //uialertview的大小位置
-(void)setFrame:(CGRect)frame{
//重新设置弹出框的大小和位置
UIWindow *window = [UIApplication sharedApplication].keyWindow; [super setFrame:CGRectMake((window.frame.size.width-self.frame.size.width)/2, (window.frame.size.height-self.frame.size.height)/2, self.frame.size.width, self.frame.size.height)];
}
//重新写界面内容
- (void) layoutSubviews {
//屏蔽系统的ImageView 和 UIButton
for (UIView *v in [self subviews]) {
if ([v class] == [UIImageView class]){
[v setHidden:YES];
} if ([v isKindOfClass:[UIButton class]] ||
[v isKindOfClass:NSClassFromString(@"UIThreePartButton")]) {
[v setHidden:YES];
}
} //添加背影图
UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
backView.backgroundColor = [UIColor colorWithRed:66/255.0 green:68/255.0 blue:70/255.0 alpha:1.0];
[self addSubview:backView]; //添加标题
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, backView.frame.size.width-20, 30)];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.text = @"语音识别";
titleLabel.font = [UIFont systemFontOfSize:16];
titleLabel.textColor = [UIColor colorWithRed:218.0/255.0 green:217.0/255.0 blue:217.0/255.0 alpha:1];
[backView addSubview:titleLabel]; //添加关闭按钮huati_close
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"alert_close.png"] forState:UIControlStateNormal];
[backView addSubview:button];
button.tag = 1;
button.frame = CGRectMake(backView.frame.size.width-25, 5, 20, 20);
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside]; //添加黄线
UIView *xianView = [[UIView alloc]initWithFrame:CGRectMake(0, 30, backView.frame.size.width, 1)];
xianView.backgroundColor = [UIColor yellowColor];
[backView addSubview:xianView]; //添加内容
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 35, backView.frame.size.width, 40)];
label.backgroundColor = [UIColor clearColor];
label.text = @"默认不讲话5秒后自动关闭,间隔不讲话2秒后关闭,最多说20秒";
label.font = [UIFont boldSystemFontOfSize:15];
label.textAlignment = UITextAlignmentCenter;
label.textColor = [UIColor yellowColor];
[backView addSubview:label];
label.numberOfLines = 0; //添加中间图片
speechImage = [[UIImageView alloc]initWithFrame:CGRectMake((self.frame.size.width-50)/2, 80, 50, 85)];
speechImage.image = [UIImage imageNamed:@"yuyin_01.png"];
[backView addSubview:speechImage]; //添加说完了按钮
UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeCustom]; submitButton.frame = CGRectMake((backView.frame.size.width-170)/2, 170, 150, 35);
submitButton.tag = 2;
[submitButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[submitButton setTitle:@"说完了" forState:UIControlStateNormal];
[submitButton setBackgroundImage:[UIImage imageNamed:@"alert_tButton.png"] forState:UIControlStateNormal];
[submitButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[backView addSubview:submitButton];
//想添加什么由此添加 //创建对象
NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@,timeout=%@",APPID,TIMEOUT];
//语音识别对象创建
_iFlySpeechRecognizer = nil;
_iFlySpeechRecognizer = [IFlySpeechRecognizer createRecognizer:initString delegate:self];
// _iFlySpeechRecognizer.delegate = self;
/*
2.vad_bos:静音超时时间,即用户多长时间不说话则当做超 时处理,单位:ms,engine 指定 sms 识别默认值为 5000,其他 情况默认值为 4000,范围 0-10000;
3.vad_eos:后端点静音检测时间,即用户停止说话多长时间 内即认为不再输入,自动停止录音,单位:ms,sms 识别默认 值为 1800,其他默认值为 700,范围 0-10000;
*/
[_iFlySpeechRecognizer setParameter:@"domain" value:@"sms"];
[_iFlySpeechRecognizer setParameter:@"sample_rate" value:@"16000"];
[_iFlySpeechRecognizer setParameter:@"plain_result" value:@"0"];
initString = nil; //开始识别
[_iFlySpeechRecognizer startListening]; }
//按钮处理方法
-(void) buttonClicked:(id)sender
{
[self dismissWithClickedButtonIndex:0 animated:YES]; } //显示
-(void)show
{
// [super show];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
backgroundView = [[UIView alloc]initWithFrame:window.frame];
backgroundView.backgroundColor = [UIColor clearColor];
[backgroundView addSubview:self];
[window addSubview:backgroundView];
}
//弹出框消失
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated
{
[_iFlySpeechRecognizer stopListening];
[_iFlySpeechRecognizer cancel];
[_iFlySpeechRecognizer setDelegate:nil];
_iFlySpeechRecognizer = nil;
speechImage = nil;
[backgroundView removeFromSuperview];
backgroundView = nil;
} #pragma mark - IFlySpeechRecognizerDelegate
- (void) onVolumeChanged: (int)volume
{
NSLog(@"%d",volume);
//录音的音量,音量范围1~100
if (volume>=0 &&volume<=5) {
speechImage.image = [UIImage imageNamed:@"yuyin_01.png"];
}else if(volume>5 && volume<=30){
speechImage.image = [UIImage imageNamed:@"yuyin_02.png"];
}else{
speechImage.image = [UIImage imageNamed:@"yuyin_03.png"];
}
} - (void) onBeginOfSpeech
{
NSLog(@"正在录音");
} - (void) onEndOfSpeech
{
NSLog(@"停止录音");
} - (void) onError:(IFlySpeechError *) error
{
NSLog(@"停止录音%@,%@",error,[error errorDesc]);
[self dismissWithClickedButtonIndex:0 animated:YES];
} //结果
- (void) onResults:(NSArray *) results
{
NSMutableString *result = [[NSMutableString alloc] init];
NSDictionary *dic = [results objectAtIndex:0];
for (NSString *key in dic) {
[result appendFormat:@"%@",key];
}
NSLog(@"转写结果:%@--results:%@",result,results); //返回结果
[_speechDelegate getResultText:result];
} @end

源码下载地址:

http://download.csdn.net/detail/rhljiayou/5889565

iphone之使用讯飞语音sdk实现语音识别功能的更多相关文章

  1. 继《关于讯飞语音SDK开发学习》之打包过程中遇到小问题

    关于讯飞语音SDK开发学习 使用vs自带打包,具体怎么操作就不说了,网上关于这方面的资料挺多的.例如:winform 打包部署,VS2010程序打包操作(超详细的),关键是桌面上创建快捷方式中的&qu ...

  2. 关于讯飞语音SDK开发学习

    前奏,浑浑噩噩已经工作一年多,这一年多收获还是挺多的.逛园子应该有两年多了,工作后基本上是天天都会来园子逛逛,园子 里还是有很多牛人写了一些不错的博客,帮我解决很多问题.但是一直没写过博客,归根到底一 ...

  3. 讯飞语音SDK Android平台使用

    1. 支持功能介绍: 2. Android API主要业务接口和流程介绍 -------------------------------------------------------- 工程代码: ...

  4. iOS: 讯飞语音的使用

    一.介绍: 讯飞语音做的相当不错,容错率达到90%多,如果需要做语音方面的功能,它绝对是一个不错的选择.讯飞语音的功能很多:语音听写.语音识别.语音合成等,但我们最常用的还是语音听写.讯飞语音中包含界 ...

  5. 讯飞语音唤醒SDK集成流程

    唤醒功能,顾名思义,通过语音,唤醒服务,做我们想做的事情. 效果图(开启应用后说讯飞语音或者讯飞语点唤醒) 源码下载 地址:http://download.csdn.net/detail/q48788 ...

  6. Android 讯飞语音听写SDK快速接入(附空指针解决和修改对话框文字方法)

    1.账号准备工作 首先要有一个讯飞的账号啦,为后面申请APPID.APPKey等东西做准备.顺带一提:讯飞对不同认证类型用户开 放的SDK的使用次数是有不同的,详情如下图. 账号申请完成后,需要去你自 ...

  7. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  8. Android讯飞语音云语音听写学习

    讯飞语音云语音听写学习         这几天两个舍友都买了iPhone 6S,玩起了"Hey, Siri",我依旧对我的Nexus 5喊着"OK,Google" ...

  9. android讯飞语音开发常遇到的问题

    场景:android项目中共使用了3个语音组件:在线语音听写.离线语音合成.离线语音识别 11208:遇到这个错误,授权应用失败,先检查装机量(3台测试权限),以及appid的申请时间(35天期限), ...

随机推荐

  1. iOS 9应用开发教程之显示编辑文本标签文本框

    iOS 9应用开发教程之显示编辑文本标签文本框 ios9显示.编辑文本 在iOS,经常会看到一些文本的显示.文字就是这些不会说话的设备的嘴巴.通过这些文字,可以很清楚的指定这些设备要表达的信息.本节将 ...

  2. leetcode 算法 Excel表列序号 python实现

    这道题给我感觉就像一个26进制数一样. A 就是1 B是2 .... Z 是26 如果AB 两位,那就是  1 * 26 + 2   就是A 的数值*26 + B的数值 如果是MNP 三位数   那就 ...

  3. PHP的钩子实现解析

    钩子是编程里一个常见的概念,非常的重要.它使得系统变得非常容易拓展(而不用理解其内部的实现机理,这样可以减少很多工作量).只要有一个钩子样本,能很容易仿照第一个钩子快速的编写第二个钩子,这里对钩子进行 ...

  4. codevs 2577 医院设置

    2577 医院设置 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold   题目描述 Description 设有一棵二叉树,如下图 其中,圈中数字表示结点居民的人口.圈边 ...

  5. Codeforces 1090J $kmp+hash+$二分

    题意 给出两个字符串\(s\)和\(t\),设\(S\)为\(s\)的任意一个非空前缀,\(T\)为\(t\)的任意一个非空前缀,问\(S+T\)有多少种不同的可能. Solution 看了一圈,感觉 ...

  6. wdcp(WDlinux Control Panel) 快速安装RPM包,lanmp一件安装

    lanmp一键安装包是wdlinux官网2010年开始推出的lamp,lnmp,lnamp(apache,nginx,php,mysql,zend,eAccelerator,pureftpd)应用环境 ...

  7. bzoj 1934 最小割

    收获: 1.流量为0的边可以不加入. 2.最小割方案要与决策方案对应. #include <cstdio> #include <cmath> #include <cstr ...

  8. visio2013 激活工具,仅供交流学习

    visio2013激活软件 环境是 win7, 64 bit 装了 visio 2013 , 可以却不能用它来画图,在网上找了一些破解工具,大都不能解决问题.网上不靠谱的广告型文章太多了 所幸,终于找 ...

  9. SQLite3知识(1)--教程

    1.SQLite3教程 [1].SQLite 教程 2.选择数据库: [2]. SQLite Select 语句 3.更新数据库: [3]. SQLite Update 语句 4.插入数据库: [4] ...

  10. paypal对接

    paypal支付接口准备工作 首先去申请一个paypal账号,https://www.paypal.com/. 申请完毕并登录,进入https://developer.paypal.com/devel ...