Use of the Tencent flying voice plug-in

Source: Internet
Author: User

After all, it is a relatively small number of plug-ins, and there are not many resources on the network. Leave a note.

1. Initialization. It is best to do this during application initialization (otherwise, a 10 Gbit/s bug or parameter error may occur)

// Initialize the Tencent voice plug-in

Nsstring * initstring = [nsstring stringwithformat: @ "% =%@", [iflyspeechconstant appid], appid_value]; // appid_value is the Unique Identification Code applied for at xunfei.

// Before starting all services, make sure that createutility is executed.

[Iflyspeechutility createutility: initstring];

 

2. Pay attention to avaudiosession settings before and after use (if there are other audio functions that need to be used in the application, otherwise there will inevitably be a 10106 bug)

// Set it to playandrecord before using the voice (usually when you click the voice button)

Nserror * sessionerror = nil;

Avaudiosession * audiosession = [avaudiosession sharedinstance];

[Audiosession setcategory: avaudiosessioncategoryplayandrecord error: & sessionerror];

   

// After using the voice, set it to playback (usually in the onresult and onerror communication proxy methods)

Nserror * sessionerror = nil;

Avaudiosession * audiosession = [avaudiosession sharedinstance];

[Audiosession setcategory: avaudiosessioncategoryplayback error: & sessionerror];

It is worth noting that if the app has the audio player function, you need to pause the player before use.

 

3. Basic processing of data returned by speech recognition, because the onresult returns an array

Nsmutablestring * result = [[nsmutablestring alloc] init];

Nsdictionary * DIC = [array objectatindex: 0];

For (nsstring * key in DIC ){

[Result appendformat: @ "% @", key];

}

[Self initialize mselecw.mainthread: @ selector (onupdatetextview :) withobject: Result waituntildone: Yes];

 

-(Void) onupdatetextview :( nsstring *) Sentence {// mainly for processing some characters

Nsmutablestring * keystr = [nsmutablestring stringwithstring: sentence];

If ([keystr hassuffix :@". "]) {

Nsange range = [keystr rangeofstring :@". "Options: nsbackwardssearch];

[Keystr deletecharactersinrange: range];

}

If ([keystr hassuffix :@"? "]) {

Nsange range = [keystr rangeofstring :@"? "Options: nsbackwardssearch];

[Keystr deletecharactersinrange: range];

}

If ([keystr hassuffix :@"! "]) {

Nsange range = [keystr rangeofstring :@"! "Options: nsbackwardssearch];

[Keystr deletecharactersinrange: range];

}

If ([keystr hassuffix: @ ","]) {

Nsange range = [keystr rangeofstring: @ "," Options: nsbackwardssearch];

[Keystr deletecharactersinrange: range];

}

// Set the voice to playback.

Nserror * sessionerror = nil;

Avaudiosession * audiosession = [avaudiosession sharedinstance];

[Audiosession setcategory: avaudiosessioncategoryplayback error: & sessionerror];

If (pausedplayer) {// check whether the player playback needs to be restored.

[[Audioplayer sharedinstance] startplay];

Pausedplayer = no;

}

[Iflyrecognizerview cancel];

}

 

Use of the Tencent flying voice plug-in

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.