Jak użyć Google Translator w własnym programie. Odtworzenie nagrania.

0

Witam, znalazłem kilka przykładów użycia Google Translatora w programie, do tłumaczenia słów. Teraz mam pytanie Google Translator umożliwia przeczytanie słowa/odtworzenie nagrania, czy można odtworzyć to nagranie w programie? W przykładach jest tylko tłumaczenie słów, a nie ma nigdzie przycisku Słuchaj, tak jak jest to na stronie http://translate.google.pl/

Na przykład mam textBoxa, użytkownik wpisał słowo age, klika przycisk i odtwarza mu się nagranie tego słowa z Google Translator, czy to jest możliwe do wykonania? Jeśli tak to proszę jakieś podpowiedzi jak to zrobić, czego szukać w internecie.
Tutaj to co znalazłem:
http://www.codeproject.com/KB/IP/GoogleTranslator.aspx
http://blogs.msdn.com/b/shahpiyush/archive/2007/06/09/3188246.aspx
http://social.msdn.microsoft.com/Forums/en/netfxnetcom/thread/b251b21c-4c66-44ff-93ae-48c4eef28662
http://www.dreamincode.net/code/snippet4248.htm
http://martinnormark.com/translate-text-in-c-using-google-translate-revisited

0

Kiedyś napisałem takie coś, piękne nie jest ale działało

class Translator
    {
        public static string Translate(string from, string to, string text)
        {
            WebClient cl = new WebClient();
            string url = string.Format("http://translate.google.com/?eotf=1&text={2}&sl={0}&tl={1}", from, to, text);
            cl.Encoding = Encoding.UTF7;
            string result = cl.DownloadString(url);
            Match m = Regex.Match(result, "(?<=onmouseout=\"this.style.backgroundColor='#fff'\">)(.*?)(?=</span>)");
            if (m.Success)
            {
                return System.Uri.UnescapeDataString(Regex.Replace(m.Value, @"<(.|\n)*?>", string.Empty)).Replace("&quot;", "\"").Replace("&amp;", "&").Replace("&nbsp;", " ").Replace("&lt;", "<").Replace("&gt;", ">");
            }
            else
            {
                return "";
            }
        }
    }

Piękną obróbką znaków specjalnych mam :P

0

aa, sory, nie doczytałem że chcesz odtworzyć dźwięk :)

0

Odpal sobie śledzenie sieci ( FireBug, LiveHTTP w Firefox, w Operze jest chyba na stanardzie, w nowym IE wciskasz F12 ) i widzisz że jakiś JS woła coś w stylu:
http://translate.google.pl/translate_tts?ie=UTF-8&q=car&tl=en&prev=input
Poprzedzane przez
http://translate.google.pl/translate_a/t?client=t&text=house&hl=pl&sl=en&tl=pl&multires=1&otf=1&ssel=0&tsel=0&sc=1

Spróbuj to wywołać, nie mam czasu bawić się teraz.
Daj znać jak się uda :)

0

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.

1 użytkowników online, w tym zalogowanych: 0, gości: 1