Android Question TTS in a code module. Is it possible?


Active Member
Licensed User
Longtime User
I'm trying to add some TextToSpeech to some notifications.
In order to maintain the whole project as clean as possible I'd like to place the TTS routines in a code module, but it seems it doesn't work.

The code of the module is as follow:

'Code module

Sub Process_Globals
    Dim TTS1 As TTS
    Dim TheMsg As String
    Dim TTsReady As Boolean
End Sub

Sub StartUp()
    Log("TTS Init")
End Sub

Sub SpeakThis(msg As String)
    TheMsg = msg
    If TTS1.IsInitialized = False Then
        If msg<>"" Then
            Log("MSG=" & TTsReady & " ->" & TheMsg)
            If TTsReady Then TTS1.Speak(TheMsg, True)
        End If
    End If
End Sub

Sub TTS1_Ready (Success As Boolean)
    If Success Then
        If TheMsg<>"" Then
            Log("MSG=" & TheMsg)           
            TTS1.Speak(TheMsg, True)
        End If
    End If
End Sub

(the code is a bit 'dirt' due my testing and trying)

The Sub TTS1_Ready is never fired...
If I copy&paste that same code in an activity, it works...


Well-Known Member
Licensed User
Longtime User

Referring to the Static Code Module Tutorial, as I understand it, you should handle the events Inside the activity/service which made the call to your code module sub. I could be wrong, but it is worth trying.

This means that you only have to create the sub to handle the event (TTS1_Ready) Inside your activity, and Inside that sub you could make another call to another part of your code's module (it should work).
Last edited:
Upvote 0