Text-input engine back-end

The text-input engine is a convenient, always available implementation designed to be used via the engine.mimic() method.

To initialize the text-input engine, do the following:

get_engine("text")

Note that dragonfly.engines.get_engine() called without "text" will never initialize the text-input engine. This is because real speech recognition backends should be returned from the function by default.

All dragonfly elements and rule classes should be supported. executable, title, and handle keyword arguments may optionally be passed to engine.mimic() to simulate a particular foreground window.

Engine Configuration

Dragonfly’s command-line interface can be used to test command modules with the text-input engine. Below are a few use cases for this engine:

# Example 1:
# Initialize the text-input engine back-end, load a command module and
# recognize from stdin.
echo "hello world" | python -m dragonfly test _module1.py

# Example 2:
# Initialize the text-input engine back-end and load a command module
# for browser commands and recognize from stdin with a processing delay
# of 2 seconds.  This allows testing context-specific browser commands.
python -m dragonfly test _browser.py --delay 2

# Example 3:
# Initialize the text-input engine back-end using German (de) as the
# language, then load a command module and recognize from stdin.
python -m dragonfly test _german_commands.py --language de

Engine API

class TextInputEngine[source]

Text-input Engine class.

connect()[source]

Connect to back-end SR engine.

create_timer(callback, interval, repeating=True)[source]

Create and return a timer using the specified callback and repeat interval.

Timers created using this engine will be run in a separate daemon thread, meaning that their callbacks will not be thread safe. threading.Timer() may be used instead with no blocking issues.

disconnect()[source]

Disconnect from back-end SR engine.

property language

Current user language of the SR engine.

Return type:

str

mimic(words, **kwargs)[source]

Mimic a recognition of the given words.

Parameters:

words (str|iter) – words to mimic

Keyword Arguments:

optional executable, title and/or handle keyword arguments may be used to simulate a specific foreground window context. The current foreground window attributes will be used instead for any keyword arguments not present.

set_exclusiveness(grammar, exclusive)[source]

Set the exclusiveness of a grammar.

speak(text)[source]

Speak the given text using text-to-speech.

Text Recognition Results Class

class Results(words, success)[source]

Text-input engine recognition results class.

property grammar

The grammar which processed this recognition, if any.

property recognition_success

Whether this recognition has been processed successfully.

property rule

The rule that matched this recognition, if any.

words()[source]

Get the words for this recognition.