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