Dav*_*dNg 5 java text-to-speech
我正在尝试使用Java从Google Translate下载文本到语音.它适用于英语,但对于日语则不成功.以下是我的代码:
try{
String word="?????";
word=java.net.URLEncoder.encode(word, "UTF-8");
URL url = new URL("http://translate.google.com/translate_tts?tl=ja&q="+word);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.addRequestProperty("User-Agent", "Mozilla/4.76");
InputStream audioSrc = urlConn.getInputStream();
DataInputStream read = new DataInputStream(audioSrc);
OutputStream outstream = new FileOutputStream(new File("mysound.mp3"));
byte[] buffer = new byte[1024];
int len;
while ((len = read.read(buffer)) > 0) {
outstream.write(buffer, 0, len);
}
outstream.close();
}catch(IOException e){
System.out.println(e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
你有什么想法或建议吗?
您似乎需要告诉Google搜索字词包含UTF-8编码字符.
更改您的URL以http://translate.google.com/translate_tts?ie=UTF-8&tl=ja&q=解决我的问题..mp3与谷歌翻译网站的音频翻译相比,我下载的内容相同.
| 归档时间: |
|
| 查看次数: |
5141 次 |
| 最近记录: |