Package com.gtranslate

Source Code of com.gtranslate.Audio

package com.gtranslate;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

public class Audio {
  private static Audio audio;

  private Audio() {
  }

  public synchronized static Audio getInstance() {

    if (audio == null) {
      audio = new Audio();
    }
    return audio;
  }

  public InputStream getAudio(String text, String languageOutput)
      throws IOException {

    URL url = new URL(URLCONSTANTS.GOOGLE_TRANSLATE_AUDIO + "q="
        + text.replace(" ", "%20") + "&tl=" + languageOutput);
    URLConnection urlConn = url.openConnection();
    urlConn.addRequestProperty("User-Agent",
        "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
    InputStream audioSrc = urlConn.getInputStream();
    return new BufferedInputStream(audioSrc);
  }

  public void play(InputStream sound) throws JavaLayerException {
    new Player(sound).play();
  }

}
TOP

Related Classes of com.gtranslate.Audio

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.