Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot make it to work with tts #55

Open
diegopefm opened this issue Jun 24, 2023 · 0 comments
Open

Cannot make it to work with tts #55

diegopefm opened this issue Jun 24, 2023 · 0 comments

Comments

@diegopefm
Copy link

diegopefm commented Jun 24, 2023

Is it possible to use the visualizer with Android text-to-speech?

My app uses Android text-to-speech to read paragraphs, and I'd like to add an audio visualizer so to have an animation according to the speech.

I find this audio visualizer very interesting, but I don't know how to use it with tts.

In the page examples it says you have to instantiate Media player, and shows this example:

mediaPlayer = MediaPlayer.create(this, R.raw.you_music);

But the fact is I'm not using MediaPlayer, but TTS for the audio. The library requires an audiosessionid to be passed to the player this way:

lineVisualizer.setPlayer(mediaPlayer.getAudioSessionId());

But I'm not finding any way to get the audiosessionid from tts, and inspected all the properties of the TextToSpeech instance, but no getAudioSessionId() or similar is present.

private lateinit var ttobj: TextToSpeech
    
    ttobj = TextToSpeech(this, this)
    ttobj.setLanguage(Locale.US)
    
    ttobj.setOnUtteranceProgressListener(object : UtteranceProgressListener() {
        override fun onStart(utteranceId: String) {
            //Here I would call setPlayer and pass an audiosessonid to start the visualizer.
        }
    
        override fun onDone(utteranceId: String) {
            runOnUiThread {
                ttsSpeechFinished()
            }
        }
    
        override fun onError(utteranceId: String) {
            Log.i("TextToSpeech", "On Error")
        }
    })
    
    fun doSpeech(){
        if (ttsStatus == TextToSpeech.SUCCESS){
            ttobj.speak("I'm going to read a paragraph for testing, right?", TextToSpeech.QUEUE_FLUSH, null,"")
        }
    }

The speech is working great, but I don't know how to "attach" the audio visualizer to the current tts audio sinthesys.

I've tried using AudioManager, that has a generateAudioSessionId() method:

var mAudioManager = activity?.getSystemService(AUDIO_SERVICE) as AudioManager
    val audioSessionId = mAudioManager.generateAudioSessionId()

But this audioSessionId is not working, and I'm obviously not sure I'm in the right direction.

Any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant