Mono,C#: Bing Translate ~ Translate & Speak Methods

Hi again, I again coded some stuff just for fun…

The things you need to look before going deep to my perfect code :)

Code:

using System;
using System.Collections.Generic;
using System.Text;
using Gtk;
using System.Threading;
using System.Runtime.InteropServices;
using GtkSharp;
using GLib;
using System.Net;
using System.IO;
namespace test{
class translate : Window
{
private Entry entTranslate;
private string appId = "XXXXXXXXXXXXXXXXX"; //get appId from link above
private Label lblResult;
private Pango.FontDescription font = Pango.FontDescription.FromString("Verdana Bold 14");
public translate(): base("Kent_Calisma"){
this.SetSizeRequest(500, 500);
this.SetPosition(WindowPosition.Center);
Button btnTranslate=new Button();
btnTranslate.Label="translate";
btnTranslate.Clicked+= new EventHandler(btnTranslate_Clicked);
entTranslate =new Entry();
lblResult =new Label();
lblResult.SetSizeRequest(400,400);
lblResult.Wrap=true;lblResult.ModifyFont(font);
Image back=new Image("bing_logo.jpg");
Fixed fixed1 = new Fixed();fixed1.Put(back,0,0);
fixed1.Put(btnTranslate,30,90);
fixed1.Put(entTranslate,30,50);
fixed1.Put(lblResult,30,250);
this.Add(fixed1);
this.ShowAll();
}
void btnTranslate_Clicked(object sender, EventArgs e){
string from2 = "en";
string to = "fr";
string detectUri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + appId +"&text=" + entTranslate.Text + "&from=" + from2 + "&to=" + to;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(detectUri);
WebResponse resp = httpWebRequest.GetResponse();
Stream strm = resp.GetResponseStream();
StreamReader reader = new System.IO.StreamReader(strm);
string translation = reader.ReadToEnd();
Console.WriteLine(translation);
lblResult.Text=translation;
string language = "en";
WebClient wc = new WebClient();
wc.DownloadFile("http://api.microsofttranslator.com/v2/Http.svc/Speak?appId="+appId+"&text=" + entTranslate.Text + "&language=" + language,"translate.wav");
}
public static void Main(){
Application.Init();
new translate();
Application.Run();
}
}
}
 

Output:

kick it on DotNetKicks.com

About these ads