0

I define this simple method in my Activity:

private void playSound(final boolean ttsOn) {
    // TODO Auto-generated method stub
    int water = 0;      
    SoundPool pl;
    pl = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

    water = pl.load(this, R.raw.water_boiling, 0);

    pl.setOnLoadCompleteListener(new OnLoadCompleteListener() {

        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            // TODO Auto-generated method stub
            soundPool.play(sampleId, 1f, 1f, 0, 0, 1);
            if(ttsOn)
                speakOut();
        }
    });

Where speakOut() is this:

private void speakOut() {

    tts.setLanguage(Locale.ITALIAN);
    tts.speak(n.Message, TextToSpeech.QUEUE_FLUSH, null);
} 

But this reproduce my mp3 file and my tts speak at same time.

So the question is:

How can I reproduce tts after my mp3?

GVillani82
  • 17,196
  • 30
  • 105
  • 172
  • I'v never used this but maybe is that. Can you add in the if condition status == 0 http://developer.android.com/reference/android/media/SoundPool.OnLoadCompleteListener.html – PedroAGSantos Apr 23 '13 at 07:19
  • also you might want to take a look at this http://stackoverflow.com/questions/4436055/android-soundpool-get-notified-when-end-of-played – PedroAGSantos Apr 23 '13 at 07:25

2 Answers2

1

You should know the duration of your sound file R.raw.water_boiling, set a countdown timer for this duration and call speakOut() in onFinish().

Hoan Nguyen
  • 18,033
  • 3
  • 50
  • 54
0

I solve the problem in this way:

private void playSound(final boolean ttsOn) {
    // TODO Auto-generated method stub
    int water = 0;      
    SoundPool pl;
    pl = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);

    water = pl.load(this, R.raw.system_alert_003, 0);



    pl.setOnLoadCompleteListener(new OnLoadCompleteListener() {

        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            // TODO Auto-generated method stub
            soundPool.play(sampleId, 1f, 1f, 0, 0, 1);
            if(ttsOn)
            {
                myMediaTimer = new Timer();
                myMediaTimer.schedule(new TimerTask() {         
                    @Override
                    public void run() {
                        speakOut();
                    }

                }, DURATION_MEDIA_FILE);

            }
        }
    });


    Log.i("onCrete","WATER FILE: "+water);

}

Even if this require the knowledge of duration of mp3 file.

GVillani82
  • 17,196
  • 30
  • 105
  • 172