用阿拉伯字符与谷歌的TTS API [英] Using Arabic characters with google TTS API
问题描述
我使用谷歌API TTS,我想在一个阿拉伯语的查询,但继续得到错误,我已经设置了文本文件编码设置为UTF-8,这是我的code
字符串oLanguage =AR;
MediaPlayer的播放器=新的MediaPlayer();
字符串的mainText =الله
尝试{
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(http://translate.google.com/translate_tts?tl=+ oLanguage +与& Q =+的mainText);
播放器prepare()。
player.start(); }赶上(例外五){
// TODO:处理异常
}
在code正常工作,当我使用其他语言,但是当我用阿拉伯语我得到这个错误
1月4日至19日:04:10.221:E / MediaPlayer的(665):错误(1,-2147483648)
另一件事是,当我尝试直接使用阿拉伯语code到链路它显示了这样的
<$p$p><$c$c>player.setDataSource(\"http://translate.google.com/translate_tts?tl=ar&q=%D8%A7%D9%84%D9%84%D9%87\");长时间的努力来解决这个问题,我发现唯一的解决办法后,井使类似于一个浏览器的请求之前改变用户代理。
不过从我的研究改变了媒体播放器的用户代理有很复杂的,所以我决定先下载该文件,然后播放。在每种情况下,用户代理仍需要与线以下
被改变 (HttpURLConnection类对象).addRequestProperty(用户代理,Mozilla的/ 5.0);
I'm using the google TTS API and I want to make a query in Arabic but keep getting errors and I have set the text file encoding set to UTF-8, here is my code
String oLanguage = "ar";
MediaPlayer player = new MediaPlayer();
String mainText = "الله";
try {
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource("http://translate.google.com/translate_tts?tl=" + oLanguage + "&q=" + mainText);
player.prepare();
player.start();
} catch (Exception e) {
// TODO: handle exception
}
The code works fine when I use other languages but when I use Arabic I get this error
04-19 01:04:10.221: E/MediaPlayer(665): error (1, -2147483648)
Another thing is when I try using the arabic code directly into the link it shows up like this
player.setDataSource("http://translate.google.com/translate_tts?tl=ar&q=%D8%A7%D9%84%D9%84%D9%87");
Well after long hours of trying to fix this the only solution I found was to change the user agent before making the request to resemble that of a browser.
However from my research changing the user-agent of the media player with very complicated so I decided to download the file first and then play it. In each case the User Agent still needs to be changed with the line below
(HttpURLConnection Object).addRequestProperty("User-Agent", "Mozilla/5.0");
这篇关于用阿拉伯字符与谷歌的TTS API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!