2012-11-12 9 views
5

मैं जावा का उपयोग करके Google अनुवाद से भाषण में पाठ डाउनलोड करने का प्रयास कर रहा हूं। यह अंग्रेजी भाषा के साथ ठीक काम करता है, लेकिन जापानी के साथ यह सफल नहीं है। मेरा कोड निम्नलिखित है:जावा: Google अनुवाद से टेक्स्ट टू स्पीच डाउनलोड करें

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()); 
} 

क्या आपके पास कोई विचार या सुझाव है?

+0

जापानी के साथ क्या होता है? –

+0

मुझे फ़ाइल नहीं मिला – DavidNg

+0

शून्य आकार फ़ाइल है, या यह दूषित है? –

उत्तर

6

ऐसा लगता है कि आपको Google को यह बताना होगा कि खोज शब्द में यूटीएफ -8 एन्कोडेड वर्ण हैं।

http://translate.google.com/translate_tts?ie=UTF-8&tl=ja&q= पर अपना यूआरएल बदलना मेरे लिए समस्या को हल करता है। मुझे Google अनुवाद साइट से ऑडियो अनुवाद की तुलना में वही .mp3 डाउनलोड किया गया है।

+1

सही रन, धन्यवाद – DavidNg

संबंधित मुद्दे