TTS Volume control

joseanquiles

Member
Licensed 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

Rick Harris

Well-Known Member
Licensed User
Changing the volume as described above acts on all sound sources, not just the TTS.
It would be nice if a specific volume setting could be added to the TTS control itself.
Can you please make that Erel?
 
Upvote 0

Sgardy

Member
Licensed 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

Rick Harris

Well-Known Member
Licensed User
Two suggestions:

1. If the TTS audio channel cannot be changed, then is it alternatively possible to change the music channel to a different channel than TTS works on?
2. It is possible to record TTS to a WAV file and then use a separete mediaplayer to play back the WAV file at a differen audio level. The ICOS-TTS library does this, but it should also be possible by using the "Speech API Extention": See: https://github.com/myflashlab/speech-ANE
Can someone maybe adapt this to B4A?
 
Upvote 0

Erel

Administrator
Staff member
Licensed 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

Rick Harris

Well-Known Member
Licensed User
Wow! This is great news. Sorry that I did not start a new thread. 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. I say this because most of my new questions in the past year have remained unanswered (apart from some by you).
Personally, I also tend to browse the Forum by giving priority to threads that already contain a substantial amount of discussion.
 
Last edited:
Upvote 0

Rick Harris

Well-Known Member
Licensed 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
I don't suppose it is possible to change the audio balance, i.e. set the volume separately for the left and right channel? I am probably asking for too much...
 
Upvote 0

Rick Harris

Well-Known Member
Licensed User
Not me. I tend not to answer questions in existing threads as such discussions are "unsearchable".

You cannot change the audio balance.
I did not realize that follow-on discussions are unsearchable. I now understand why often I do find relevant answers to questions by luck or chance which were not found by normally searching the Forum. To my opinion that is a draw-back for the Forum because so much can be found and learned in these long(er) threads! Some threads span more than 10 pages!
Often it takes time and some debate in a thread before someone really comes up with the right or best answer or recommendation and/or source code samples start to appear... Sorry to be a nuisance, and you probably don't agree, but I recommend to enhance the Forum by also showing search results linked to prolonged thread discussions.
It would be nice to hear what other Forum users think about this as well.
 
Upvote 0
Top