Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Dragonfly

Docs Status Join Matrix/Gitter chat

Introduction

Dragonfly is a speech recognition framework for Python that makes it convenient to create custom commands to use with speech recognition software. It was written to make it very easy for Python macros, scripts, and applications to interface with speech recognition engines. Its design allows speech commands and grammar objects to be treated as first-class Python objects.

Dragonfly can be used for general programming by voice. It is flexible enough to allow programming in any language, not just Python. It can also be used for speech-enabling applications, automating computer activities and dictating prose.

Dragonfly contains its own powerful framework for defining and executing actions. It includes actions for text input and key-stroke simulation. This framework is cross-platform, working on Windows, macOS and Linux (X11 only). See the actions sub-package documentation for more information, including code examples.

This project is a fork of the original t4ngo/dragonfly project.

Dragonfly currently supports the following speech recognition engines:

  • Dragon, a product of Nuance. All versions up to 16 (the latest) should be supported. Home, Professional Individual and previous similar editions of Dragon are supported. Other editions may work too.

  • Windows Speech Recognition (WSR), included with Microsoft Windows Vista, Windows 7+, and freely available for Windows XP.

  • Kaldi, open source (AGPL) and multi-platform.

  • CMU Pocket Sphinx, open source and multi-platform.

Documentation and FAQ

Dragonfly’s documentation is available online at Read the Docs. The changes in each release are listed in the project’s changelog. Dragonfly’s FAQ is available in the documentation here. There are also a number of Dragonfly-related questions on Stackoverflow, although many of them are related to issues resolved in the latest version of Dragonfly.

CompoundRule Usage example

A very simple example of Dragonfly usage is to create a static voice command with a callback that will be called when the command is spoken. This is done as follows:

from dragonfly import Grammar, CompoundRule

# Voice command rule combining spoken form and recognition processing.
class ExampleRule(CompoundRule):
    spec = "do something computer"                  # Spoken form of command.
    def _process_recognition(self, node, extras):   # Callback when command is spoken.
        print("Voice command spoken.")

# Create a grammar which contains and loads the command rule.
grammar = Grammar("example grammar")                # Create a grammar to contain the command rule.
grammar.add_rule(ExampleRule())                     # Add the command rule to the grammar.
grammar.load()                                      # Load the grammar.

To use this example, save it in a command module in your module loader directory or Natlink user directory, load it and then say do something computer. If the speech recognition engine recognized the command, then Voice command spoken. will be printed in the Natlink messages window. If you’re not using Dragon, then it will be printed into the console window.

MappingRule usage example

A more common use of Dragonfly is the MappingRule class, which allows defining multiple voice commands. The following example is a simple grammar to be used when Notepad is the foreground window:

from dragonfly import (Grammar, AppContext, MappingRule, Dictation,
                       Key, Text)

# Voice command rule combining spoken forms and action execution.
class NotepadRule(MappingRule):
    # Define the commands and the actions they execute.
    mapping = {
        "save [file]":            Key("c-s"),
        "save [file] as":         Key("a-f, a/20"),
        "save [file] as <text>":  Key("a-f, a/20") + Text("%(text)s"),
        "find <text>":            Key("c-f/20") + Text("%(text)s\n"),
    }

    # Define the extras list of Dragonfly elements which are available
    # to be used in mapping specs and actions.
    extras = [
        Dictation("text")
    ]


# Create the grammar and the context under which it'll be active.
context = AppContext(executable="notepad")
grammar = Grammar("Notepad example", context=context)

# Add the command rule to the grammar and load it.
grammar.add_rule(NotepadRule())
grammar.load()

To use this example, save it in a command module in your module loader directory or Natlink user directory, load it, open a Notepad window and then say one of mapping commands. For example, saying save or save file will cause the control and S keys to be pressed.

The example aboves don’t show any of Dragonfly’s exciting features, such as dynamic speech elements. To learn more about these, please take a look at Dragonfly’s online docs.

Installation

Dragonfly is a Python package. It can be installed as dragonfly using pip:

pip install dragonfly

If you are installing this on Linux, you will also need to install the wmctrl, xdotool and xsel programs.

Please note that, on Linux, Dragonfly is only fully functional in an X11 session. Input action classes, application contexts and the Window class will not be functional under Wayland. It is recommended that Wayland users switch to X11, Windows or macOS.

Dragonfly can also be installed by cloning this repository or downloading it from the releases page and running the following (or similar) command in the project’s root directory:

python setup.py install

If pip fails to install dragonfly or any of its required or extra dependencies, then you may need to upgrade pip with the following command:

pip install --upgrade pip

Speech recognition engine back-ends

Installation instructions, requirements and API references for each Dragonfly speech recognition engine are documented separately on the following pages:

Existing command modules

The related resources page of Dragonfly’s documentation has a section on command modules which lists various sources.

Release files for dragonfly 1.0.0rc2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dragonfly 1.0.0rc2
File Size Uploaded
dragonfly-1.0.0rc2.tar.gz 356.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dragonfly 1.0.0rc2
File Interpreter ABI Platform
dragonfly-1.0.0rc2-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 795.0 kB

Release files / dragonfly-1.0.0rc2.tar.gz

Download URL dragonfly-1.0.0rc2.tar.gz
Size 356.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bda9288c2d4d9756a6662816749f393a1bae59156c1effa2a414bec119191d09
BLAKE2b-256 checksum
How to use checksums
27ce902975b86a493786f1e72b9b0e8f6a63b5d068eac03c8bc1aff44b4d6137
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1

Release files / dragonfly-1.0.0rc2-py2.py3-none-any.whl

Download URL dragonfly-1.0.0rc2-py2.py3-none-any.whl
Size 438.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1df63a3ee192aadbccb5f47843b159a61b7531847a62c862b6a4062e71732924
BLAKE2b-256 checksum
How to use checksums
4b710606e031db0178981f37e6861332bf189a27c8b8b75ab7288bd4b616f7e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.1
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page