Speech Synthesis --interactive option


“man say” in the terminal has the option of --interactive. I tired it out in the terminal and pretty cool.
" Print the text line by line during synthesis, highlighting words as they are spoken"

In my app I open text file and display the text and have an option to speak the text by passing the text or the selected text to s.Execute("say " + sometext) How can I have my app highlight the text in the textarea as its being spoken like with the --interactive option?

This one puzzles me a bit.


Break the source text into words (e.g. split on spaces), then pass each piece to say at the same time you highlight it in the textarea.

Use an interactive shell,
in the dataAvaliable event you will have your string with some control codes
find the position of the start hi light IE [7m and the position of the ending one IE (B
considering the offset: the string has a [M extra and if you have more lines you will have to shift for the current line of text since say replies are relative to the current line (endofline)
Hilight as you wish the text in your textArea

1 Like

Well, for that we have willSpeakWord event in NSSpeechSynthesizerMBS class in MBS Xojo Plugins.

And the sample project NSSpeechSynthesizer Progress does show the word highlighting.

I see. Testing out some ideas. Cool thanks! :sunglasses:

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.