Android Question why is the TextToSpeechFinish Phone event raised twice?

RichyK68

Active Member
Licensed User
Longtime User
Hi,

I've noticed that when using TTS, the TextToSpeechFinish event is being raised twice? Why is that?
At first I thought it was my project, but I set up a very simple project, with one activity, one button, one TTS object, which speaks one word when the button is pressed. And the TextToSpeechFinish event gets called twice for some reason, which is annoying because I need to synchronize the speech with different actions/events.

Is this a feature and do I need to deal with this? Or will it be called twice on one version of Android or one particular device, and once only on others, or even more? I just need to know :) Reading the documentation, it sounds like it is only meant to be raised the once.

Any ideas?

Richard
 

RichyK68

Active Member
Licensed User
Longtime User
Sure thing, thanks.

I thought it was because this code

Dim p As PhoneEvents
Dim PID As PhoneId
p.InitializeWithPhoneState("test",PID)
TTS.Initialize("TTS2")

was in the Activity_Resume, but I've also tried it in the Activity_Create too and it does the same thing.
If you run the project in debug (rapid) mode, press the button to make it speak the once, then put a breakpoint on the counter = counter + 1 line in the test_TextToSpeechFinish event, and press the button again to make it speak, you'll see the counter is now 2, when it should really be one?

Cheers,

Richard
 

Attachments

  • TTS test.zip
    7 KB · Views: 226
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You are adding a listener each time the activity is resumed.

Your code should be:
B4X:
Sub Activity_Create (FirstTime As Boolean)
 If FirstTime Then
   Dim p As PhoneEvents
   Dim PID As PhoneId
   p.InitializeWithPhoneState("test",PID) 'not really required. Use Initialize instead and do not dim PID.
   TTS.Initialize("TTS2")
End If
...
End Sub
 
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
Thanks. I've also tried that (but also copied and pasted your code too just to be sure and removed the ...). It still calls the event twice?
 
Upvote 0

RichyK68

Active Member
Licensed User
Longtime User
I've found it is only called once when using Google TTS, when using Samsung TTS (default on the S4) it raises the event twice.
However, the event is still useless for knowing when speech has finished (to call up VR) as the event is raised well before the speech has ended.
 
Upvote 0
Top