2014-10-28 169 views
2

我想在我的項目中使用文本到語音實現,因爲我使用java-google文本語音API https://code.google.com/p/java-google-translate-text-to-speech/,但它只能識別多達100個字符。如果我給出了超過100個字符的長通道,它顯示錯誤。java文本到語音api

講話也應保存爲WAV或MP3文件

java.io.FileNotFoundException: http://translate.google.com/translate_tts?q=Some%20JVMs%20put%20restrictions%20on%20the%20total%20amount%20of%20memory%20available%20on%20the%20heap%20If%20you%20are%20getting%20to.%20Some%20JVMs%20put%20restrictions%20on%20the%20total%20amount%20of%20memory%20available%20on%20the%20heap%20If%20you%20are%20getting%20to&tl=en 
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) 
at com.gtranslate.Audio.getAudio(Audio.java:34) 
at googl.STT.main(STT.java:25) 
Exception in thread "main" java.lang.NullPointerException: in 
at javazoom.jl.decoder.Bitstream.<init>(Unknown Source) 
at javazoom.jl.player.Player.<init>(Unknown Source) 
at javazoom.jl.player.Player.<init>(Unknown Source) 
at com.gtranslate.Audio.play(Audio.java:39) 
at googl.STT.main(STT.java:42) 

有什麼辦法來糾正這一錯誤或建議我一個很好的開源文本到語音API,可以在Java

可用
+2

爲什麼不把你的文本分成塊並分別傳入每個塊? – Floegipoky 2014-10-28 14:11:45

+1

我想將音頻也保存爲wav或mp3文件。如果拆分成塊,將很難加入所有這些,這將是一項額外的工作。 – vignesh 2014-10-28 14:29:48

+0

這裏是一個多語言的文本到語音[系統](https://github.com/marytts/marytts)。 – Luminous 2014-10-28 14:48:28

回答

1

你可以很容易分開你的字符串,並給字符串中那樣大塊:

String longString; 
... 
Audio audio = Audio.getInstance(); 
InputStream sound; 

String[] chunks = longString.split(" "); 
for(int i = 0; i < chunks.length; i++){ 
    sound = audio.getAudio(chunks[i], Language.ENGLISH); 
    audio.play(sound);        
} 

現在我使用的示範目的空格分割的字符串。