5
我想從谷歌翻譯下載文本到語音使用Java。它適用於英語,但日語並不成功。以下是我的代碼:Java:從谷歌翻譯下載文本到語音
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());
}
你有什麼想法或建議嗎?
日本人怎麼了? –
我得到的文件沒有聲音 – DavidNg
是零大小的文件,或者它已損壞? –