我正在使用谷歌翻译来做一些文字转语音。该课程如下:
public static final String BASE_URL = "https://translate.google.com/translate_tts?ie=UTF-8&q=test&tl=zh-TW&client=tw-ob";
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, "en");
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();
f.delete();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (URISyntaxException e) {
e.printStackTrace();
} catch (JavaLayerException e) {
e.printStackTrace();
}
}
我的主要人物:
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
say("Hello World");
}
尽管改变了我的主要文本,但我的程序继续用相同的词语...用外语。不确定它在说什么或为什么它没有改变。没有错误......有什么建议吗?