一、介紹:
訊飛語音做的相當不錯,容錯率達到90%多,如果需要做語音方面的功能,它絕對是一個不錯的選擇。訊飛語音的功能很多:語音聽寫、語音識別、語音合成等,但我們最常用的還是語音聽寫。訊飛語音中包含界面的語音聽寫和不帶界面的語音聽寫,下面我來演示一下。
二、准備工作:
(1)去訊飛語音開發平台注冊賬號並登陸,然后在控制台創建應用,獲取對應的app id,這個以后使用它注冊激活訊飛語音。
(2)下載訊飛語音SDK,將其拖入到項目中,然后添加需要所有的依賴庫,另外還有新添加庫Contacts.framework,編譯運行即可。
(3)引入頭文件,以及遵從代理,激活訊飛語音,並實現功能。
三、BitCode 設置
在 Xcode 7 默認開啟了 Bitcode,Bitcode 需要工程依賴的類庫同時支持。而語記 SDK 暫時還不支持Bitcode,所以可以先臨時關閉。后續支持 Bitcode 請關注訊飛開放平台版本更新,QQ 群中也會醒。在 Targets - Build Settings 中搜索 Bitcode 即可,找 到相應選項,設置為 NO。
四、演示:
第一種不帶界面的語音聽寫:
DDHomeSearchViewController.m
#import <UIKit/UIKit.h> #import "iflyMSC/iflyMSC.h" #import "iflyMSC/IFlySpeechRecognizerDelegate.h" #import "iflyMSC/IFlySpeechRecognizer.h" @interface DDHomeSearchViewController : UIViewController<IFlySpeechRecognizerDelegate> @property (nonatomic, strong) IFlySpeechRecognizer *iFlySpeechRecognizer; //不帶界面的識別對象 @end //初始化Appid -(void)initAppId { NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",@"xxxxxxx"]; [IFlySpeechUtility createUtility:initString]; } //初始化識別器 -(void)initRecognizer { //單例模式,無UI的實例 if (_iFlySpeechRecognizer == nil) { _iFlySpeechRecognizer = [IFlySpeechRecognizer sharedInstance]; } // 設置參數 if (_iFlySpeechRecognizer != nil) { //擴展參數 [_iFlySpeechRecognizer setParameter:@"" forKey:[IFlySpeechConstant PARAMS]]; //設置聽寫模式 [_iFlySpeechRecognizer setParameter:@"iat" forKey:[IFlySpeechConstant IFLY_DOMAIN]]; //設置最長錄音時間 [_iFlySpeechRecognizer setParameter:@"30000" forKey:[IFlySpeechConstant SPEECH_TIMEOUT]]; //設置后端點 [_iFlySpeechRecognizer setParameter:@"1800" forKey:[IFlySpeechConstant VAD_EOS]]; //設置前端點 [_iFlySpeechRecognizer setParameter:@"1800" forKey:[IFlySpeechConstant VAD_BOS]]; //網絡等待時間 [_iFlySpeechRecognizer setParameter:@"20000" forKey:[IFlySpeechConstant NET_TIMEOUT]]; //設置采樣率,推薦使用16K [_iFlySpeechRecognizer setParameter:@"16000" forKey:[IFlySpeechConstant SAMPLE_RATE]]; //設置語言 [_iFlySpeechRecognizer setParameter:@"zh_cn" forKey:[IFlySpeechConstant LANGUAGE]]; //設置方言 [_iFlySpeechRecognizer setParameter:@"mandarin" forKey:[IFlySpeechConstant ACCENT]]; //設置是否返回標點符號 [_iFlySpeechRecognizer setParameter:@"1" forKey:[IFlySpeechConstant ASR_PTT]]; //設置數據返回格式 [_iFlySpeechRecognizer setParameter:@"plain" forKey:[IFlySpeechConstant RESULT_TYPE]]; } // 設置代理 _iFlySpeechRecognizer.delegate = self; } //實現代理方法 // 出現錯誤 - (void) onError:(IFlySpeechError *) error { NSLog(@"出現錯誤 :%@",error); } // 識別結果 - (void) onResults:(NSArray *) results isLast:(BOOL)isLast { NSMutableString *result = [[NSMutableString alloc] init]; NSDictionary *dic = [results objectAtIndex:0]; for (NSString *key in dic) { [result appendFormat:@"\n\n------ %@ (置信度:%@) ------ \n\n",key,[dic objectForKey:key]]; } // 忽略結束。號 if ([result hasPrefix:@"\n\n------ 。"]) { return; } NSLog(@"%@",result); } //點擊開始和結束 - (IBAction)understand:(id)sender { // 開始識別 [_iFlySpeechRecognizer startListening]; } - (IBAction)finish:(id)sender { // 停止識別 [_iFlySpeechRecognizer stopListening]; } //初始化 - (void)viewDidLoad { [super viewDidLoad]; [self initAppId]; [self initRecognizer]; }
演示結果:
2015-12-31 01:09:15.687 fa[23747:446296] [IFLYTEK] -[IFlySpeechUtility login],login=0 2015-12-31 01:09:15.720 fa[23747:446296] [IFLYTEK] +[IFlySystemInfo getWorkPath],_gMscLogPath=(null) 2015-12-31 01:09:15.723 fa[23747:446296] [IFLYTEK] login -[IFlyLoginParam toString:] SessionParam:timeout=20000,appid=567f981a,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,work_dir=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Data/Application/4C7C4E0A-9A1A-4063-8068-B8978BC7D946/Library/Caches,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:15.723 fa[23747:446296] [IFLYTEK] paramString: timeout=20000,appid=567f981a,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,work_dir=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Data/Application/4C7C4E0A-9A1A-4063-8068-B8978BC7D946/Library/Caches,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:15.726 fa[23747:446296] [IFLYTEK] login in 2015-12-31 01:09:15.726 fa[23747:446296] [IFLYTEK] +[IFlySpeechRecognizer sharedInstance][IN],iflyInstance=0 2015-12-31 01:09:15.726 fa[23747:446296] [IFLYTEK] +[IFlySpeechRecognizer sharedInstance][OUT],iflyInstance=53658592 2015-12-31 01:09:20.069 fa[23747:446296] [IFLYTEK] -[IFlySpeechRecognizer startListening][IN] 2015-12-31 01:09:20.070 fa[23747:446296] [IFLYTEK] isr SessionParam:engine_type=cloud,sub=iat,language=zh_cn,plr=0,audio_source=1,vad_speech_tail=1800,msc.skin=0,rse=utf8,asr_audio_path=record.pcm,sample_rate=16000,timeout=20000,domain=iat,speech_timeout=30000,vad_timeout=1800,vad_bos=1800,rst=plain,vad_eos=1800,auf=audio/L16;rate=16000,ptt=1,voice_change=0,sch=0,accent=mandarin,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:20.070 fa[23747:446296] [IFLYTEK] params=engine_type=cloud,sub=iat,language=zh_cn,plr=0,audio_source=1,vad_speech_tail=1800,msc.skin=0,rse=utf8,asr_audio_path=record.pcm,sample_rate=16000,timeout=20000,domain=iat,speech_timeout=30000,vad_timeout=1800,vad_bos=1800,rst=plain,vad_eos=1800,auf=audio/L16;rate=16000,ptt=1,voice_change=0,sch=0,accent=mandarin,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:20.070 fa[23747:446296] [IFLYTEK] grammarid=(null) 2015-12-31 01:09:20.070 fa[23747:446296] [IFLYTEK] audioSource=1 2015-12-31 01:09:20.070 fa[23747:446296] [IFLYTEK] isListening:NO 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] -[IFlySpeechRecognizer startListening:grammar:][IN] 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] _mscer count0=1 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] iflySpeechQueue0=1 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] _mscer count2=3 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] _mscer count3=2 2015-12-31 01:09:20.071 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer main][IN],self=53528272 2015-12-31 01:09:20.071 fa[23747:446296] [IFLYTEK] iflySpeechQueue1=3 2015-12-31 01:09:20.072 fa[23747:446296] [IFLYTEK] -[IFlySpeechRecognizer startListening:grammar:][OUT] 2015-12-31 01:09:20.072 fa[23747:446296] [IFLYTEK] params: engine_type=cloud,sub=iat,language=zh_cn,plr=0,audio_source=1,vad_speech_tail=1800,msc.skin=0,rse=utf8,asr_audio_path=record.pcm,sample_rate=16000,timeout=20000,domain=iat,speech_timeout=30000,vad_timeout=1800,vad_bos=1800,rst=plain,vad_eos=1800,auf=audio/L16;rate=16000,ptt=1,voice_change=0,sch=0,accent=mandarin,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:20.072 fa[23747:446296] [IFLYTEK] startListening audioSource:1 2015-12-31 01:09:20.072 fa[23747:446296] [IFLYTEK] -[IFlySpeechRecognizer runService][OUT] 2015-12-31 01:09:20.072 fa[23747:446296] [IFLYTEK] -[IFlySpeechRecognizer startListening][OUT] 2015-12-31 01:09:20.072 fa[23747:446340] [IFLYTEK] Converted String : 2016/12/31 01:09:20 072 2015-12-31 01:09:20.073 fa[23747:446296] [IFLYTEK] -[IFlyMscRecognizer startRecord][IN] 2015-12-31 01:09:20.073 fa[23747:446296] [IFLYTEK] +[IFlyAudioSession initRecordingAudioSession] 2015-12-31 01:09:20.074 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder setSample:],rate=16000 2015-12-31 01:09:20.074 fa[23747:446296] [IFLYTEK] +[IFlySystemInfo getWorkPath],_gMscLogPath=(null) 2015-12-31 01:09:20.074 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder start],[IN] 2015-12-31 01:09:20.124 fa[23747:446296] [IFLYTEK] pcmRecorder|timeValue:0.049352 2015-12-31 01:09:20.124 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder start],[OUT],ret =0 2015-12-31 01:09:20.124 fa[23747:446296] [IFLYTEK] -[IFlyMscRecognizer startRecord][OUT] 2015-12-31 01:09:20.124 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer beginSession][IN],self= 2015-12-31 01:09:20.124 fa[23747:446340] [IFLYTEK] beginSession before state=1 2015-12-31 01:09:20.127 fa[23747:446340] [IFLYTEK] QISRSessionBegin:engine_type=cloud,sub=iat,language=zh_cn,plr=0,audio_source=1,vad_speech_tail=1800,msc.skin=0,rse=utf8,asr_audio_path=record.pcm,sample_rate=16000,timeout=20000,domain=iat,speech_timeout=30000,vad_timeout=1800,vad_bos=1800,rst=plain,vad_eos=1800,auf=audio/L16;rate=16000,ptt=1,voice_change=0,sch=0,accent=mandarin,msc.ver=1.0.1109.1123,openudid=5f45f8636e008e75426c1dd4bb57c83da1a9312a,carrier=,os.system=iPhone OS,os.release=8.4,os.version=8.4,os.model=x86_64,os.resolution=750*1334,os.manufact=apple,os.jailbreak=0,app.name=noName,app.path=/Users/lecason/Library/Developer/CoreSimulator/Devices/7B272449-DB68-43E8-A196-7C7D3FAA1F1D/data/Containers/Bundle/Application/E071193E-648F-4A18-9A22-378BB22F8649/fa.app,app.pkg=fa.app,net_type=wifi 2015-12-31 01:09:20.200 fa[23747:446340] [IFLYTEK] QISRRegisterNotify=0 2015-12-31 01:09:20.201 fa[23747:446340] [IFLYTEK] beginSession after state=1,_error=0 2015-12-31 01:09:20.201 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer beginSession][OUT],self=53528272 2015-12-31 01:09:20.201 fa[23747:446340] [IFLYTEK] _startDate,50338112 2015-12-31 01:09:20.205 fa[23747:446353] [IFLYTEK] recog_status_callback type==1,status=79 2015-12-31 01:09:20.383 fa[23747:446353] [IFLYTEK] recog_status_callback type==0,status=1 2015-12-31 01:09:22.946 fa[23747:446353] [IFLYTEK] recog_result_callback resultStatus==0,result=47889584,resultLen=6 2015-12-31 01:09:22.946 fa[23747:446353] [IFLYTEK] -[ISREngine isVoiceChange],voiceChange=0 2015-12-31 01:09:22.947 fa[23747:446296] ------ 中國 (置信度:100) ------ 2015-12-31 01:09:24.496 fa[23747:446353] [IFLYTEK] recog_status_callback type==0,status=3 2015-12-31 01:09:24.497 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder stop][IN] 2015-12-31 01:09:24.497 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueFlush 2015-12-31 01:09:24.497 fa[23747:446353] [IFLYTEK] recog_status_callback type==0,status=3 2015-12-31 01:09:24.497 fa[23747:446296] [IFLYTEK] stop recording success 2015-12-31 01:09:24.498 fa[23747:446353] [IFLYTEK] recog_result_callback resultStatus==5,result=50332544,resultLen=3 2015-12-31 01:09:24.498 fa[23747:446353] [IFLYTEK] -[ISREngine isVoiceChange],voiceChange=0 2015-12-31 01:09:24.521 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueStop 2015-12-31 01:09:24.542 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueDispose 2015-12-31 01:09:24.542 fa[23747:446296] [IFLYTEK] -[IFlyPcmRecorder stop][OUT] 2015-12-31 01:09:24.546 fa[23747:446340] [IFLYTEK] while end,self=53528272 2015-12-31 01:09:24.546 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer setSessionInfo][IN] 2015-12-31 01:09:24.547 fa[23747:446340] [IFLYTEK] info:{"rec_ustop":"0","app_fau":310,"app_start":"2016/12/31 01:09:20 072","app_frs":2875,"rec_close":4425,"app_lrs":4426,"rec_start":307,"rec_open":1,"app_ssb":52,"rec_ready":52,"app_lau":4425} 2015-12-31 01:09:24.547 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer setSessionInfo][OUT] 2015-12-31 01:09:24.548 fa[23747:446340] [IFLYTEK] -[ISREngine stopEngine] _szSession=53715544[IN] 2015-12-31 01:09:24.549 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer setState:][ISREnd IN] 2015-12-31 01:09:24.549 fa[23747:446340] [IFLYTEK] -[IFlySpeechRecognizer onError:] [IN] errorCode=0 2015-12-31 01:09:24.549 fa[23747:446340] [IFLYTEK] -[IFlySpeechRecognizer onError:][OUT] 2015-12-31 01:09:24.549 fa[23747:446296] 出現錯誤 :<IFlySpeechError: 0x7fad02f74d80> 2015-12-31 01:09:24.549 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer setState:][ISREnd OUT] 2015-12-31 01:09:24.549 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer main][OUT],self=53528272 2015-12-31 01:09:24.550 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer dealloc][IN],self=53528272 2015-12-31 01:09:24.550 fa[23747:446340] [IFLYTEK] -[IFlyMscRecognizer dealloc][OUT],self=53528272
第二種帶界面的語音聽寫:
DDHomeSearchViewController.m
// // DDHomeSearchViewController.m// // Created by 夏遠全 on 16/12/1. // Copyright © 2016年 . All rights reserved. // #import "DDHomeSearchController.h" @interface DDHomeSearchViewController ()<UISearchBarDelegate,IFlyRecognizerViewDelegate> { IFlyRecognizerView *_iflyRecognizerView; } @property (nonatomic, strong) UISearchBar * searchBar; @end @implementation DDHomeSearchController - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor clearColor]; //初始化導航欄 [self _createNavigationBar]; //初始化語音識別 [self initIFly]; [self initAppid]; } //創建導航欄 - (void)_createNavigationBar { //取消 self.navigationItem.leftBarButtonItems = [UIBarButtonItem itemWithFrame:CGRectMake(0, 0, 60, 40) ImageName:@"back" Title:@"取消" TitleColor:[UIColor whiteColor] size:14 target:self action:@selector(back)]; _searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 100, 30)]; //搜索欄 _searchBar.placeholder = @"請輸入要搜索的商家、品類"; _searchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin; _searchBar.autoresizesSubviews = YES; _searchBar.delegate = self; self.navigationItem.titleView = _searchBar; //搜索 self.navigationItem.rightBarButtonItems = [UIBarButtonItem itemWithFrame:CGRectMake(0, 0, 60, 40) Title:@"語音" TitleColor:[UIColor whiteColor] size:14 target:self action:@selector(voiceStart)]; } //返回 -(void)back{ [self.presentingViewController dismissViewControllerAnimated:NO completion:nil]; } //初始化Appid -(void)initAppid{ //注冊訊飛語音 NSString *initString = [[NSString alloc] initWithFormat:@"appid=%@",@"xxxxxxx"]; [IFlySpeechUtility createUtility:initString]; } //語音識別初始化 -(void)initIFly{ //單例模式,無UI的實例 if (_iflyRecognizerView == nil) { _iflyRecognizerView = [[IFlyRecognizerView alloc] initWithCenter:self.view.center]; _iflyRecognizerView.delegate = self; } // 設置參數 if (_iflyRecognizerView != nil) { //擴展參數 [_iflyRecognizerView setParameter:@"" forKey:[IFlySpeechConstant PARAMS]]; //設置聽寫模式 [_iflyRecognizerView setParameter:@"iat" forKey:[IFlySpeechConstant IFLY_DOMAIN]]; //設置最長錄音時間 [_iflyRecognizerView setParameter:@"30000" forKey:[IFlySpeechConstant SPEECH_TIMEOUT]]; //設置后端點 [_iflyRecognizerView setParameter:@"1800" forKey:[IFlySpeechConstant VAD_EOS]]; //設置前端點 [_iflyRecognizerView setParameter:@"1800" forKey:[IFlySpeechConstant VAD_BOS]]; //網絡等待時間 [_iflyRecognizerView setParameter:@"20000" forKey:[IFlySpeechConstant NET_TIMEOUT]]; //設置采樣率,推薦使用16K [_iflyRecognizerView setParameter:@"16000" forKey:[IFlySpeechConstant SAMPLE_RATE]]; //設置語言 [_iflyRecognizerView setParameter:@"zh_cn" forKey:[IFlySpeechConstant LANGUAGE]]; //設置方言 [_iflyRecognizerView setParameter:@"mandarin" forKey:[IFlySpeechConstant ACCENT]]; //設置是否返回標點符號 [_iflyRecognizerView setParameter:@"1" forKey:[IFlySpeechConstant ASR_PTT]]; //設置數據返回格式 [_iflyRecognizerView setParameter:@"plain" forKey:[IFlySpeechConstant RESULT_TYPE]]; } } //語音搜索啟動 -(void)voiceStart{ //按鈕變換 self.navigationItem.rightBarButtonItems = [UIBarButtonItem itemWithFrame:CGRectMake(0, 0, 60, 40) Title:@"結束" TitleColor:[UIColor whiteColor] size:14 target:self action:@selector(voiceEnd)]; //啟動識別服務 [_iflyRecognizerView start]; } //結束錄音 -(void)voiceEnd{ //按鈕變換 self.navigationItem.rightBarButtonItems = [UIBarButtonItem itemWithFrame:CGRectMake(0, 0, 60, 40) Title:@"語音" TitleColor:[UIColor whiteColor] size:14 target:self action:@selector(voiceStart)]; //結束識別服務 [_iflyRecognizerView cancel]; } /*識別結果返回代理 @param resultArray 識別結果 @ param isLast 表示是否最后一次結果 */ - (void)onResult: (NSArray *)resultArray isLast:(BOOL) isLast { [resultArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { DDLog(@"%@",obj); }]; } /*識別會話錯誤返回代理 @ param error 錯誤碼 */ - (void)onError: (IFlySpeechError *) error { DDLog(@"語音識別出錯:%@",error); } #pragma mark - UISearchBarDelegate -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar{ [searchBar becomeFirstResponder]; } -(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ DDLog(@"%@",searchText); } -(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{ [searchBar resignFirstResponder]; [searchBar setText:nil]; } @end
演示結果:
2016-12-02 08:56:49.444 BiaoJiePay[1057:379880] [IFLYTEK] startListening audioSource:1 2016-12-02 08:56:49.444 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlySpeechRecognizer runService][OUT] 2016-12-02 08:56:49.444 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlySpeechRecognizer startListening][OUT] 2016-12-02 08:56:49.444 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp start][OUT] 2016-12-02 08:56:49.445 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerView start],identifyingVIew start 2016-12-02 08:56:49.445 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerView start][OUT] 2016-12-02 08:56:49.445 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyMscRecognizer startRecord][IN] 2016-12-02 08:56:49.445 BiaoJiePay[1057:379880] [IFLYTEK] +[IFlyAudioSession initRecordingAudioSession] 2016-12-02 08:56:49.449 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder setSample:],rate=16000 2016-12-02 08:56:49.449 BiaoJiePay[1057:379880] [IFLYTEK] +[IFlySystemInfo getWorkPath],_gMscLogPath=(null) 2016-12-02 08:56:49.449 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder start],[IN] 2016-12-02 08:56:49.636 BiaoJiePay[1057:379880] [IFLYTEK] pcmRecorder|timeValue:0.187140 2016-12-02 08:56:49.641 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder start],[OUT],ret =0 2016-12-02 08:56:49.641 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyMscRecognizer startRecord][OUT] 2016-12-02 08:56:49.641 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer beginSession][IN],self= 2016-12-02 08:56:49.641 BiaoJiePay[1057:379975] [IFLYTEK] beginSession before state=1 2016-12-02 08:56:49.642 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onBeginOfSpeech][IN] 2016-12-02 08:56:49.642 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onBeginOfSpeech][OUT] 2016-12-02 08:56:49.654 BiaoJiePay[1057:379975] [IFLYTEK] QISRSessionBegin:engine_type=cloud,sub=iat,language=zh_cn,plr=0,audio_source=1,vad_speech_tail=1800,msc.skin=default,rse=utf8,asr_audio_path=record.pcm,sample_rate=16000,timeout=20000,domain=iat,speech_timeout=30000,vad_timeout=1800,vad_bos=1800,rst=plain,vad_eos=1800,auf=audio/L16;rate=16000,ptt=1,voice_change=0,sch=0,accent=mandarin,msc.ver=1.0.1115.1145,xxxxxx,xxxxxxxxx........ 2016-12-02 08:56:49.658 BiaoJiePay[1057:379975] [IFLYTEK] QISRRegisterNotify=0 2016-12-02 08:56:49.659 BiaoJiePay[1057:379975] [IFLYTEK] beginSession after state=1,_error=0 2016-12-02 08:56:49.659 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer beginSession][OUT],self=221654928 2016-12-02 08:56:49.659 BiaoJiePay[1057:379975] [IFLYTEK] _startDate,156534080 2016-12-02 08:56:49.790 BiaoJiePay[1057:380225] [IFLYTEK] recog_status_callback type==0,status=1 2016-12-02 08:56:50.823 BiaoJiePay[1057:380225] [IFLYTEK] recog_status_callback type==1,status=1175 2016-12-02 08:56:51.850 BiaoJiePay[1057:380225] [IFLYTEK] recog_result_callback resultStatus==0,result=ÂëµÂëµ,resultLen=6 2016-12-02 08:56:51.850 BiaoJiePay[1057:380225] [IFLYTEK] -[ISREngine isVoiceChange],voiceChange=0 2016-12-02 08:56:51.850 BiaoJiePay[1057:380225] [IFLYTEK] -[ISRDataHander dataHander:parse:],resultString=呵呵 2016-12-02 08:56:51.850 BiaoJiePay[1057:379880] { "\U5475\U5475" = 100; } 2016-12-02 08:56:52.326 BiaoJiePay[1057:380225] [IFLYTEK] recog_status_callback type==0,status=3 2016-12-02 08:56:52.326 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder stop][IN] 2016-12-02 08:56:52.327 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueFlush 2016-12-02 08:56:52.330 BiaoJiePay[1057:379880] [IFLYTEK] stop recording success 2016-12-02 08:56:52.346 BiaoJiePay[1057:380225] [IFLYTEK] recog_result_callback resultStatus==5,result=ÔºÅ,resultLen=3 2016-12-02 08:56:52.346 BiaoJiePay[1057:380225] [IFLYTEK] -[ISREngine isVoiceChange],voiceChange=0 2016-12-02 08:56:52.346 BiaoJiePay[1057:380225] [IFLYTEK] -[ISRDataHander dataHander:parse:],resultString=! 2016-12-02 08:56:52.351 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueStop 2016-12-02 08:56:52.373 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder stop]|AudioQueueDispose 2016-12-02 08:56:52.373 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyPcmRecorder stop][OUT] 2016-12-02 08:56:52.373 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onEndOfSpeech][IN] 2016-12-02 08:56:52.374 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onEndOfSpeech][OUT] 2016-12-02 08:56:52.374 BiaoJiePay[1057:379880] { "\Uff01" = 100; } 2016-12-02 08:56:52.380 BiaoJiePay[1057:379975] [IFLYTEK] while end,self=221654928 2016-12-02 08:56:52.380 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer setSessionInfo][IN] 2016-12-02 08:56:52.380 BiaoJiePay[1057:379975] [IFLYTEK] info:{"rec_close":2883,"app_ssb":198,"app_fau":346,"rec_ready":198,"ui_lrs":2931,"app_start":"2016/12/02 08:56:49 443","app_frs":2407,"app_lau":2883,"rec_ustop":"0","rec_start":343,"app_lrs":2903,"ui_frs":2407,"rec_open":2} 2016-12-02 08:56:52.380 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer setSessionInfo][OUT] 2016-12-02 08:56:52.381 BiaoJiePay[1057:379975] [IFLYTEK] -[ISREngine stopEngine] _szSession=221656648[IN] 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer setState:][ISREnd IN] 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlySpeechRecognizer onError:] [IN] errorCode=0 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlySpeechRecognizer onError:][OUT] 2016-12-02 08:56:52.383 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onError:][IN],errorCode=0 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer setState:][ISREnd OUT] 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer main][OUT],self=221654928 2016-12-02 08:56:52.383 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer dealloc][IN],self=221654928 2016-12-02 08:56:52.384 BiaoJiePay[1057:379975] [IFLYTEK] -[IFlyMscRecognizer dealloc][OUT],self=221654928 2016-12-02 08:56:52.385 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerView onError:][IN],errorCode=0 2016-12-02 08:56:52.385 BiaoJiePay[1057:379880] 語音識別出錯:<IFlySpeechError: 0x10d39b2f0> 2016-12-02 08:56:52.385 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerView onError:][OUT] 2016-12-02 08:56:52.385 BiaoJiePay[1057:379880] [IFLYTEK] -[IFlyRecognizerViewImp onError:][OUT]
效果截圖:(說一句“附近的商店”)