Recognition observers
This section describes classes and functions for observing Dragonfly’s recognition state events:
on_begin()
– called when speech start is detected.
on_recognition()
– called when speech successfully decoded to a grammar rule or to dictation. This is called before grammar rule processing (i.e.Rule.process_recognition()
).
on_failure()
– called when speech failed to decode to a grammar rule or to dictation.
on_end()
– called when speech ends, either with a successful recognition or in failure.
Recognition observer classes
- class PlaybackHistory(length=10)[source]
Storage class for playing back recent recognitions via the
Playback
action.Instances of this class monitor recognitions and store them internally. This class derives from the built in list type and can be accessed as if it were a normal list containing
Playback
actions for recent recognitions. Note that an instance’s contents are updated automatically as recognitions are received.
- class RecognitionHistory(length=10)[source]
Storage class for recent recognitions.
Instances of this class monitor recognitions and store them internally. This class derives from the built in list type and can be accessed as if it were a normal list containing recent recognitions. Note that an instance’s contents are updated automatically as recognitions are received.
- property complete
False if phrase-start detected but no recognition yet.
- class RecognitionObserver[source]
Recognition observer base class.
Sub-classes should override one or more of the event methods.
- on_end(results=None)[source]
Method called when speech ends, either with a successful recognition (after
on_recognition
) or in failure (afteron_failure
).- Parameters:
results (engine-specific type) – optional engine recognition results object
- on_failure(results=None)[source]
Method called when speech failed to decode to a grammar rule or to dictation.
- Parameters:
results (engine-specific type) – optional engine recognition results object
- on_recognition(words, results=None)[source]
Method called when speech successfully decoded to a grammar rule or to dictation.
This is called before grammar rule processing, i.e., before
Rule.process_recognition()
.- Parameters:
words (tuple) – recognized words
results (engine-specific type) – optional engine recognition results object
Recognition state change callbacks
- class CallbackRecognitionObserver(event, function)[source]
Observer class for calling recognition state change callbacks.
This class is used by the
register_*_callback
functions and is registered with the current engine on initialization.- Constructor arguments:
event (str) – the name of the recognition event to register for (e.g.
"on_begin"
).function (callable) – function to call on the specified recognition event.
- register_beginning_callback(function)[source]
Register a callback function to be called when speech starts.
The
CallbackRecognitionObserver
object returned from this function can be used to unregister the callback function.- Parameters:
function (callable) – callback function
- Returns:
recognition observer
- Return type:
- register_ending_callback(function)[source]
Register a callback function to be called when speech ends, either successfully (after calling the recognition callback) or in failure (after calling the failure callback).
The
CallbackRecognitionObserver
object returned from this function can be used to unregister the callback function.- Parameters:
function (callable) – callback function
- Returns:
recognition observer
- Return type:
- register_failure_callback(function)[source]
Register a callback function to be called on recognition failures.
The
CallbackRecognitionObserver
object returned from this function can be used to unregister the callback function.- Parameters:
function (callable) – callback function
- Returns:
recognition observer
- Return type:
- register_recognition_callback(function)[source]
Register a callback function to be called on recognition success.
The
CallbackRecognitionObserver
object returned from this function can be used to unregister the callback function.- Parameters:
function (callable) – callback function
- Returns:
recognition observer
- Return type:
Doctest usage examples
See Dragonfly’s doctests for recognition observers for some usage examples.