TTS with bluetooth headset

brelto85

Active Member
Licensed User
Longtime User
I'm trying to run TTS but not speaks into bluetooth headset
I try this to determine if the headset bluetooth is connected

B4X:
Sub IsBluetoothHeadsetOn As Boolean
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    Return r.RunMethod("isBluetoothScoOn")
End Sub

but return always false also if the headset is connected
i tried also to run this code

B4X:
Sub SetBluetooth(Value As Boolean)
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    Dim mode As Int
    If Value Then mode = 2 Else mode = 0
     r.RunMethod2("setBluetoothScoOn" , True , "java.lang.boolean") 
End Sub

but speaking into bluetooth headset, the voice recognition do not works.
the curious thing is that the microphone of the mobile phone is actually off

I also added "android.permission.MODIFY_AUDIO_SETTINGS" permission in the manifest
 

brelto85

Active Member
Licensed User
Longtime User
I want to share my experiments because can serve other
I think your solution is incomplete

with these methods, TTS works perfectly over bluetooth headset

B4X:
Sub StartBluetoothSco()   
   Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    r.RunMethod("startBluetoothSco")

    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    r.RunMethod2("setMode", 2, "java.lang.int")
End Sub

B4X:
Sub StopBluetoothSco()   
   Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    r.RunMethod("stopBluetoothSco")

    r.Target = r.GetContext
    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
    r.RunMethod2("setMode", 0, "java.lang.int")
End Sub

thanks
alberto
 
Upvote 0

SoyEli

Active Member
Licensed User
Longtime User
is this together or a choice, do you have to repeat everything but the last line?

Thank you:
======================
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod("startBluetoothSco")

r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
r.RunMethod2("setMode", 2, "java.lang.int")
 
Upvote 0
Top