TTS

This is a helper class to handle text-to-speech functionality.

Virtual Methods

Note

These methods should be implemented in other scripts to control TTS output. When a node gets focused, the TTS system will traverse the nodes and it’s parents recursively in search of one of these methods, and if existing, use it’s text output instead.

Type

Name

String

tts_text

String

tts_tree_item_text

String

tts_range_value_text

String

tts_popup_menu_item_text


String tts_text (focused: Control)

Generic TTS text method. This is called when a node gets focused. The focused parameter is the node that got focused, and is a child of either the node where this script is, or of one of this children.

This method should return the text to be spoken, which overrides the default implementation. If it returns an empty string, the TTS system will continue traversing the parent methods, and use the default implementation if no further node overrides it.

func tts_text(focused):
        if focused is $MyLabel:
                # Override output in this particular case
                return "Hey, my label got focused!"
        # We're not interested in this node, so return an empty string
        return ""

String tts_tree_item_text (item: TreeItem, tree: Tree)

Specific TTS text for a focused cell on a Tree node.

This method should return the text to be spoken, which overrides the default implementation. If it returns an empty string, the TTS system will continue traversing the parent methods, and use the default implementation if no further node overrides it.


String tts_range_value_text (value: float, range: Range)

Specific TTS text for a focused Range node. It supplies the current node’s value to customize how it is presented to the user.

This method should return the text to be spoken, which will be appended to the default implementation. If it returns an empty string, the TTS system will continue traversing the parent methods, and use the default implementation if no further node overrides it.

Warning

Always use the supplied value, not the range’s value. The TTS system might use different values, such as minimum/maximum ranges.

func tts_range_value_text(value, range):
        if range is $FilesizeRange:
                # This range works with file sizes, so add a suffix
                return "%d megabytes" % value
        # We're not interested in this node, so return an empty string
        return ""

String tts_popup_menu_item_text (idx: int, menu: PopupMenu)

Specific TTS text for a focused PopupMenu node. It supplies the currently selected menu item.

This method should return the text to be spoken, which will be appended to the default implementation. If it returns an empty string, the TTS system will continue traversing the parent methods, and use the default implementation if no further node overrides it.

Methods

Type

Name

void

speak

void

stop

bool

is_speaking

String

singular_or_plural


void speak (text: String, interrupt: bool = true)

Speaks the given text. If interrupt is true, the current speech is interrupted, ttherwise, the new text is queued.

TTS.speak("Hello")
TTS.speak("World!", false)
# Will speak "Hello World!"

void stop ()

Stops any current speech immediately.


bool is_speaking ()

Returns whether the TTS system is currently speaking any sentence.


String singular_or_plural (count: int, singular: String, plural: String)

Returns the singular or plural form of a word depending on the given count. Useful if using variables and the final text needs to change due to pluralization.

var count = 5
TTS.speak("You have %d %s" % [
        count,
        TTS.singular_or_plural(count, "apple", "apples")
])