Friday, September 12, 2014

JavaFX with text-to-speech, with java-google-translate-text-to-speech

To add text-to-speech function to JavaFX application, we can using java-google-translate-text-to-speech, an Api unofficial with the main features of Google Translate in Java.

This video show how to add download and add the library of java-google-translate-text-to-speech tyo Netbeans, and create Hello World with text-of-speech in Netbeans.

package javafx_texttospeech;

import com.gtranslate.Audio;
import com.gtranslate.Language;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javazoom.jl.decoder.JavaLayerException;

 * @web
public class JavaFX_TextToSpeech extends Application {
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            public void handle(ActionEvent event) {
                InputStream sound = null;
                try {
                    System.out.println("Hello World!");
                    Audio audio = Audio.getInstance();
                    sound = audio.getAudio("Hello World", Language.ENGLISH);
                } catch (IOException | JavaLayerException ex) {
                    Logger.getLogger(JavaFX_TextToSpeech.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                    try {
                    } catch (IOException ex) {
                        Logger.getLogger(JavaFX_TextToSpeech.class.getName()).log(Level.SEVERE, null, ex);
        StackPane root = new StackPane();
        Scene scene = new Scene(root, 300, 250);
        primaryStage.setTitle("Hello World!");

     * @param args the command line arguments
    public static void main(String[] args) {

- Google Translater (with tts) on JavaFX

1 comment:

  1. i had this problem Server returned HTTP response code: 503 for URL: