Android Question TTS : error speaking text

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello,

I am trying the TTS Library but get some error : in fact, when TTS is initialized, my example app crash with error

java.lang.RuntimeException: Error speaking text.

The unfiltered logs is below

My code is really simple and the project attached

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim TTS1 As TTS
    Dim tTemp As String
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Dim Button1 As Button
    Dim Button2 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume
    TTS1init
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    TTS1.Release
End Sub


Sub say(sentence As String)
    sentence=sentence & " was pressed"
    LogColor(sentence,Colors.Magenta)

    If Not(TTS1.IsInitialized) Then
        tTemp=sentence
        TTS1init
    Else
        TTS1.Speak(sentence,True)
    End If

End Sub


Sub TTS1init
    If Not(TTS1.IsInitialized) Then
        LogColor("TTS1init",Colors.green)
        TTS1.Initialize("TTS1")
    End If
End Sub


Sub TTS1_Ready (Success As Boolean)
    LogColor("TTS1_Ready: "&Success,Colors.Green)
    If Success Then
        TTS1.Speak(tTemp,True)
    Else
        say(tTemp)
    End If       
End Sub
Sub Button2_Click
    LogColor("button2",Colors.Red)
    say("button 2")
End Sub
Sub Button1_Click
    LogColor("button1",Colors.blue)
    say("button 1")
End Sub

Please could you point me to a way to fix this crash ? Many thanks
 

Attachments

  • TTS_test.zip
    8 KB · Views: 199

NJDude

Expert
Licensed User
Longtime User
You have to give a little bit of time to the TTS to initialize, I would suggest you set those buttons as Enabled = False and then change them to Enabled = True when the initialization is Successful in the TTS1_Ready event.
 
Upvote 0

lemonisdead

Well-Known Member
Licensed User
Longtime User
Hello NJDude,

I do thank you for your quick and detailed reply. I really appreciate. But I must admit my misunderstanding : I have thought that the TTS1_Ready event will be raised only when the TTS engine will be ready.

This because I was creating an app for myself reading the state of another appliance. Sometime only one event has to be said and the TTS speaks and other times when there is a delay between the events, the TTS crashes because it is initialized but not ready... As I did understood...
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…