public static void speakNow(String content) throws Exception{
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + URLEncoder.encode(content));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
try {
try {
Player player = new Player(new BufferedInputStream(
entity.getContent()));
player.play();
} catch (Exception e) {
System.out.println("语音播报功能出错了");
System.out.println(e.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
}
if(httpclient!=null)
httpclient.close();
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&text=" + URLEncoder.encode(content));
HttpResponse response = httpclient.execute(httpost);
HttpEntity entity = response.getEntity();
try {
try {
Player player = new Player(new BufferedInputStream(
entity.getContent()));
player.play();
} catch (Exception e) {
System.out.println("语音播报功能出错了");
System.out.println(e.getMessage());
}
} catch (Exception e) {
e.printStackTrace();
}
if(httpclient!=null)
httpclient.close();
}
使用的JAR包为jl1.0.1.jar