Engines sub-package
Dragonfly supports multiple speech recognition engines as its backend. The engines sub-package implements the interface code for each supported engine.
Also contained within this sub-package are a number of text-to-speech
implementations. These can be used independently of the speech recognition
engines via the get_speaker()
function.
Main SR engine back-end interface
- get_current_engine()[source]
Get the currently initialized SR engine object.
If an SR engine has not been initialized yet,
None
will be returned instead.- Return type:
EngineBase | None
- Returns:
engine object or None
Usage example:
# Print the name of the current engine if one has been # initialized. from dragonfly import get_current_engine engine = get_current_engine() if engine: print("Engine name: %r" % engine.name) else: print("No engine has been initialized.")
- get_engine(name=None, **kwargs)[source]
Get the engine implementation.
This function will initialize an engine instance using the
get_engine
andis_engine_available
functions in the engine packages and return an instance of the first available engine. If one has already been initialized, it will be returned instead.If no specific engine is requested and no engine has already been initialized, this function will initialize and return an instance of the first available engine in the following order:
SR engine back-end
Engine name string(s)
Dragon/Natlink
"natlink"
Kaldi
"kaldi"
WSR/SAPI 5
"sapi5", "sapi5inproc", "sapi5shared"
CMU Pocket Sphinx
"sphinx"
The Text-input engine can be initialized by specifying
"text"
as the engine name. This back-end will not be initialized if no specific engine is requested because the back-end is not a real SR engine and is used mostly for testing.Arguments:
- Parameters:
name (str) – optional human-readable name of the engine to return.
**kwargs – optional keyword arguments passed through to the engine for engine-specific configuration.
- Return type:
- Returns:
engine instance
- Raises:
EngineError
- get_speaker(name=None)[source]
Get the text-to-speech (speaker) implementation.
This function will initialize and return a speaker instance instance of the available speaker back-end. If one has already been initialized, it will be returned instead.
If no specific speaker back-end is requested and no speaker has already been initialized, this function will initialize and return an instance of the first available back-end in the following order:
TTS speaker back-end
Speaker name string(s)
SAPI 5
"sapi5"
Dragon/Natlink
"natlink"
eSpeak
"espeak"
CMU Flite
"flite"
Text (stdout)
"text"
The first two speaker back-ends are only available on Microsoft Windows. The second requires that Dragon NaturallySpeaking and Natlink are installed on the system.
The third and fourth back-ends, eSpeak and CMU Flite, may be used on most platforms. These require that the appropriate command-line programs are installed on the system.
The last back-end (text) is used as a fallback when no real speaker implementation is available. This back-end writes input text to stdout, i.e., prints text to the console.
Arguments:
- Parameters:
name (str) – optional human-readable name of the speaker to return.
- Return type:
- Returns:
speaker instance
- Raises:
EngineError
Engine back-ends
Text-to-speech (speaker) back-ends
For more information on the available text-to-speech implementations, see the following sections: