C # googletranslate

Source: Internet
Author: User

Sometimes we need software to translate some of the terms, for example we do speech recognition intelligent interaction

Users say a lot of English machine recognition, because we only recognize the Chinese command what to do?

we'll find a way to get our program to recognize what the foreigner says. What should we do? This

we need to translate, but I have not seen the translation aspect of C # The line library is only online

But also good, look at Microsoft's Cortana robot it is to identify what users say in the search through Bing

to many information, and the program we give users will certainly not be to Microsoft Cortana, Apple Siri so that

Smart, but We just need the software to recognize what the user needs to do with the software, but I

Now the point is how to to achieve translation, I generally commonly used googletranslate not for other translation of foreigners

posts inside the content of Google is the best, at least translated to be able to read 55 of the number almost,

        public static string Googletranslate (String message) {string Requiredurl = string. Format ("http://translate.google.com/translate_a/single?client=t&sl={0}&tl={1}&hl=zh-cn&dt=bd &dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&ie=utf-8&oe                    =UTF-8&SRCROM=0&SSEL=3&TSEL=3&KC=0&TK=523084|487837&Q={2} "," Auto "//Auto Check language                    , CultureInfo.CurrentCulture.Name//Chinese (Simplified, China)/LCID 2052/ACP && OEMCP 936            , UrlEncode (message, encoding.default)); String outerhtml = String.            Empty; try {using (WebClient client = new WebClient ()) {client.                    Encoding = Encoding.UTF8; outerhtml = client.                Downloadstring (Requiredurl);             }} catch (WebException) {   Goto Endtranslate; } if (Outerhtml.length > 0) outerhtml = Regex.match (outerhtml,@ "\x22 ([\s\s]+?) \x22 "). GROUPS[1].        Value;        Endtranslate:return outerhtml; }

The above code returns only the preferred result after a googletranslate but

Yes, it's almost there. We identify what the user said and I'm sure there is absolutely

Condition everyone is using the method of recognizing phonetic transcription although the fuzziness is higher but

Software-compatible users a weird accent is a big boost for those later in the discussion

You can also change the code, googletranslate it back to a

JSON-formatted text, classes you can parse with JSON solve the problem

        public static string UrlEncode (String uristring, Encoding uriencoding)        {            StringBuilder str = new StringBuilder () ;            byte[] buf = uriencoding.getbytes (uristring);            for (int i = 0; i < BUF. Length; i++)                str. Append ("%" + convert.tostring (Buf[i], +));            return convert.tostring (str);        }

Above is a non-standard URL encryption code but googletranslate

You can parse the correct content so you don't have to use standard URL encryption code

And the Googletranslate server is really not worried about a few more calculations.

How will the Googletranslate server,

        [STAThread]        unsafe static void Main ()        {            Console.WriteLine (googletranslate ("Hello World"));            Console.readkey (FALSE);        }

The above is called in the Main method of the written googletranslate

Part, immediately after the operation to see the effect is quite to force?

    Using System;    Using System.Globalization;    Using System.Net;    Using System.Text;    Using System.Text.RegularExpressions;

The above is dependent on the namespace, do not copy or you can put the mouse on the code anyway

Polygons will prompt you to add namespaces, so don't worry about the code not working

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

C # googletranslate

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.