0

I'm new to android development and I followed some tutorials to get text to speech working on an emulator with a higher API but my phone is a galaxy s3 running android 4.3 (api 18) which is too low.

So now I'm stumped,

1) is there any tutorial out there that explains how to get tts working on api 18? 2) how do I make my app behave differently depending on the android version it's dealing with?

1 Answers1

0

You need to have the internet permission set. Use this code on a button click to test it out or something. You can also change the query behind the '?' to fit your needs, for example if you need to TTS from the English language change 'tl=zh-TW' to 'tl=en'. You also need to fill in the 'q=' with some value like 'q=hello'. Right now the api is being blocked by a captcha, to get around it use this Google Translate TTS API blocked.

    String url = "http://translate.google.com/translate_tts?ie=utf-8&tl=zh-TW&q=";
    mPlayer = new MediaPlayer();
    mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);

    try{

        mPlayer.setDataSource(url);
        mPlayer.prepareAsync();
        Log.i("url", url + MainActivity2.cursor.getString(0));

    }catch(Exception e){
        Log.e("mediaPlayer", e.toString());
    }
Community
  • 1
  • 1
ginsengtang
  • 751
  • 1
  • 7
  • 17