TTS Volume control

joseanquiles

Member
Licensed User
Longtime User
I have tried TTS and it's works fine. Very easy and very powerful.
However, it doesn't seem possible to adjust the volume in a physical device. Volume phone buttons doesn't work......
How can I achieve volume buttons to respond?
 
Upvote 0

JohnK

Active Member
Licensed User
Longtime User
You can use Phone.SetVolume and set the VOLUME_MUSIC channel. It will change the TTS volume.
I will assume by this that there is no way to have TTS at a different volume to the music channel volume?
 
Upvote 0

Sgardy

Member
Licensed User
Longtime User
I have tried TTS and it's works fine. Very easy and very powerful.
However, it doesn't seem possible to adjust the volume in a physical device. Volume phone buttons doesn't work......
How can I achieve volume buttons to respond?

It seems that the volume act while TTS is speaking, also the phone setvolume method have to be placed after the Speak function.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
This is an old thread. You should have started a new thread for these questions / suggestions.

It is now possible to change the TTS volume with:
B4X:
Sub Process_Globals
   Private tts As TTS
End Sub

Sub Globals
 

End Sub

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

Sub tts_Ready (Success As Boolean)
   Log($"ready: ${Success}"$)
End Sub

Sub activity_click
   SpeakWithVolume(tts, "strong", False, 1)
   SpeakWithVolume(tts, "soft", False, 0.2)
End Sub

'volume should be between 0 to 1.
Private Sub SpeakWithVolume(TTSObject As TTS, Text As String, ClearQueue As Boolean, Volume As Float)
   Dim m As JavaObject
   Dim f As String = Volume
   m.InitializeNewInstance("java.util.HashMap", Array(CreateMap("volume": f)))
   Dim jo As JavaObject = TTSObject
   Dim queue As Int
   If ClearQueue Then queue = 0 Else queue = 1
   jo.RunMethod("speak", Array(Text, queue, m))
End Sub
This will work on Android 4+.

Note that there are other keys that can be modified: http://developer.android.com/refere...ch.Engine.html#KEY_FEATURE_EMBEDDED_SYNTHESIS
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Maybe I am wrong, but I currently have the impression that Forum members are more inclined to reply to already running threads than to new threads
Not me. I tend not to answer questions in existing threads as such discussions are "unsearchable".

You cannot change the audio balance.
 
Upvote 0
Top