【问题标题】:Android Text To Speech Service Stopped suddenlyAndroid 文字转语音服务突然停止
【发布时间】:2015-07-28 14:59:16
【问题描述】:

这是我的文本到语音服务部分,我在其中获取数据并且工作正常,现在我收到此错误“java.io.FileNotFoundException:http://ipv4.google.com/sorry/IndexRedirect?continue=http://translate.google.com/translate_tts%3Ftl%3Den-AU%26q%3Dhello%2Bhow%2Bare%2Byou%2Btoday%2B&q=CGMSBMpY7fgYhL_crQUiGQDxp4NL6gmQZhZKyI3fztC8pj7G18P2vhg”当我在浏览器上打开相同的内容时,我得到了这个如果我正在写字符,我将获得所需的数据。这是一个常见问题还是谷歌改变了某些东西,请帮助

                                // data
    {

        // Log.e("JUSTLOGGINGURL", text);
        text = URLEncoder.encode(text, "UTF-8");
        String voiceUrl = "http://translate.google.com/translate_tts?tl="
                + lang_to + "&q=" + text;
        // Log.e("JUSTLOGGINGURL", voiceUrl);

        HttpURLConnection con = null;
        InputStream is = null;
        try {

            URL url = new URL(voiceUrl);
            con = (HttpURLConnection) url.openConnection();
            con.setRequestProperty(
                    "User-Agent",
                    "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9.2.2) Gecko/20100316 Firefox/3.6.2");
//          con.setRequestProperty(
//                  "User-Agent",
//                  "Mozilla/5.0 (Linux; Android 4.0.0; Nexus 7 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Safari/537.36");
            con.setRequestMethod("GET");
            con.setDoInput(true);
            con.connect();
            is = con.getInputStream();

        } catch (IOException e) {
            e.printStackTrace();
            is = null;
            return is;

        }
        return is;

【问题讨论】:

标签: android text-to-speech google-text-to-speech


【解决方案1】:

你很聪明;)

但是你必须记住,当你使用来自页面源的链接时,它会改变。 谷歌只是阻止你,因为你提出了很多要求或类似的事情。

您有 3 个解决方案:

  1. 使用 Google 翻译 API 并付款 - Here you have Pricing

  2. 使用另一个可免费用于商业用途的 API - 这里有一些 free API。但是如果你想要更多,你必须在谷歌中四处看看。

  3. 在 Android 中使用 Build in TTS 服务(TextToSpeech) - 你必须知道它有一点小错误。

【讨论】:

  • 是的。这将是那里的关键。我认为它适用于公钥和私钥。如果我帮助你,请接受我的回答。在这里查看更多信息console.developers.google.com/project
  • 我会接受答案,如果我没有为您的时间获得任何其他解决方案 +1 :)
  • 看,它可能会有所帮助。但是您必须在服务器上制作自己的服务。你必须知道它的解决方法,所以它可以停止工作。有来自谷歌翻译的 TTS。 github.com/soimort/translate-shell
  • 谢谢,找到了另一种解决方法,但我会接受你的回答。可能对其他人有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-23
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 2018-11-18
相关资源
最近更新 更多