Event "When TextToSpeech.AfterSpeaking" can not trigger procedure

101 views
Skip to first unread message

Arnaud

unread,
Aug 17, 2016, 10:33:44 AM8/17/16
to MIT App Inventor Forum
Hello, 

I am building an app and everything was going right until I needed the "When TextToSpeech.AfterSpeaking" event (part of TextToSpeech associated functions). I've understood that it's supposed to trigger some actions when the text has been totally spoken. It's quite more practical than timer, especially when we don't know in advance the time it will take to speech the text.

The issue is that AI2 does not want to execute DO instructions placed inside the event.
I've tried 2 ways :
1) Using a global variable (flag) set by the AfterSpeaking event
2) Using the result provided by AfterSpeaking event

Then to prevent the program to go further on next line, I've put a while do loop test these flag.

Maybe I'm totally wrong on the way to handle that : please help.

I also have the same kind of issue with the "AfterGettingText" in SpeechRecognizer.

Thanks in advance for your help.

Best regards,
Arnaud


 
issueai2.png.jpg

Ghica

unread,
Aug 17, 2016, 10:50:12 AM8/17/16
to MIT App Inventor Forum
You are trying to use a kind of delay in App Inventor and this cannot work, because of the event based approach that App Inventor takes.
What you have to do, is keeping the index to your list in a global and have a procedure that speaks one item, where the index used is an input parameter to your procedure. Somewhere you kick off the first one and then in the after speaking event, you increase the index in the global, test if it is not larger than the length of the list and if not, call the procedure with the next index number.
Cheers, Ghica

Arnaud

unread,
Aug 17, 2016, 12:31:49 PM8/17/16
to MIT App Inventor Forum
Thank you very much Ghica, you helped me a lot !!! I was totally running in the wrong way.

Please find attached my new code which is quite lighter, cleaner and more important : that works !! Whatever the length of text to speech everything happens one after the one with no timer use.

Now my next step is, once the text to speech of each alert is done, I want to trigger a SpeechRecognizer and try to catch words from the user. I will try the same way and will let you know if it works.

Have a nice day !

Arnaud

ai2issuesolved.jpg

Arnaud

unread,
Aug 17, 2016, 1:30:03 PM8/17/16
to MIT App Inventor Forum
Yes, it also works with the SpeechRecognizer !!
So one very precious advice got from Ghica : Simply do isolated (not linked with other actions) calls to such functions. Then, all the operations sequencing is done under the "After_event" event.

Hope this may help.

Arnaud
Reply all
Reply to author
Forward
0 new messages