3

I use Audio Manager to fade Text to speech voice command and Background music for a short time. I request audio focus using AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK flag.

It will fade two voice out puts but not very clear. I want to increase Text to speech volume higher and background music volume lower. After finish the speech it should be recovered.

I try setStreamVolume as well. But it control both the voices. Is there a way to increase Text to speech volume without increasing background. Any help is appreciated.

var vol = mAudioManager?.getStreamVolume(AudioManager.STREAM_MUSIC)

tts!!.setOnUtteranceProgressListener(object : UtteranceProgressListener() {

                override fun onStart(utteranceId: String?) {
                    mAudioManager?.setStreamVolume(AudioManager.STREAM_MUSIC,vol!!+3,0)
                }

                override fun onDone(utteranceId: String?) {
                    mAudioManager?.abandonAudioFocus(afChangeListener)
                    mAudioManager?.mode = AudioManager.MODE_NORMAL
                    mAudioManager?.setStreamVolume(AudioManager.STREAM_MUSIC,vol!!,0)
                }

                override fun onError(utteranceId: String?) {
                }
            })
----

AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK)
----
j.doe
  • 662
  • 4
  • 19
shanzAD
  • 55
  • 5

0 Answers0