Monday 25 February 2013

Text To Speech using C#.Net


using System.Speech.Synthesis;
    
      SpeechSynthesizer ss = new SpeechSynthesizer();
      ss.Volume = 100;
      ss.Speak("My Name is khan. And I am not a terrorist.");

language Translator using Google Translate


protected void Button1_Click(object sender, EventArgs e)
  {
     // using Google Translate
   string Fromlang = "en";
   string Tolang = "gu";
   string url = @"http://translate.google.com/translate_a/t?client=t&text=" + txtFrom.Text +
                 "&hl=en&sl="+Fromlang+"&tl="+Tolang+"&ie=UTF-8&oe=UTF-
                  8&multires=1&otf=1&ssel=3&tsel=3&sc=1"
;

    WebRequest client = WebRequest.Create(url);
    WebResponse resp = client.GetResponse();
    Stream strm = resp.GetResponseStream();

    StreamReader sr = new StreamReader(strm);
    string strResp = sr.ReadToEnd();
    dvTo.InnerHtml = strResp.Split(']')[0].Split(',')[0].Replace('[', ' ').Replace('"',' ');
   }


    <div>
        <asp:TextBox ID="txtFrom" runat="server" TextMode="MultiLine" Height="88px"   
Width="235px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <div id="dvTo" runat="server" > </div>
    </div>

language translation using Bing API


protected void Button1_Click(object sender, EventArgs e)
  {
                // Bing ApI Key
            string applicationid = "68D088969D79A8B23AF8585CC83EBA2A05A97651";           
            string fromlanguage = "en";  // From language
            string translatedText = "";
            string texttotranslate = txtFrom.Text; // Text to translate
            string tolanguage = "hi";//To language?
           
            //preparing url with all four parameter
            string uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?appId=" + applicationid
                       + "&text=" + texttotranslate + "&from=" + fromlanguage + "&to=" + tolanguage;           
            //making web request to url
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            //getting response from api
            WebResponse response = request.GetResponse();

            Stream strm = response.GetResponseStream();

            StreamReader reader = new System.IO.StreamReader(strm);
            //reading result
            translatedText = reader.ReadToEnd();           
            dvTo.InnerHtml = translatedText;           
            response.Close();           
   }


    <div>
        <asp:TextBox ID="txtFrom" runat="server" TextMode="MultiLine" Height="88px"   
Width="235px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        <div id="dvTo" runat="server" > </div>
    </div>