Using the Hkust Flying SDK to achieve voice function _sdk

Source: Internet
Author: User
Tags allkeys

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.

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.