Iflytek speech recognition

Source: Internet
Author: User

Register your account with the Iflytek open platform, create an app and download the SDK, unzip the SDK package, and drag the framework into the project, such as

Then you'll import the class library: specifically,

Create a project, we are divided into two parts, the first part is in the Fristviewcontroller, the realization of speech recognition function, the second part is in the Secondviewcontroller, the realization of text conversion to speech

First Import the header file in APPDELEGATE.M

1 // Import Header File 2 #import <iflyMSC/iflyMSC.h>

Then sign in to the APPDELEGATE.M. Iflytek Voice Platform

1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2     //Override point for customization after application launch.3     4     //The second step: Login to the Iflytek voice platform "for your own application ID on the fly."5NSString *appid = [NSString stringWithFormat:@"appid=%@",@"5750da61"];6 [iflyspeechutility createutility:appid];7     8     returnYES;9}

To the first part of the implementation, directly on the code "firstviewcontroller.m"

1 #import "FirstViewController.h"2 //First step: Introduce the library file3 //the interface file of the Iflytek voice recognition function callback method4 #import<iflyMSC/IFlyRecognizerViewDelegate.h>5 //The Voice recognition view of the Iflytek speech recognition function6 #import<iflyMSC/IFlyRecognizerView.h>7 //the constants defined in the Iflytek speech recognition function8 #import<iflyMSC/IFlySpeechConstant.h>9 Ten @interfaceFirstviewcontroller () <IFlyRecognizerViewDelegate>//Follow the agent One  A /** TextView*/ -@property (Weak, nonatomic) iboutlet Uitextview *TextView; -  the /** Speech Recognition Object*/ -@property (nonatomic, strong) Iflyrecognizerview *Iflyrecognizerview; -  - /** strings that receive related results*/ +@property (nonatomic, strong) nsmutablestring *result; -  + @end A  at @implementationFirstviewcontroller -  -- (void) Viewdidload { - [Super Viewdidload]; -     //Do any additional setup after loading the view. -      in      -     //Create a sound Recognition view object, initialize the sound recognition control toself.iflyrecognizerview=[[Iflyrecognizerview alloc] initWithCenter:self.view.center]; +     //delegate needs to be set to ensure that the delegate callback returns normally -Self.iflyrecognizerview.Delegate=Self ; the } *  $ Panax Notoginseng #pragmaMark-Start identifying --(Ibaction) Beginrecongnise: (ID) Sender { the      + [self startlistenning]; A } the  +  - //Speech Recognition $- (void) startlistenning $ { -     //set speech recognition results to be used as plain text fields -[Self.iflyrecognizerview Setparameter:@"IAT"forkey:[iflyspeechconstant Ifly_domain]]; the     //set the front point detection time to 6000ms -[Self.iflyrecognizerview Setparameter:@"6000"forkey:[iflyspeechconstant Vad_bos]];Wuyi     //after setting the endpoint detection time is 700ms the[Self.iflyrecognizerview Setparameter:@" the"forkey:[iflyspeechconstant Vad_eos]]; -     //set the sample rate to 8000 Wu[Self.iflyrecognizerview Setparameter:@"8000"forkey:[iflyspeechconstant Sample_rate]]; -     //set to return included punctuation in results About[Self.iflyrecognizerview Setparameter:@"1"forkey:[iflyspeechconstant Asr_ptt]]; $     //to set the return data structure type XML after speech recognition is complete -[Self.iflyrecognizerview Setparameter:@"Plain"forkey:[iflyspeechconstant Result_type]]; -     //set the file name to be cached in the Documents folder named Temp.asr -[Self.iflyrecognizerview Setparameter:@"Temp.asr"forkey:[iflyspeechconstant Asr_audio_path]]; A     //to set custom parameters +[Self.iflyrecognizerview Setparameter:@"Custom"forkey:[iflyspeechconstant PARAMS]]; the      - [Self.iflyrecognizerview start]; $ } the  the  the #pragmaMark-Proxy method the //Success -- (void) Onresult: (Nsarray *) resultarray islast: (BOOL) islast { in      theSelf.result =[[Nsmutablestring alloc] init]; theNsdictionary *dic = [Resultarray objectatindex:0]; About      the      for(NSString *keyinchdic) the     { the[Self.result AppendFormat:@"%@", key]; +     } -NSLog (@"%@---------", _result); the     Bayi     //Customizing control display content theSelf.textView.text = [NSString stringWithFormat:@"%@%@", Self.textview.text,self.result]; the } -  -  the //failed the- (void) OnError: (Iflyspeecherror *) Error { the      the } -  the @end

Implement Part Two "SECONDVIEWCONTROLLER.M"

1 #import "SecondViewController.h"2 3 //callback method interface for text recognition4 #import<iflyMSC/IFlySpeechSynthesizerDelegate.h>5 //Text Recognition Object6 #import<iflyMSC/IFlySpeechSynthesizer.h>7 //the constant defined by the Iflytek voice framework8 #import<iflyMSC/IFlySpeechConstant.h>9 Ten @interfaceSecondviewcontroller () <IFlySpeechSynthesizerDelegate>//Follow related agents One  A /** TextView*/ -@property (Weak, nonatomic) iboutlet Uitextview *TextView; -  the /** Text Recognition object*/ -@property (Strong, nonatomic) Iflyspeechsynthesizer *synthesizer; -  - @end +  - @implementationSecondviewcontroller +  A- (void) Viewdidload { at [Super Viewdidload]; -      -      -     //Create a text recognition object -Self.synthesizer =[Iflyspeechsynthesizer sharedinstance]; -      in     //Specify a proxy object for a text-aware object -Self.synthesizer.Delegate=Self ; to      +     //set key properties of a text-aware object -[Self.synthesizer Setparameter:@" -"forkey:[iflyspeechconstant Speed]]; the[Self.synthesizer Setparameter:@" -"forkey:[iflyspeechconstant VOLUME]]; *[Self.synthesizer Setparameter:@"XIAOYAN"forkey:[iflyspeechconstant Voice_name]]; $[Self.synthesizer Setparameter:@"8000"forkey:[iflyspeechconstant Sample_rate]];Panax Notoginseng[Self.synthesizer Setparameter:@"TEMP.PCM"forkey:[iflyspeechconstant Tts_audio_path]]; -[Self.synthesizer Setparameter:@"Custom"forkey:[iflyspeechconstant PARAMS]]; the } +  A  the #pragmaMark-Identify the relevant content +-(Ibaction) Beginrecognise: (ID) Sender { -      $ [Self.synthesizer Startspeaking:_textview.text]; $ } -  -  the #pragmaMark-Proxy method -- (void) oncompleted: (Iflyspeecherror *) Error {Wuyi      theNSLog (@""); - } Wu  - @end

Iflytek speech recognition

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.