2

I have used the following code to convert text to speech, but I am getting the following errors:

errors

Caused by: java.io.IOException: Server returned HTTP response code: 503 for URL: http://ipv4.google.com/sorry/IndexRedirect?continue=http://translate.google.com/translate_tts%3Fie%3DUTF-8%26q%3DHello%2BWorld%26tl%3Dde%26prev%3Dinput&q=CGMSBCmIeyUYvpnkrwUiGQDxp4NLHAGq2VYVjoplnZ0vwMrZvShTrYA at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at us.monoid.web.AbstractResource.fill(AbstractResource.java:30) ... 5 more

Java Codes

public class TextToSpeech {

private static final String BASE_URL = "http://translate.google.com/translate_tts?ie=UTF-8&q={0}&tl={1}&prev=input";

public static void main(String[] args) {
    say("Hello World");
}

public static void say(String text) {
    try {
        File f = new File("translate.mp3");
        String sentence = URLEncoder.encode(text, "UTF-8");
        String urlString = MessageFormat.format(BASE_URL, sentence, "de");
        BinaryResource res = new Resty().bytes(new URI(urlString));
        res.save(f);

        FileInputStream in = new FileInputStream(f);

        Player p = new Player(in);

        p.play();

        p.close();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    } catch (JavaLayerException e) {
        e.printStackTrace();
    }

Note that I have already included the jar files JLayer & Resty.. Please help ! Thanks

James Smith
  • 55
  • 2
  • 11
  • Seems like the server is temporarily unavailable. Have a look at http://stackoverflow.com/questions/30492370/server-returned-http-response-code-503-for-url – Balwinder Singh Sep 16 '15 at 06:45
  • @BalwinderSingh Is there any alternatives ? – James Smith Sep 16 '15 at 06:48
  • you cannot use directly the url like this - you need to create a developper account and have credentials to use the service, see https://developers.google.com/api-client-library/java/apis/translate/v2 – Frederic Henri Sep 16 '15 at 06:49
  • @FredericHenri meaning the service is no more publicly available ? Is there any alternatives to this ? – James Smith Sep 16 '15 at 06:51
  • the service is available but you need to authenticate yourself, see the link I provide you. If you have google account it should be sufficient – Frederic Henri Sep 16 '15 at 06:53
  • Yes, I have already login with my google account.. What is the next step to do ? Any changes in my code ? – James Smith Sep 16 '15 at 06:56
  • Where do you do that in your code ? you're not passing any credentials. you should definitely read through the guide from google. There's too much to post to make a single answer – Frederic Henri Sep 16 '15 at 11:50
  • Can you just please advise me where should I pass the credentials ? – James Smith Sep 16 '15 at 13:06

0 Answers0