首页 > 技术文章 > 关于集成科大讯飞语音识别

cecely-clj 2016-07-13 09:11 原文

 一、添加静态库

⚠️将开发工具包中lib目录下地iflyMSC.framework添加到工程中去。

再添加如下图所示的库:

添加静态库

 

二、导入头文件

 1 #import <iflyMSC/IFlyRecognizerViewDelegate.h>
 2 #import <iflyMSC/IFlyRecognizerView.h>
 3   
 4 #import <iflyMSC/IFlySpeechRecognizerDelegate.h>
 5 #import <iflyMSC/IFlySpeechRecognizer.h>
 6   
 7 #import <iflyMSC/IFlySpeechUnderstander.h>
 8   
 9 #import <iflyMSC/IFlySpeechSynthesizerDelegate.h>
10 #import <iflyMSC/IFlySpeechSynthesizer.h>
11   
12 #import <iflyMSC/IFlyContact.h>
13 #import <iflyMSC/IFlyDataUploader.h>
14 #import <iflyMSC/IFlyUserWords.h>
15 #import <iflyMSC/IFlySpeechConstant.h>
16 #import <iflyMSC/IFlySpeechUtility.h>

三、初始化SDK

1 //在AppDelegate.m文件中的
2 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
3 
4 NSString *appid = @"53be3a59";
5     NSString *initString = [NSString stringWithFormat:@"appid=%@",appid];
6 [IFlySpeechUtility createUtility:initString];
7 
8 
9 }

四、语音听写(带界面)

 1  _iflyRecognizerView = [[IFlyRecognizerView alloc] initWithCenter:self.view.center];
 2    _iflyRecognizerView.delegate = self;
 3   [_iflyRecognizerView setParameter: @"iat" forKey: [IFlySpeechConstant IFLY_DOMAIN]];
 4     //asr_audio_path保存录音文件名,如不再需要,设置value为nil表示取消,默认目录是documents
 5     [_iflyRecognizerView setParameter:@"asrview.pcm " forKey:[IFlySpeechConstant ASR_AUDIO_PATH]];
 6      //设置数据返回的类型
 7     [_iflyRecognizerView setParameter:@"plain" forKey:[IFlySpeechConstant RESULT_TYPE]];
 8    //设置识别语言为英语
 9  [_iflyRecognizerView setParameter:@"en_us" forKey:[IFlySpeechConstant LANGUAGE]]; 
10   //设置识别语言为中文 普通话
11  [_iflyRecognizerView setParameter:@"zh_ch" forKey:[IFlySpeechConstant LANGUAGE]];
12          [_iflyRecognizerView setParameter:@"mandarin"forKey:[IFlySpeechConstant ACCENT]];
13 
14 - (void)onResult: (NSArray *)resultArray isLast:(BOOL) isLast
15 {
16     NSMutableString *result = [[NSMutableString alloc] init];
17     NSDictionary *dic = resultArray[0];
18 
19     for (NSString *key in dic) {
20        [result appendFormat:@"%@",key];
21     }
22     self.label.text = [NSString stringWithFormat:@"%@%@",self.label.text,result];
23     NSLog(@"self.textField.text = %@",self.textField.text);
24 
25 }
26 
27 /*识别会话错误返回代理
28  @ param  error 错误码
29  */
30 - (void)onError: (IFlySpeechError *) error
31 {
32 }
33 
34 
35 
36  
37  

 

推荐阅读