简体   繁体   中英

MediaPlayer Android programming google text to speech.

Don't get the wrong sound when playing, when I enter text in English then I'll get everything and the result gives sootvetstvuyushaya word,

but when I change the url to: http://translate.google.com/translate_tts?tl=ru&q =привет and open computer browser then I'm fine but when I enter the url in the source code that gives me no intelligible speech, give that to me to do

This is my code:

public void onClick(View v) {

MediaPlayer player = new MediaPlayer();

try {           
    player.setAudioStreamType(AudioManager.STREAM_MUSIC);

    player.setDataSource("http://translate.google.com/translate_tts?tl=ru&q=привет");
    player.prepare();
    player.start();

} catch (Exception e) 
{
    Toast.makeText(this, "speaking error!!", Toast.LENGTH_LONG).show(); 
}

}

Thread x;
MediaPlayer  mediaPlayer;
 x=new Thread(){    
public void run(){
         try{
             url1="http://www.translate.google.com/translate_tts?ie=UTF-8&q="this is word which is speech"%0A&tl="this is language"&prev=input";


            mediaPlayer=new MediaPlayer();
            mediaPlayer.reset();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
            mediaPlayer.setDataSource(url1);
            mediaPlayer.prepare(); // might take long! (for buffering, etc)
            mediaPlayer.start();
                    } catch (IllegalArgumentException e) {
                        mediaPlayer.reset();
                    } catch (IllegalStateException e) {
                        mediaPlayer.reset();
                    } catch (IOException e) {
                        mediaPlayer.reset();
                    } 


            finally{ 
            //  x.suspend();
            } 
     }

    };

then you can call like this :

x.start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM