我試圖下載一個由谷歌翻譯生成的MP3文件和雖然要達到這個,翻譯並不如預期。C#下載文本到谷歌語音轉換帶有問題
我葡萄牙語和我們使用很多特殊字符的,我認爲這是問題...
string text = "Teste de criação no ficheiro";
string googleTextToSpeech = "http://translate.google.com/translate_tts?tl=pt&q=";
string url = googleTextToSpeech + HttpUtility.UrlEncode(text);
string url2 = googleTextToSpeech + text;
using (WebClient myWebClient = new WebClient())
{
myWebClient.DownloadFile(url, pathToSaveFile + "\\" + "mp3CriationTest.mp3");
myWebClient.DownloadFile(url2, pathToSaveFile + "\\" + "mp3CriationTest2.mp3");
}
的文件實際上創建的,但在這兩種情況下的聲音說同樣的事情: OK直到「Teste de cria」(在'ç'和'〜'之前)並且確定爲「沒有ficheiro」。在中間的聲音說的東西不是很明確... 希望我是明確的。 =)
正如你所看到的,我嘗試使用和不使用UrlEncode
和相同的結果...我嘗試UrlEncode所有url也。 我用BinaryWriter
來試試,問題是一樣的。 我嘗試通過new Uri(url)
在myWebClient.DownloadFile
並沒有任何變化。
最讓我惱火的是如果你把url結果放到你的瀏覽器中,你可以聽到正確的文本到語音。 試試看:http://translate.google.com/translate_tts?tl=pt&q=Teste de criação no ficheiro
「Teste decriaçãono ficheiro」代表「文件創建測試」。
這是因爲網址錯誤的字符編碼的可能。您的示例網址適用於瀏覽器。 url和url2是什麼樣的? – bzlm
我認爲WebClient.DownloadFile是英文的,並改變我的特殊字符爲英文對應的。我檢查了我的myWebClient.Encoding,但它附帶「iso-8859-1:西歐(Windows)」正確的=( –
我不知道更多要做什麼,希望能幫助我或給予 –