Code Behind: using System; using System.Configuration; using System.Data; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Net; using System.Xml; public partial class _Default : System.Web.UI.Page { // Bing API Id: get your own @ http://www.bing.com/developers/appids.aspx const string AppId = "FD087E7F3CDFEC530B63A2AC2FEEC5846127DA39"; protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { // retrieve the basic parameters string sourceText = TextBox1.Text; string targetLang = DropDownList1.SelectedValue; // Sample code from the Bing API documentation, with minor modifications // see http://msdn.microsoft.com/en-us/library/dd877832.aspx HttpWebRequest request = BuildRequest(sourceText, targetLang); try { // Send the request; display the response. HttpWebResponse response = (HttpWebResponse)request.GetResponse(); TextBox2.Text = DisplayResponse(response); } catch (WebException ex) { // An exception occurred while accessing the network. TextBox2.Text = ex.Message; } } static HttpWebRequest BuildRequest(string sourceText, string targetLang) { string requestString = "http://api.bing.net/xml.aspx?" // Common request fields (required) + "AppId=" + AppId + "&Query=" + HttpUtility.UrlEncode(sourceText) + "&Sources=Translation" // Common request fields (optional) + "&Version=2.2" // SourceType-specific request fields (required) + "&Translation.SourceLanguage=en" + "&Translation.TargetLanguage=" + targetLang; // Create and initialize the request. HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create( requestString); return request; } static string DisplayResponse(HttpWebResponse response) { // Load the response into an XmlDocument. XmlDocument document = new XmlDocument(); document.Load(response.GetResponseStream()); // Add the default namespace to the namespace manager. XmlNamespaceManager nsmgr = new XmlNamespaceManager( document.NameTable); nsmgr.AddNamespace( "api", "http://schemas.microsoft.com/LiveSearch/2008/04/XML/element"); XmlNodeList errors = document.DocumentElement.SelectNodes( "./api:Errors/api:Error", nsmgr); if (errors.Count > 0) { // There are errors in the response. Display error details. return DisplayErrors(errors); } else { // There were no errors in the response. Display the // Translation results. return DisplayResults(document.DocumentElement, nsmgr); } } static string DisplayResults(XmlNode root, XmlNamespaceManager nsmgr) { string results = String.Empty; string version = root.SelectSingleNode("./@Version", nsmgr).InnerText; string searchTerms = root.SelectSingleNode( "./api:Query/api:SearchTerms", nsmgr).InnerText; // Add the Translation SourceType namespace to the namespace manager. nsmgr.AddNamespace( "tra", "http://schemas.microsoft.com/LiveSearch/2008/04/XML/translation"); XmlNodeList nodes = root.SelectNodes( "./tra:Translation/tra:Results/tra:TranslationResult", nsmgr); // Display the Translation results. foreach (XmlNode result in nodes) { results = String.Concat(results, result.SelectSingleNode("./tra:TranslatedTerm", nsmgr).InnerText); } return results; } static string DisplayErrors(XmlNodeList errors) { string results = String.Empty; // Iterate over the list of errors and display error details. foreach (XmlNode error in errors) { foreach (XmlNode detail in error.ChildNodes) { results = String.Concat(detail.Name + ": " + detail.InnerText); } } return results; } } Client Code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TranslateUsingBingSpeechSample.aspx.cs" Inherits="_Default" %> Translate to Speech Sample
Translate2Speech Sample Using the Bing API - ASPX
 
Translate      to  French German Spanish     
 
Translation       
 
hover over for mt disclaimer