Android Question When a value changes speaks

Isac

Active Member
Licensed User
Longtime User
Hi friends B4A,

The Label4 automatically acquires a value and when
this value changes I would make him talk, but currently is not talking.
Maybe I have to memorize it and then compare it to?

B4X:
    If Label4.Text.Length > 0 OR Label4.Text<> Label4.Text  Then
             tts1.Speak(Label4.Text,True)


thank you
 

Cableguy

Expert
Licensed User
Longtime User
Don't use a Label. Use an Edit text view and put your ts inside the text changed event.
you will need extra coding to prevent user input.
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
I assume that you are setting the label from many places in your code, as you don't want to simply call it from there.

My suggestion would be to add a sub to set the label and speak if need be:

B4X:
Sub SetTTSLabel(Text as string)
  If Label4.Text<>Text Then
    Label4.Text=Text
    If Text<>"" Then
      tts1.Speak(Text,True)
    End If
  End If
End Sub

Then, simply, use

SetTTSLabel(Text)

instead of

Label4.Text=Text

everywhere you change the value of Label4 (except, of course, in SetTTSLabel).
 
Upvote 0
Top