Exchange rate conversion Natural language understanding function iOS DEMO

Source: Internet
Author: User

Original address

http://blog.csdn.net/dfman1978/article/details/78468318

Objective

The use of voice input is increasingly common. Voice input is not only efficient, but also more natural, in line with human input methods. A currency converter APP has been developed here that shows how to use speech input and speech recognition.

App Introduction

The app can recognize the user's input, then return the result and read it in natural language.

The user can click on the microphone icon to enter the voice input: "1 yuan for the amount of dollars exchanged." Or, "350 Baht for RMB" and so on. And the results will be read by voice.

function implementation

Both speech recognition and semantic understanding are realized through the Olami platform. This need to go to the Olami platform to register, and then you can try it for free. Website address Https://olami.ai, the site has a wealth of teaching resources specific use can view the relevant documents. Olami is an AI software development platform launched by the AI-sheng Electronics (Shanghai) Co., Ltd. Artificial intelligence software research team, which provides a full range of human-computer interaction solutions including natural voice interaction technology, covering a wide range of semantic common scenarios in the vertical domain.

The reading of the voice is done using Apple's avspeechsynthesis library. This library is also very easy to use. This library is in the avfoundation.

Since the Olami platform has built-in calculations for the calculation of exchange rates, the code is less processed. The main source of code is the processing of the JSON data passed in.

- (void) Onresult: (NSData *) result {Nserror *error; __Weak typeof (Self) weakself =SelfNsdictionary *dic = [nsjsonserialization jsonobjectwithdata:result options:nsjsonreadingmutablecontainers Error: &error];if (Error) {Nsslog (@"Error is%@", error. localizeddescription); }else{NSString *jsonstr=[[NSString Alloc]initwithdata:result encoding:nsutf8stringencoding];NSLog (@"Jsonstr is%@", jsonstr);NSString *ok = [dic objectforkey:@"Status"];if ([OK isequaltostring:@"OK"]) {Nsdictionary *dicdata = [dic objectforkey:@"Data"];Nsdictionary *ASR = [Dicdata objectforkey:@"ASR"];if (ASR) {If ASR is not empty, the description is currently voice input [weakself PROCESSASR:ASR]; }Nsdictionary *nli = [[Dicdata objectforkey:@"Nli"] Objectatindex:0];Nsdictionary *desc = [Nli objectforkey:@"Desc_obj"];int status = [[Desc objectforkey:@if (Status! = 0) {//0 indicates that the status is OK, Nonzero is unhealthy or result is null [[nsnotificationcenter Defaultcenter] Postnotification:[nsnotification notificationwithname:@ "Noresult" Object:nil userinfo:nil]"; }else{nsdictionary *semantic = [[Nli ObjectForKey:@ "semantic"] objectatindex:0]; nsstring *result = [desc objectforkey:@ "result"]; [self.delegate Onresult:result];}} else{}}            

The result is placed in the result field

{    "Data ":{        "ASR ":{            "Result ":"398 HKD is how much renminbi", "Speech_status ":0, "Final ":True, "Status ":0}, "Nli ":[{"desc_obj": {"result":  "information you are looking for: 398 HKD for 338.22040 RMB", " Span class= "Hljs-attribute" >source_currency ": " 398 HKD "," status ": 0}," data_obj ": [{" target_ Currency ": " 338.22040 RMB "}],"  Type ": " exchangerate "}]},"  Status ":        

Just get the value out of this field.

The specific code can refer to GitHub
Https://github.com/lym-ay/RateDemo

Exchange rate conversion Natural language understanding function iOS DEMO

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.