Ejemplo n.º 1
0
        /// <summary>
        /// Voice text
        /// </summary>
        /// <param name="q"></param>
        /// <param name="tl"></param>
        /// <returns></returns>
        public async Task <byte[]> Translate_tts(string q, string tl = "ja")
        {
            string tk       = ActionF1.GetTk(q);
            var    iTextLen = q.Length;
            string encodeQ  = Uri.EscapeDataString(q);

            byte[] res = null;
            HttpResponseMessage response = null;

            try
            {
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(ActionBase.UrlTranslateGoogleWebAPI);
                    HttpRequestHeaders reqH = client.DefaultRequestHeaders;
                    Authen(ref reqH);
                    reqH.Add(HttpRequestHeader.Cookie.ToString(), "NID=188=" + RenCookie());
                    string pathH = "/translate_tts?ie=UTF-8&q={0}&tl={1}&total=1&idx=0&textlen={2}{3}&client=webapp&prev=input";
                    string path  = string.Format(pathH, encodeQ, tl, iTextLen, tk);
                    response = await client.GetAsync(path);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("エラー: {0}", ex.ToString());
            }
            finally
            {
            }
            if (response.IsSuccessStatusCode)
            {
                res = await response.Content.ReadAsByteArrayAsync();
            }
            return(res);
        }
Ejemplo n.º 2
0
        private void btnGetMulti_Click(object sender, EventArgs e)
        {
            //string[][] res = await TEST_GETTranslatesAPI();
            //MessageBox.Show(res[0][0]);
            string tk = ActionF1.GetTk("月曜日");

            MessageBox.Show(tk);
        }
Ejemplo n.º 3
0
 public Form1()
 {
     AcF1 = new ActionF1();
     InitializeComponent();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Translate Single Text
        /// </summary>
        /// <param name="tk_q"></param>
        /// <returns></returns>
        public async Task <JArray> GetSingle(string q, string sl = "ja", string tl = "en")
        {
            string tk      = ActionF1.GetTk(q);
            string encodeQ = Uri.EscapeDataString(q);
            string tk_q    = tk + "&q=" + encodeQ;
            string res     = "";
            HttpResponseMessage response = null;

            try
            {
                //HttpClientHandler handler = new HttpClientHandler()
                //{
                //    Proxy = new WebProxy("http://192.168.0.12"),
                //    UseProxy = true,
                //};
                //using (var client = new HttpClient(handler))
                using (var client = new HttpClient())
                {
                    //specify to use TLS 1.2 as default connection
                    //System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
                    client.BaseAddress = new Uri(ActionBase.UrlTranslateGoogleWebAPI);
                    HttpRequestHeaders reqH = client.DefaultRequestHeaders;
                    Authen(ref reqH);
                    reqH.Add(HttpRequestHeader.Cookie.ToString(), "NID=188=" + RenCookie());
                    //HTTP GET
                    string[] paths = new string[] { "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=0&tsel=0&kc=1{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=3&tsel=3&kc=4{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=3&tsel=3&kc=1{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=1&ssel=3&tsel=3&kc=5{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=3&tsel=3&kc=6{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=2&ssel=3&tsel=3&kc=2{2}",
                                                    "/translate_a/single?client=webapp&sl={0}&tl={1}&hl=vi&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&otf=1&ssel=3&tsel=3&kc=7{2}" };
                    //Random r = new Random();
                    //int i = r.Next(0, 7);
                    string path = string.Format(paths[0], sl, tl, tk_q);
                    response = await client.GetAsync(path);
                }
            }
            catch (Exception ex)
            {
                Debug.Fail("エラー: {0}", ex.ToString());
            }
            finally
            {
            }
            //try
            //{
            //    response.EnsureSuccessStatusCode();
            //    // Handle success
            //    res = await response.Content.ReadAsStringAsync();
            //}
            //catch (HttpRequestException ex)
            //{
            //    throw ex;
            //    // Handle failure
            //}
            if (response.IsSuccessStatusCode)
            {
                res = await response.Content.ReadAsStringAsync();
            }
            JArray jj = JsonConvert.DeserializeObject(res) as JArray;

            return(jj);
        }