【问题标题】:Android: Coordinate SounPool and TTSAndroid:协调SounPool和TTS
【发布时间】:2013-04-23 07:11:33
【问题描述】:

我在我的 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();
        }
    });

speakOut() 在哪里:

private void speakOut() {

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

但这会重现我的 mp3 文件和我的 tts 同时说话。

所以问题是:

如何在我的 mp3 之后重现 tts?

【问题讨论】:

标签: android multithreading text-to-speech


【解决方案1】:

您应该知道您的声音文件R.raw.water_boiling 的持续时间,为此持续时间设置一个倒计时并在onFinish() 中调用speakOut()

【讨论】:

    【解决方案2】:

    我是这样解决问题的:

    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);
    
    }
    

    即使这需要知道 mp3 文件的持续时间。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2013-12-16
      相关资源
      最近更新 更多