Mam tutaj przykład użycia Bing Translatora http://www.jimmycollins.org/blog/?p=241. Tutaj przykład w załączniku i wszystko działa. Na podstawie tego stworzyłem podobny kod, oczywiście ID podaje, referencja dodana.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BingTranslatorSlownik
{
public partial class Form1 : Form
{
string translatedText;
public void przetlumaczSlowo(string textToTranslate, string sourceLanguage, string targetLanguage)
{
try
{
BingTranslatorService.LanguageServiceClient client = new BingTranslatorService.LanguageServiceClient();
translatedText = client.Translate("Your ID", textToTranslate, sourceLanguage, targetLanguage);
MessageBox.Show(translatedText);
}
catch (Exception ex)
{
MessageBox.Show("An error has occurred: " + ex.ToString(), "Error");
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
przetlumaczSlowo("dom", "pl", "ang");
}
}
}
I dostaję błąd, treść w załączniku. Na czym polega błąd?
Kolejne pytanie, tutaj przykład na msdn pokazuje jak odtworzyć nagranie http://msdn.microsoft.com/en-us/library/ff512420.aspx Skopiowałem go, ale nie działa. Dostaję błąd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Media;
using System.IO;
namespace BingSpeak
{
class Program
{
public static void Speak()
{
string appId = "ID oczywiście podaje";
string text = "Speak this for me";
string language = "en";
string uri = "http://api.microsofttranslator.com/v2/Http.svc/Speak?appId=" + appId +
"&text;=" + text + "&language;=" + language;
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
//httpWebRequest.Proxy = new WebProxy(""); set your proxy name here if needed
WebResponse response = null;
try
{
response = httpWebRequest.GetResponse();
using (Stream stream = response.GetResponseStream())
{
using (SoundPlayer player = new SoundPlayer(stream))
{
player.PlaySync();
}
}
}
catch (WebException e)
{
ProcessWebException(e, "Failed to speak");
}
finally
{
if (response != null)
{
response.Close();
response = null;
}
}
}
private static void ProcessWebException(WebException e, string message)
{
Console.WriteLine("{0}: {1}", message, e.ToString());
// Obtain detailed error information
string strResponse = string.Empty;
using (HttpWebResponse response = (HttpWebResponse)e.Response)
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.ASCII))
{
strResponse = sr.ReadToEnd();
}
}
}
Console.WriteLine("Http status code={0}, error message={1}", e.Status, strResponse);
}
static void Main(string[] args)
{
Speak();
Console.ReadLine();
}
}
}
Wiem, że w temacie jest napisane Google Translator, ale przy użyciu Binga chyba będzie łatwiej.