我使用以下代码将文本转换为语音,但我收到以下错误:
错误
引起:java.io.IOException:服务器返回HTTP响应代码:503为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个
Java代码
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();
}
请注意,我已经包含了jar文件JLayer& Resty ..请帮忙!感谢