vignesh
vignesh

Reputation: 51

Java text to speech API

I want text to speech implementation in my project for that I used java-google text to speech api https://code.google.com/p/java-google-translate-text-to-speech/ but it can recognize up to 100 characters only. If I give a long passage beyond 100 char it is showing error.

The speech should also be saved as a wav or mp3 file

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)

Is there any way to correct this error or suggest me a good open-source text to speech API that can be usable in Java.

Upvotes: 2

Views: 2232

Answers (1)

Mosa
Mosa

Reputation: 393

You can easy split your string and give the string in chunks like that:

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

Now I use for demonstration purpose whitespace to split the string.

Upvotes: 1

Related Questions