Android Question TTS ID

Colin Evans

Active Member
Licensed User
Longtime User
Trying to implement the text to speech but I don't want the user to press a button I just want to get the app to speak dependant on what's happening in the program but whilst I can get the example's to work on my phone I keep getting error messages when I try to simply tell it to speak a specific text string.

java.lang.RuntimeException: Error speaking text.

when trying to action this

B4X:
    If tts.Ready Then
                    If tts.IsAvailableLanguage("en_US") Then tts.SetLanguage("en","US")
                    tts.Speak("Just a test to se if it gets read out",False)
                End If
 

Colin Evans

Active Member
Licensed User
Longtime User
Hi, I've tried it and OK = True but I still get the same error, I'm obviously missing something but can't find it :)

java.lang.RuntimeException: Error speaking text.

B4X:
Dim OK As Object
 OK = tts.SetLanguage("en","US")
Log(OK)
If OK = True Then tts.Speak("Here is a simple text app, i can talk any text",False)
[/code}
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Please post the full log error events from the right side of the IDE
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
So I've tried what I want in the TTS ID example and I still get the error

this is the code, hope it makes sense!

B4X:
Sub Activity_Create(FirstTime As Boolean)
    tts.Initialize(Me,"TTS")
    Activity.LoadLayout("1")
    Dim OK As Object
    OK = tts.SetLanguage("en","US")
    Log(OK)
    If OK = True Then tts.Speak("Here is a simple text app, i can talk any text",False)
End Sub

and the error

** Activity (main) Create, isFirst = true **
true
main_activity_create (java line: 369)
java.lang.RuntimeException: Error speaking text.
at anywheresoftware.b4a.obejcts.TTS.Speak(TTS.java:62)
at b4a.example.ttsid._vv7(ttsid.java:287)
at tts.example.id.main._activity_create(main.java:369)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
at tts.example.id.main.afterFirstLayout(main.java:105)
at tts.example.id.main.access$000(main.java:17)
at tts.example.id.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7397)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935)
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Try moving the tts.speak command to another sub.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi I think its a delay problem, because I'm trying to speak before the app is fully functional, seems to be something with TTs-ID or TTS because my app is loading very slowly and then I get the error as it tries to speak on loading

I've attached a sample and you'll probably see the delay, obviously when I click button2 the program is loaded so it works but trying adding it tio the create sub and the program hasn't fully loaded, hope I'm making sense
 

Attachments

  • TTS-ID Test.zip
    181.6 KB · Views: 251
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Something seems weird with your use of the OK object.

Try Erel's example AS-IS to see if it works:

 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Hi I think its a delay problem, because I'm trying to speak before the app is fully functional, seems to be something with TTs-ID or TTS because my app is loading very slowly and then I get the error as it tries to speak on loading

I've attached a sample and you'll probably see the delay, obviously when I click button2 the program is loaded so it works but trying adding it tio the create sub and the program hasn't fully loaded, hope I'm making sense
Yeah, Erel's example waits for the TTS ready event.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Sorted but don't think I can use it at start up as there is around 6 to 10 seconds delay in actioning TTS Done event but thanks for your help
 
Last edited:
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Follow what Erel did in his example.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Hi John I did and the delay is still prominent, slows the first screen being displayed and the the initial speak command can appear many seconds later
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
But it is no longer giving you an error right?

That initial delay may always happen because it might take time to initially load in the vocabulary the very first time it speaks. But what if you try to speak " " (a space) at the start of your app to force this delay to happen before you really need to speak something. Then when you try to speak for the second time, it might start speaking much quicker because the vocabulary was already loaded when it said the space.
 
Upvote 0

Colin Evans

Active Member
Licensed User
Longtime User
Yes there aren't any errors and when it eventually loads it works brilliantly, I will try and refocus and see what I can do, again many thanks for all your help and guidance, appreciated, cheers
 
Upvote 0
Top