求帮忙关于Google语音合成 API
我用Java调用了Google的语音合成API并接收mp3文件,在接收英文时没有问题,但在接收中文时出现问题,请各位帮我看一下,万分感谢!
public static void getFromHttpGet_ZH(){
String myMsg="早上好中午好晚上好";
String url="http://translate.google.com/translate_tts?tl=zh_cn&q="+myMsg;
System.out.println(url);
HttpClient httpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
try {
HttpResponse httpResponse=httpClient.execute(httpGet);
System.out.println(httpResponse.getStatusLine());
if(httpResponse.getStatusLine().getStatusCode()==200){
InputStream inputStream=httpResponse.getEntity().getContent();
File file=new File("result/tts/TTS_ZH.mp3");
FileOutputStream fileOutputStream=new FileOutputStream(file);
byte[] buffer=new byte[1024];
int count=0;
while((count=inputStream.read(buffer))!=-1)
fileOutputStream.write(buffer, 0, count);
fileOutputStream.close();
inputStream.close();
}
httpClient.getConnectionManager().shutdown();
} catch (Client
ProtocolException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (
IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
如果是英文的,是不会有问题的
String myMsg="I-Love-Google";
String url="http://translate.google.com/translate_tts?tl=en&q="+myMsg;
中文敲到地址栏,也可以听到正确结果,但是一到本地就不行了!!!!
真的很困惑!!!
------解决方案-------------------- 没有设置浏览器类型
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17");