This article is from my notes directly turned over, we will see.
The following two addresses are of great reference value:
Speech Recognition: http://www.tuicool.com/articles/NRF3a2
Speech synthesis: http://www.daxueit.com/article/4422.html of Hkust Open address: http://www.xfyun.cn
Nothing to do. Research on the mobile phone voice function, the use of the Hkust Flying SDK. You can look at the official document (see you before you know that there are so many aspects of speech, but I was only preliminary research on speech synthesis and speech recognition), especially when adding a local library.
1. Apply for AppID, import class library, Import SDK These do not say, refer to official documents.
2. And almost all using a Third-party SDK, you must initialize the AppID.
First start the service of hkust flying
NSString *initstring = [[nsstringalloc]initwithformat:@ "appid=%@,timeout=%@", @ "553caea5", @ "20000"];
[Iflyspeechutility createutility:initstring];
3. You must be aware of its structure in parsing the results, and you must use a tool that parses the JSON string. (The Analytic method provided in the sense is a bit biased)
NSLog (@ "result:%@", results);
Nsdictionary *dic = results[0];
NSLog (@ "resultdic:%@", DIC);
nsmutablestring *resultstr = [nsmutablestring string];
Nsarray *temp = [[Nsarray alloc]init];
For (NSString *key in Dic.allkeys) {
[ResultStr appendformat:@ "%@", key];
// }
NSLog (@ "final result:%@", resultstr);
Sbjsonparser *parser = [[Sbjsonparser alloc]init];
Nserror *error = nil;
Parse Result: The result is in WS, parsing error, the first element is a string form of JSON string
NSString *dic100string = [dic allkeys][0];
Parsing a JSON string using Sbjson
Nsdictionary *dic100 = [parser objectwithstring:dic100string error:&error];
Nsarray *array_ws = [dic100 objectforkey:@ "ws"];
Traverse each word of the recognition result
for (int i = 0; i < Array_ws.count i + +) {
temp = [[Array_ws objectatindex:i]objectforkey:@ "CW"];
Nsdictionary *DIC_CW = [temp objectatindex:0];
ResultStr = (nsmutablestring *) [ResultStr stringbyappendingstring:[dic_cwobjectforkey:@ "W"]];
NSLog (@ "Recognition Result:%@", [DIC_CW objectforkey:@ "W"]);
[Lastresult appendformat:@ "%@", ResultStr];
}
Call this method if it is the last time
if (islast) {
NSLog (@ "Final recognition Result:%@", Lastresult);
Resultview.text = Lastresult;
}
4. The above method for returning the parsed result is invoked multiple times, and the result must be stored with a global variable to determine if the last call is displayed again.