Tts

splatt

Active Member
Licensed User
Is there a way to detect that the Speech has finished?

I want to disable a button untill a line of text has been spoken.
 

Erel

Administrator
Staff member
Licensed User
If you are playing the same string each time then you can measure it and then use a timer.
There is no "complete" event.
 

Erel

Administrator
Staff member
Licensed User
There is no Complete event in the underlying API. There is a method that you can poll named isSpeaking.
It should be easy to call it with the Reflection library. If you need I can help you.
 

Rusty

Well-Known Member
Licensed User
Hi Erel,
It's been a while since I posted to this thread.
You offered to help with the ispeaking example.
Can you do so now?
I need to know when a TTS is finished speaking (or know when it is speaking).
thanks in advance.
 

Erel

Administrator
Staff member
Licensed User
You can use PhoneEvents from the Phone library and listen to the TextToSpeechFinish event.
 

RichyK68

Active Member
Licensed User
Wow, this is an old thread!
Sadly, the TextToSpeechFinish event is unreliable on the Samsung Galaxy S4 (it is raised twice) and it is raised immediately upon starting speaking the text on my Nexus 7 (which is stock Android, I believe). I'm still struggling to find a suitable solution for all devices. How would I go about using the IsSpeaking property with reflection? I'm hoping that might be the answer. Else it's pretty pointless combining TTS with VR on an Android device, using the built-in functionality.

Thanks,

Richard
 

Erel

Administrator
Staff member
Licensed User
B4X:
Dim jTTS As JavaObject = TTS
Log(jTTS.RunMethod("isSpeaking", null)
 

RichyK68

Active Member
Licensed User
You're a legend, Erel! It actually appears to be working on both of my devices, I'll roll this new version out to others and see what the verdict is.

Thank you very much!!
 
U

unba1300

Guest
I just tried the code above and get the error:
java.lang.RuntimeException: Method: isSpeaking not found in: java.lang.String
And I am using the Reflection library.
 

Erel

Administrator
Staff member
Licensed User
Your code is wrong. You should use JavaObject with the code I posted above.
 
U

unba1300

Guest
Sorry Erel, I am using both libraries Reflection and JavaObject, but still getting the same error. I've tried
Dim jTTS As JavaObject = TTS in both Process_Globals and Globals and
Log(jTTS.RunMethod("isSpeaking", null) in a part of my code after TTS1.Speak(lblStory.Text, True), which does speak the text. Could there be a conflict while using both libraries? I started using JavaObject to pad edittexts, and I'm using Reflection for various other things.
 

Erel

Administrator
Staff member
Licensed User
Could there be a conflict while using both libraries?
No.

You can run:
B4X:
Dim jTTS As JavaObject = TTS1 'not TTS
Anywhere you like, after TTS1 was initialized.
 

Douglas Farias

Expert
Licensed User
and how to make disable button spk when isSpeaking?
can post a simple code?

for exemple
button spk click
button spk.enable = false
TTS1.ready

if click again when isSpeaking show a mensage
"lalalalalalalala"

later finish speak button spk.enable = true ?????


sory my english.
i m not programmer xD
 

Erel

Administrator
Staff member
Licensed User
B4X:
Sub Button_Click
 If jTTS.RunMethod("IsSpeaking", null) = True Then
   ToastMessageShow(...)
 Else
  TTS.Speak(...)
 End If
End Sub
 

Douglas Farias

Expert
Licensed User
why this error :( ????

i m using this libs
-core
-java object

-dialogs
-clipboard
-TTS
-Admob
-Reflection
-Phone


java.lang.RuntimeException: Method: IsSpeaking not found in: android.speech.tts.TextToSpeech

my code

B4X:
Sub btnSpeak_Click
    Dim jTTS As JavaObject = TTS1
    If jTTS.RunMethod("IsSpeaking", Null) = True Then  'this line is the error *-*
    ToastMessageShow("Leitor em uso, aguarde!", True)
    Else If  EditText1.Text = "" Then
    ToastMessageShow("O campo texto está vazio",True)
    Else
    EditText1.SelectAll
    TTS1.Speak(EditText1.Text, True) 
    End If
End Sub
 
Top