Search code examples
androidtext-to-speechandroid-audiomanagerbluetooth-sco

How to Text-to-Speech plays on Bluetooth in Android?


I'm a newbie for android. I've created an app that can read Incoming messages using Android Text-To-Speech. Up to now its fine with it. Now user's want It has to play over paired Bluetooth.

I'd read all the forums but i didn't get it. Now how i play my TTS engine on Bluetooth ?

Anyone having any idea ?

Thanks in advance.


Solution

  • Use my answer at Using the Android RecognizerIntent with a bluetooth headset

    And create a speak method like below

    protected void speak(String text)
    {
    
        HashMap<String, String> myHashRender = new HashMap<String, String>();
    
        if (mBluetoothHelper.isOnHeadsetSco())
        {
            myHashRender.put(TextToSpeech.Engine.KEY_PARAM_STREAM, 
                    String.valueOf(AudioManager.STREAM_VOICE_CALL));
        }
        mTts.speak(text, TextToSpeech.QUEUE_FLUSH, myHashRender);
    }