【发布时间】:2012-11-05 00:12:14
【问题描述】:
我正在尝试创建一个说希腊语的应用程序。但由于 Microsoft 不支持将希腊语作为一种口语,而且我对如何创建自己的词典 (here) 的指南提出了问题,所以我问这个问题:
如何下载包含我在运行时发送给谷歌翻译的文本的 mp3(或只是数据无关紧要)并使用 C# 播放?
【问题讨论】:
标签: c# google-translate text-to-speech
我正在尝试创建一个说希腊语的应用程序。但由于 Microsoft 不支持将希腊语作为一种口语,而且我对如何创建自己的词典 (here) 的指南提出了问题,所以我问这个问题:
如何下载包含我在运行时发送给谷歌翻译的文本的 mp3(或只是数据无关紧要)并使用 C# 播放?
【问题讨论】:
标签: c# google-translate text-to-speech
只需使用此链接下载 MP3:
http://translate.google.com/translate_tts?tl=el&q=%22hello%22
编辑: 请注意,某些浏览器(例如 Firefox)会将 %22 替换为 ",并且链接不起作用,因此您需要复制它并且无法单击它!
如何下载文件: http://www.csharp-examples.net/download-files/
http://msdn.microsoft.com/en-us/library/ez801hhe.aspx
如何播放 MP3: http://msdn.microsoft.com/en-us/library/4y171b18.aspx
using System.Media;
String strTextYouWantAsMp3 = "Hello";
WebClient webClient = new WebClient();
webClient.DownloadFile("http://translate.google.com/translate_tts?tl=el&q=%22" + strTextYouWantAsMp3 + "%22", @"c:\audio.mp3");
SoundPlayer simpleSound = new SoundPlayer(@"c:\audio.mp3");
simpleSound.Play();
【讨论】:
SoundPlayer 不播放 MP3。它在MSDN reference 中特别说明了这一点。我发现的唯一方法是使用 WMPLib COM 控件来播放 MP3。
此链接现已损坏,您可以在此处参考 Chris Cirefice 的答案: Google Text-To-Speech API
按照建议,您需要针对以下 URL 发出获取请求
http://translate.google.com/translate_tts?tl=en&q=Hello%20World&client=t
其中q={your word you want to translate} 和tl={your language}
【讨论】: