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
LogCat connected to: B4A-Bridge: Acer V370-355338055629443
--------- beginning of /dev/log/main
create interp thread : stack size=32KB
create new thread
new thread created
update thread list
threadid=17: interp stack at 0x5d786000
threadid=17: created from interp
start new thread
threadid=17: notify debugger
threadid=17 (Thread-9052): calling run()
java.lang.RuntimeException: Error speaking text.
** Activity (main) Resume **
Setting install_non_market_apps has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
invalidate [global]: current 249 != cached 248
from db cache, name = install_non_market_apps , value = 1
Failed to destroy process 25405
libcore.io.ErrnoException: kill failed: ESRCH (No such process)
at libcore.io.Posix.kill(Native Method)
at libcore.io.ForwardingOs.kill(ForwardingOs.java:81)
at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:260)
at anywheresoftware.b4a.phone.Phone$LogCat.LogCatStop(Phone.java:759)
at anywheresoftware.b4a.b4abridge.service1._stoplogcat(service1.java:612)
at anywheresoftware.b4a.b4abridge.service1._streams_newdata(service1.java:673)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$3.run(BA.java:307)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
Failed to destroy process 25405
libcore.io.ErrnoException: kill failed: ESRCH (No such process)
at libcore.io.Posix.kill(Native Method)
at libcore.io.ForwardingOs.kill(ForwardingOs.java:81)
at java.lang.ProcessManager$ProcessImpl.destroy(ProcessManager.java:260)
at anywheresoftware.b4a.phone.Phone$LogCat.LogCatStop(Phone.java:759)
at anywheresoftware.b4a.phone.Phone$LogCat.LogCatStart(Phone.java:704)
at anywheresoftware.b4a.b4abridge.service1._startlogcat(service1.java:605)
at anywheresoftware.b4a.b4abridge.service1._streams_newdata(service1.java:669)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA$3.run(BA.java:307)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
threadid=17: exiting
threadid=17: bye!
create interp thread : stack size=32KB
create new thread
new thread created
update thread list
threadid=17: interp stack at 0x5d7e0000
threadid=17: created from interp
start new thread
threadid=17: notify debugger
threadid=17 (Thread-9053): calling run()

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: 281

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
Top