Android Question how do I change audiostream channel of TTS?

RichyK68

Active Member
Licensed User
Longtime User
Hi,

I need to get TTS running playing on the notifications audio stream instead of the music audio stream. I know Android can do that (http://android-developers.blogspot.com.au/2009/09/introduction-to-text-to-speech-in.html) but can it be done with B4A and reflection?

B4X:
HashMap<String,String> myHashAlarm =newHashMap();
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
        String.valueOf(AudioManager.STREAM_ALARM));
mTts.speak(myText1,TextToSpeech.QUEUE_FLUSH, myHashAlarm);
mTts.speak(myText2,TextToSpeech.QUEUE_ADD, myHashAlarm);

Thanks,

Richard
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Process_Globals
   Dim ts As TTS
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     ts.Initialize("ts")
   End If
End Sub

Sub ts_Ready (Success As Boolean)
   If Success Then
     Dim p As Phone
     Dim jo As JavaObject
     jo.InitializeNewInstance("java.util.HashMap", Null)
     jo.RunMethod("put", Array("streamType", "" & p.VOLUME_ALARM))
     Dim jts As JavaObject = ts
     jts.RunMethod("speak", Array("ABCD", 0, jo)) '0 = QUEUE_FLUSH, 1 = QUEUE_ADD
   End If
End Sub
 
Upvote 0
Top