1

Topic: How to make Text to speech by means of Java and Eclipse on googl

Hello. My question more low. At first short introduction. Now I learn Java (I use Eklips) and came across the following educational example - which represents a program variation text-to-speech (TTS) on Java. Actually program lies here Lesson01_Speech.zip. The program essence (it consists of 2 classes and connected library) is reduced to the following: to Connect the project to library JLayer (jl1.0.1.jar) for playback mp3 with java to Create a class copy: GoogleTextToSpeech gtts = new GoogleTextToSpeech () to Use a method: gtts.say ("Hello everybody", "en") the First argument a phrase for the pronouncing, the second - language. I added in a program the comments (in English) and commented out explicitly  a line, now the program looks so (Main class): package com.example. TTS;//package of class Main import com.example. TTS.GoogleTextToSpeech; //import class GoogleTextToSpeech public class Main {public static void main (String [] args) {GoogleTextToSpeech gtts = new GoogleTextToSpeech ();//make instance gtts gtts.say ("Hello dear friends", "en");//use method say//gtts.say ("Bonjour mon amis!", "fr");} } GoogleTextToSpeech class: package com.example. TTS;//package of class GoogleTextToSpeech import java.io. InputStream;//import classes from Java library import java.net. HttpURLConnection; import java.net. URL; import java.net. URLConnection; import java.net. URLEncoder; import javazoom.jl.player. Player;//import class from jl1.0.1.jar public class GoogleTextToSpeech {private static String ENCODING = "UTF-8";//make constants and assign values to them private static String URL_BEGINNING = "http://translate.google.com/translate_tts?ie="; private static String URL_QUERY = "&q="; private static String URL_TL = "&tl="; private static String USER_AGENT_LITERAL = "User-Agent"; private static String USER_AGENT = "Mozilla/4.7"; public void say (String phrase, String lang) {try {//Make full URL phrase=URLEncoder.encode (phrase, ENCODING); //assign value to variable with name ' phrase ' by use method encode from class URLEncoder String sURL = URL_BEGINNING + ENCODING + URL_TL + lang + URL_QUERY + phrase;//assign value to variable sURL URL url = new URL (sURL);//make instance url with constructor//Create connection URLConnection urlConn = url.openConnection ();//assign value to variable urlConn HttpURLConnection httpUrlConn = (HttpURLConnection) urlConn;//Declaring httpUrlConn var of type HttpURLConnection, assigning it value to var urlConn (reduce to HttpURLConnection) httpUrlConn.addRequestProperty (USER_AGENT_LITERAL, USER_AGENT);//use method//Create stream InputStream mp3WebStream = urlConn.getInputStream ();//create instance and assign it a value//Play stream Player plr = new Player (mp3WebStream);//create instance plr with constructor plr.play ();//use method}//use exception with name ex catch (Exception ex) {ex.printStackTrace (); //use method}}} I Start the program by choice Run as-> Java Application on Main.java. Also I have the following output (in  consoles): java.io. IOException: Server returned HTTP response code: 503 for URL:http://ipv4.google.com/sorry/index?continue=http://translate.google.com/translate_tts%3Fie%3DUTF-8%26tl%3Den%26q%3DHello%2Bdear%2Bfriends&q=EgRbegWvGJ3FldEFIhkA8aeDS952qU94sbK8DAgP55pH8cbMicZdMgFy at sun.net.www.protocol.http.HttpURLConnection.getInputStream0 (HttpURLConnection.java:1894) at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java:1492) at com.example. TTS.GoogleTextToSpeech.say (GoogleTextToSpeech.java:32) at com.example. TTS.Main.main (Main.java:9) Everything that I understood at present, it that: in my case an error in lines: at com.example. TTS.GoogleTextToSpeech.say (GoogleTextToSpeech.java:32) at com.example. TTS.Main.main (Main.java:9) then library MP3 Decoder code / player / converter which opens connection with translate.google.com, which is caused: 1.  on page with CAPTCHA 2. Returns the status 503 Service it is inaccessible My questions: 1. I not absolutely understand, how this program works and what for the library jl1.0.1.jar is necessary to it. It can be possible to do without library and to work directly with API? 2. What to do, that the program worked correctly? Perhaps, I need to be registered Google that I could use this API without ?

2

Re: How to make Text to speech by means of Java and Eclipse on googl

Hello, sasvak, you wrote: S> My questions: S> 1. I not absolutely understand, how this program works and what for the library jl1.0.1.jar is necessary to it. It can be possible to do without library and to work directly with API? After a line "//Play stream" it is used for flow playback (probably, audio), received as inquiry answer to service tts. S> 2. What to do, that the program worked correctly? Perhaps, I need to be registered Google that I could use this API without ? Yes, added captch because of it broke, looking it is possible to find a little that it is necessary to add one more argument (client=tw-ob) in request: http://translate.google.com/translate_tts?ie=UTF-8 &q=test &tl=en &client=tw-ob Remaining arguments at you are, result the URL in such type and should earn (but can be at frequent reversal to tts simply will to refuse).

3

Re: How to make Text to speech by means of Java and Eclipse on googl

Hello, UDI, you wrote: UDI> Hello, sasvak, you wrote: S>> My questions: S>> 1. I not absolutely understand, how this program works and what for the library jl1.0.1.jar is necessary to it. It can be possible to do without library and to work directly with API? UDI> After a line "//Play stream" it is used for flow playback (probably, audio), received as inquiry answer to service tts. S>> 2. What to do, that the program worked correctly? Perhaps, I need to be registered Google that I could use this API without ? UDI> Yes, added captch because of it broke, looking it is possible to find a little that it is necessary to add one more argument (client=tw-ob) in request: UDI> UDI> http://translate.google.com/translate_tts?ie=UTF-8 &q=test &tl=en &client=tw-ob UDI> Remaining arguments at you are, result the URL in such type and should earn (but can be at frequent reversal to tts simply will to refuse). I will check, tell, , I like delivered you "thanks", but would like, that other participants also gave the answers. That is: what I CANNOT push (cups of different types, a finger upwards and ) that remaining  saw this question yet not received the final answer?

4

Re: How to make Text to speech by means of Java and Eclipse on googl

Hello, sasvak, you wrote: S> I Will check, tell, , I like delivered you "thanks", but would like, that other participants also gave the answers. That is: what I CANNOT push (cups of different types, a finger upwards and ) that remaining  saw this question yet not received the final answer? With the advent of new subjects your subject will drift downwards with the list. It can be lifted upwards new messages. There is no sign of the final answer in the list that a forum (there it will not be written [IS solved]). No estimations of answers to it influence. If you are satisfied by answers in a subject can summarize a subject the message and write in it shortly outputs (even  you found the answer and anybody any more did not write that people with the same problem could find the decision in the future). Well and in a root undressed "Forums" can esteem rules.