Android 文本转语音服务突然停止

Android Text To Speech Service Stopped suddenly

这是我的文本转语音服务部分,我在其中获取数据并且工作正常,现在我收到此错误“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" When I open the same on browser I am getting this and if I am writing the characters I am getting the required data.Is this a common issue or google has changed something please help

                                // 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;

你真聪明 ;)

但是你要记住,当你从页面源使用link时,它会改变。 Google 只是阻止你,因为你提出了很多要求或类似的事情。

您有 3 个解决方案:

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

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

  3. 使用 Android (TextToSpeech) 中的内置 TTS 服务 - 你必须知道这是小马车。