文字转语音翻译

时间:2016-03-16 04:46:31

标签: java text-to-speech

我使用text to speech translator api将文本转换为另一种语言。我将gtranslateapi-1.0.jar和jl-1.0.jar文件添加到库路径中。这是我的代码段

public class NextTranslator {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Translator translate = Translator.getInstance();
        String text = translate.translate("I am programmer", Language.ENGLISH, Language.PORTUGUESE);
        System.out.println(text);
        /*  Translator translate = Translator.getInstance();
         String prefix = translate.detect("I am a bus");
         System.out.println(prefix);*/
    }

}

作为输出我收到以下错误

java.net.UnknownHostException: translate.google.com.br

    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at java.net.Socket.connect(Socket.java:538)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1168)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1104)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:998)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:932)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1512)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
    at com.gtranslate.utils.WebUtils.source(WebUtils.java:24)
    at com.gtranslate.parsing.ParseTextTranslate.parse(ParseTextTranslate.java:19)
    at com.gtranslate.Translator.translate(Translator.java:37)
    at nexttranslator.NextTranslator.main(NextTranslator.java:22)
BUILD SUCCESSFUL (total time: 0 seconds)

我无法弄清楚如何解决这个问题。提前谢谢

已更新 检查DNS连接后发生错误。

java.io.IOException: Server returned HTTP response code: 403 for URL: http://translate.google.com.br/translate_a/t?client=t&text=I%20am%20programmer&hl=en&sl=en&tl=pt&multires=1&prev=btn&ssel=0&tsel=0&sc=1
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1839)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
    at com.gtranslate.utils.WebUtils.source(WebUtils.java:24)
    at com.gtranslate.parsing.ParseTextTranslate.parse(ParseTextTranslate.java:19)
    at com.gtranslate.Translator.translate(Translator.java:37)
    at nexttranslator.NextTranslator.main(NextTranslator.java:24)
BUILD SUCCESSFUL (total time: 0 seconds)

这意味着我需要apikey。这意味着我不能在没有密钥的情况下使用文本到语音api吗?但是根据以下链接https://code.google.com/archive/p/java-google-translate-text-to-speech/ 它说这个api是免费的。我可以在java Web应用程序中免费使用文本翻译器吗?

0 个答案:

没有答案