MediaPlayer streaming mp3, get jibberish
I was thinking of a shortcut to get Chinese TTS working. I'm using
MediaPlayer to stream Google Translate Text-to-Speech generated mp3's.
When I use to englishToSpeech method, the audio plays back perfectly.
However, when I use my hanziToSpeech(Chinese) method, the audio plays back
with jibberish Chinese. I suspect the jibberish occurs due to the time it
takes Google Translate to generate an mp3.
For example,
http://translate.google.com/translate_tts?tl=zh-cn&q=%E4%B8%89%E5%8F%B7%E6%80%8E%E4%B9%88%E6%90%9E%E7%9A%84
Google generates a mp3 in Chinese. It takes a little bit. I suspect that
the MediaPlayer is buffering the audio before its actually done being
generated. It works perfectly fine with English, probably because
generating English mp3s is quick.
It also got some errors which I posted.
public static void hanziToSpeech(String input)
{
String translateURL =
"http://translate.google.com/translate_tts?tl=zh-cn&q=" + input;
Sound.playURL(translateURL);
}
public static void englishToSpeech(String input)
{
String translateURL =
"http://translate.google.com/translate_tts?tl=en&q=" + input;
Sound.playURL(translateURL);
}
public static void playURL(String url)
{
MediaPlayer mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.setDataSource(url);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
mp.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
mp.start();
}
TextToSpeech.englishToSpeech(english);
TextToSpeech.hanziToSpeech(chinese);
09-13 23:50:31.049: V/ChromiumHTTPDataSource(39): connect on behalf of uid
10044 09-13 23:50:31.049: I/ChromiumHTTPDataSource(39): connect to
http://translate.google.com/translate_tts?tl=zh-cn&q=http://translate.google.com/translate_tts?tl=zh-cn&q=ÈýºÅÔõô¸ãµÄ£¬°ÑÇòÈÃÈ˼ҶӸøÇÀ×ßÁË¡£
@0 09-13 23:50:31.389: E/WVMExtractor(39): Failed to open libwvm.so 09-13
23:50:31.400: I/NuCachedSource2(39): ERROR_END_OF_STREAM 09-13
23:50:32.440: D/AudioSink(39): bufferCount (4) is too small and increased
to 12
No comments:
Post a Comment