Windows phone 7 使用谷歌&x27;s在WP7上的文本到语音转换

Windows phone 7 使用谷歌&x27;s在WP7上的文本到语音转换,windows-phone-7,webclient,text-to-speech,http-status-code-403,Windows Phone 7,Webclient,Text To Speech,Http Status Code 403,我正在编写一些代码,使用一个简单的GET方法使用googletranslate的文本到语音,我很困惑为什么它不起作用。例如,单击 我写了一些C#代码,据我所知,它应该能工作,但它不能。我想知道谷歌是否在阻止这些请求?从控制台尝试此操作会出现403错误(“禁止”) 下面是代码。如果有人能帮忙,我将不胜感激 namespace WCTest { public partial class MainPage : PhoneApplicationPage { string

我正在编写一些代码,使用一个简单的GET方法使用googletranslate的文本到语音,我很困惑为什么它不起作用。例如,单击

我写了一些C#代码,据我所知,它应该能工作,但它不能。我想知道谷歌是否在阻止这些请求?从控制台尝试此操作会出现403错误(“禁止”)

下面是代码。如果有人能帮忙,我将不胜感激

namespace WCTest
{
    public partial class MainPage : PhoneApplicationPage
    {
        string searchString = "http://translate.google.com/translate_tts?tl=en&q=hello"; 

        // Constructor
        public MainPage()
        {
            InitializeComponent();

            WebClient client = new WebClient();
            client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
            client.Headers["Referrer"] = "http://brillisoft.com"; 

            client.OpenReadCompleted += (s, e) =>
            {
                if (e.Error == null)
                {
                    Stream audio = e.Result;
                    mediaElement1.SetSource(audio);
                    mediaElement1.Play();
                }
            };

            client.OpenReadAsync(new Uri(searchString));

        }
    }
}
更新。。。三月十日

故事还在继续。。。以下代码在我同事的一些计算机上有效,但在我的计算机上无效。。。是什么原因造成的?请让我知道这是否适用于您,如果您认为有必要将文件保存到IsolatedStorage

namespace PhoneApp1 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
        // Constructor 
        public MainPage() 
        { 
            InitializeComponent(); 
        } 

        string searchString = "http://translate.google.com/translate_tts?tl=en&q=it+works"; 

        private void button1_Click(object sender, RoutedEventArgs e) 
        { 
            WebClient client = new WebClient(); 

            client.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0)" + " (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"; 

            client.Headers[HttpRequestHeader.Referer] = "http://translate.google.com"; 

            client.OpenReadCompleted += (s, ex) => 
            { 

                if (ex.Error == null) 
                { 
                    using (var store = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) 
                    { 
                        if (store.FileExists("hello3.mp3")) 
                        { 
                            store.DeleteFile("hello3.mp3"); 
                        } 
                        using (var fs = new System.IO.IsolatedStorage.IsolatedStorageFileStream("hello3.mp3", System.IO.FileMode.Create, store)) 
                        { 
                            byte[] bytesInStream = new byte[ex.Result.Length]; 
                            ex.Result.Read(bytesInStream, 0, (int)bytesInStream.Length); 
                            fs.Write(bytesInStream, 0, bytesInStream.Length); 
                            fs.Flush(); 

                            mediaElement1.SetSource(fs); 
                        } 
                    } 

                    mediaElement1.Play(); 

                } 

            }; 

            client.OpenReadAsync(new Uri(searchString)); 
        } 
    } 
} 

它在浏览器中工作吗?这是我的。如果您试图欺骗标题,请确保您在浏览器上设置了所有标题。是的,如果我设置了用户代理,它可以从浏览器和控制台工作。。。