rogerm104 / java-google-translate-text-to-speech

Automatically exported from code.google.com/p/java-google-translate-text-to-speech
0 stars 0 forks source link

The audio is 'jerky' or it is not present at all for a few languages, when running outside the IDE. #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. I build a very simple program using this API.
2. Added gtranslateapi-1.0.jar and jl1.0.jar to Libraries so they can be 
compiled. 
3. Run the program in NetBeans IDE by hitting play button.
4. Works excellent with ANY language.
5. Run the program outside the IDE by double clicking the jar. The audio is 
'jerky' or it is not present at all. (there is NO error thrown when running the 
jar outside the IDE).

What is the expected output? What do you see instead?

When running outside the IDE and using text to speech in Chinese, Japanese, 
Hindi or Arabic the audio is 'jerky' or it is not present at all.

What version of the product are you using? On what operating system?
1.0

Please provide any additional information below.

I experienced this problem with Chinese, Japanese, Hindi and Arabic so far. The 
other languages plays well both in IDE and outside the IDE.
This is very strange.

Here is the code

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package googletranslatetest;

import com.gtranslate.Audio;
import com.gtranslate.Language;
import com.gtranslate.Translator;
import java.io.IOException;
import java.io.InputStream;
import javazoom.jl.decoder.JavaLayerException;

/**
 *
 * @author PHLOO
 */
public class GoogleTranslateTest {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) throws IOException, JavaLayerException {
Translator translate = Translator.getInstance();
String text = translate.translate("I am programmer", Language.ENGLISH, 
Language.ROMANIAN);
System.out.println(text);

Audio audio = Audio.getInstance();
InputStream sound  = audio.getAudio(translate.translate("This is a demo text!", 
Language.ENGLISH, Language.CHINESE), Language.CHINESE);
audio.play(sound);
    }
}

Original issue reported on code.google.com by virtejfl...@gmail.com on 9 May 2013 at 9:37

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Here is what I discovered more: 

If you try to do text to speech in Chinese and you call getAudio method by 
passing normal Latin characters, the audio will be played correctly in IDE AND 
outside the IDE.

If you call getAudio with Chinese characters, no audio will be returned when 
running from outside the IDE only when running from IDE.

So there must be something wrong when calling with these special Chinese, 
Japanese, Hindi, Arabic characters ....  

Example: 

//THIS WORKS WELL BOTH IN IDE AND OUTSIDE THE IDE
Audio audio = Audio.getInstance();
InputStream sound  = audio.getAudio("aaaaabbbbcccc", Language.CHINESE);
audio.play(sound);

//THIS WORKS ONLY INSIDE IDE
Audio audio = Audio.getInstance();
InputStream sound  = audio.getAudio("但所给內容兩相矛盾", 
Language.CHINESE);
audio.play(sound);

Anyway this work is fantastic. Thank you!

Original comment by virtejfl...@gmail.com on 9 May 2013 at 10:14

GoogleCodeExporter commented 8 years ago
Found the solution:

in getAudio method, you must encode the text to be played, to UTF-8, before 
appending it to the URL:

String encodedString = URLEncoder.encode(text, "UTF-8");

                URL url = new URL(URLCONSTANTS.GOOGLE_TRANSLATE_AUDIO + "q="
                                + encodedString + "&tl=" + languageOutput);

Now it works fine!!! 

Original comment by virtejfl...@gmail.com on 9 May 2013 at 10:58

GoogleCodeExporter commented 8 years ago
thanks....its working

Original comment by xyza6...@gmail.com on 19 Mar 2014 at 9:22