Tôi đang cố tải xuống văn bản thành lời nói từ Google Dịch bằng Java. Nó hoạt động tốt với ngôn ngữ tiếng Anh, nhưng với tiếng Nhật nó không thành công. Sau đây là mã của tôi:Java: tải xuống Văn bản thành Lời nói từ Google Dịch
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());
}
Bạn có ý tưởng hoặc đề xuất nào không?
điều gì xảy ra với tiếng Nhật? –
Tôi nhận được tệp không có âm thanh – DavidNg
là tệp có kích thước bằng không hoặc tệp bị hỏng? –