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