参考Using Arabic characters with google TTS API,我尝试了以下内容:
public void button_star_click(View view)
{
player = new MediaPlayer();
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
String Abc = "http://translate.google.com/translate_tts?tl=zh-cn&q=你好嗎";
try
{
player.setDataSource(Abc);
}
catch (IllegalArgumentException e) {Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();}
catch (SecurityException e) {Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();}
catch (IllegalStateException e) {Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();}
catch (IOException e) {e.printStackTrace();}
try
{
player.prepare();
}
catch (IllegalStateException e) {Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();}
catch (IOException e) {Toast.makeText(getApplicationContext(), "You might not set the URI correctly!", Toast.LENGTH_LONG).show();}
player.start();
}
10-20 00:59:27.190: D/GestureDetector(11559): [Surface Touch Event] mSweepDown False, mLRSDCnt : -1 mTouchCnt : 2 mFalseSizeCnt:0
10-20 00:59:27.190: D/MediaPlayer Datasource XXXX(11559): The datasource is: http://translate.google.com/translate_tts?tl=zh-cn&q=你好嗎
10-20 00:59:27.190: V/MediaPlayer-JNI(11559): native_setup
10-20 00:59:27.190: V/MediaPlayer(11559): constructor
10-20 00:59:27.195: V/MediaPlayer(11559): setListener
10-20 00:59:27.195: V/MediaPlayer-JNI(11559): setAudioStreamType: 3
10-20 00:59:27.195: V/MediaPlayer(11559): MediaPlayer::setAudioStreamType
10-20 00:59:27.200: V/MediaPlayer(11559): setVideoSurfaceTexture
10-20 00:59:27.200: V/MediaPlayer(11559): prepare
10-20 00:59:27.275: V/MediaPlayer(11559): message received msg=100, ext1=1, ext2=-1004
10-20 00:59:27.275: E/MediaPlayer(11559): error (1, -1004)
10-20 00:59:27.275: V/MediaPlayer(11559): signal application thread
10-20 00:59:27.275: V/MediaPlayer(11559): prepare complete - status=1
10-20 00:59:27.280: V/MediaPlayer-JNI(11559): start
10-20 00:59:27.280: V/MediaPlayer(11559): start
10-20 00:59:27.280: E/MediaPlayer(11559): start called in state 0
10-20 00:59:27.280: V/MediaPlayer(11559): message received msg=100, ext1=-38, ext2=0
10-20 00:59:27.280: E/MediaPlayer(11559): error (-38, 0)
10-20 00:59:27.280: V/MediaPlayer(11559): callback application
10-20 00:59:27.280: V/MediaPlayer(11559): back from callback
10-20 00:59:27.290: E/MediaPlayer(11559): Error (-38,0)
单击按钮后,不会输出任何声音。
我已经尝试了http://translate.google.com/translate_tts?tl=zh-hk&q=你好嗎,它也正常工作。
我尝试过实施TTS但似乎TTS只支持英语,德语,法语和其他2种语言,共有5种语言,只有粤语或中文。
有没有人可以告知上述代码有什么问题? 非常感谢!
答案 0 :(得分:0)
您可以先尝试下载媒体,然后再播放。