2016-04-30 4 views
7

Ich bin ein Anfänger in Java und ich folgte in Java ein Video-Tutorial über Text-zu-Sprache in diesem Link: https://www.youtube.com/watch?v=ameD1ocbn9sjava text to speech-Programm in Eclipse Mars nicht funktioniert Google Übersetzer mit

In hier traf ich auf einem Problem mit dem eclipse-mars, wenn diese Zusammenstellung program.It sagt wie folgt:

Hier ist mein Code:

import java.io.File; 
import java.io.FileInputStream; 
import java.io.IOException; 
import java.io.UnsupportedEncodingException; 
import java.net.URI; 
import java.net.URISyntaxException; 
import java.net.URLEncoder; 
import java.text.MessageFormat; 

import javazoom.jl.decoder.JavaLayerException; 
import javazoom.jl.player.Player; 
import us.monoid.web.BinaryResource; 
import us.monoid.web.Resty; 

//here,we loaded the javaLayer and resty lib files to this project 

public class TextToSpeech 
{ 
    //base url from google translator to get the sound, 
    //tts-text to speech ,q-translating text,tl-translating language 
    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) 
    { 
     speech("hello kalanka"); 
    } 
    public static void speech(String text) 
    { 

     try 
     { 
      File file=new File("temp.mp3");//temp file to save the sound from google 

      String sentence= URLEncoder.encode(text,"UTF-8");//encoding the text we send as utf-8 

      String urlString=MessageFormat.format(Base_URL,sentence,"en");// filling the baseUrl with arguments 
      //"en" means the English language 

      BinaryResource res=new Resty().bytes(new URI(urlString));//creating a rest object for the binary resources to get the mp3 file 
      //which will receive from google 

      res.save(file);//saving the binary res file in file that we created 

      FileInputStream in=new FileInputStream(file); 

      Player pp=new Player(in);//creating the Player object 

      pp.play();//playing the file 
      pp.close();//closing the play 
      file.delete();//deleting the file 

     } 
     catch (UnsupportedEncodingException e) 
     { 
      e.printStackTrace(); 
     } 
     catch (IOException e) 
     { 
      e.printStackTrace(); 
     } 
     catch (URISyntaxException e) 
     { 
      e.printStackTrace(); 
     } catch (JavaLayerException e) 
     { 
      e.printStackTrace(); 
     } 


    } 

} 

Hier ist der Fehler in voller Länge:

java.io.IOException: Error while reading from GET: [503] Service Unavailable 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
<head><meta http-equiv="content-type" content="text/html; charset=utf-8"><meta name="viewport" content="initial-scale=1"><title>http://translate.google.com/translate_tts?ie=UTF-8&amp;q=hello+kalanka&amp;tl=en&amp;prev=input</title></head> 
<body style="font-family: arial, sans-serif; background-color: #fff; color: #000; padding:20px; font-size:18px;" onload="e=document.getElementById('captcha');if(e){e.focus();}"> 
<div style="max-width:400px;"> 
<hr noshade size="1" style="color:#ccc; background-color:#ccc;"><br> 

    To continue, please type the characters below:<br><br> 
    <img src="/sorry/image?id=15657022896595218819&amp;q=CGMSBGf3MFUY-PWSuQUiGQDxp4NLgYkSgFOxxcQGJWJm5jZQLxCJi6c&amp;hl=en&amp;continue=http://translate.google.com/translate_tts%3Fie%3DUTF-8%26q%3Dhello%2Bkalanka%26tl%3Den%26prev%3Dinput" border="1" alt="Please enable images"><br><br><form action="CaptchaRedirect" method="get"><input type='hidden' name='q' value='CGMSBGf3MFUY-PWSuQUiGQDxp4NLgYkSgFOxxcQGJWJm5jZQLxCJi6c'><input type="hidden" name="continue" value="http://translate.google.com/translate_tts?ie=UTF-8&amp;q=hello+kalanka&amp;tl=en&amp;prev=input"><input type="hidden" name="id" value="15657022896595218819"><input type="text" name="captcha" value="" id="captcha" size="12" style="font-size:16px; padding:3px 0 3px 5px; margin-left:0px;"><input type="submit" name="submit" value="Submit" style="font-size:18px; padding:4px 0;"><br><br><br></form> 
    <hr noshade size="1" style="color:#ccc; background-color:#ccc;"> 

    <div style="font-size:13px;"> 
    <b>About this page</b><br><br>Our systems have detected unusual traffic from your computer network. This page checks to see if it&#39;s really you sending the requests, and not a robot. <a href="#" onclick="document.getElementById('infoDiv').style.display='block';">Why did this happen?</a><br><br> 
    <div id="infoDiv" style="display:none; background-color:#eee; padding:10px; margin:0 0 15px 0; line-height:1.4em;"> 
    This page appears when Google automatically detects requests coming from your computer network which appear to be in violation of the <a href="//www.google.com/policies/terms/">Terms of Service</a>. The block will expire shortly after those requests stop. In the meantime, solving the above CAPTCHA will let you continue to use our services.<br><br>This traffic may have been sent by malicious software, a browser plug-in, or a script that sends automated requests. If you share your network connection, ask your administrator for help &mdash; a different computer using the same IP address may be responsible. <a href="//support.google.com/websearch/answer/86640">Learn more</a><br><br>Sometimes you may be asked to solve the CAPTCHA if you are using advanced terms that robots are known to use, or sending requests very quickly. 
    </div> 




IP address: 103.247.48.85<br>Time: 2016-04-30T14:02:34Z<br>URL: http://translate.google.com/translate_tts?ie=UTF-8&amp;q=hello+kalanka&amp;tl=en&amp;prev=input<br> 
</div> 
</div> 
</body> 
</html> 

    at us.monoid.web.AbstractResource.fill(AbstractResource.java:51) 
    at us.monoid.web.Resty.fillResourceFromURL(Resty.java:432) 
    at us.monoid.web.Resty.doGET(Resty.java:388) 
    at us.monoid.web.Resty.bytes(Resty.java:355) 
    at main.TextToSpeech.speech(TextToSpeech.java:42) 
    at main.TextToSpeech.main(TextToSpeech.java:28) 
Caused by: java.io.IOException: Server returned HTTP response code: 503 for URL: http://ipv4.google.com/sorry/IndexRedirect?continue=http://translate.google.com/translate_tts%3Fie%3DUTF-8%26q%3Dhello%2Bkalanka%26tl%3Den%26prev%3Dinput&q=CGMSBGf3MFUY-PWSuQUiGQDxp4NLgYkSgFOxxcQGJWJm5jZQLxCJi6c 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840) 
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) 
    at us.monoid.web.AbstractResource.fill(AbstractResource.java:30) 
    ... 5 more 

Bitte helfen Sie mir in diesem Code ....

+1

Geben Sie dem _full_ Ausnahme-Stack-Trace. Dazu gehört die erste Zeile, die angibt, welche Ausnahme tatsächlich ausgelöst wird. – bcsb1001

+1

@ bcsb1001 Ich habe die Frage mit der vollständigen Fehlermeldung editiert.aber ich denke, es ist etwas mit der Eclipse in Verbindung mit Google Translator.Ich weiß nicht, was zu tun ist.Same Fehlermeldung kommt mit Netbeans too.please Hilfe. .. – Kalanka

Antwort

Verwandte Themen