Mycroft plugins¶
Mycroft is extendable by plugins. These plugins can add support for new Speech To Text engines, Text To Speech engines, wake word engines and add new audio playback options.
TTS - Base for TTS plugins¶
- class mycroft.tts.TTS(lang, config, validator, audio_ext='wav', phonetic_spelling=True, ssml_tags=None)[source]¶
TTS abstract class to be implemented by all TTS engines.
It aggregates the minimum required parameters and exposes
execute(sentence)
andvalidate_ssml(sentence)
functions.- Parameters
lang (str) –
config (dict) – Configuration for this specific tts engine
validator (TTSValidator) – Used to verify proper installation
phonetic_spelling (bool) – Whether to spell certain words phonetically
ssml_tags (list) – Supported ssml properties. Ex. [‘speak’, ‘prosody’]
- end_audio(listen=False)[source]¶
Helper function for child classes to call in execute().
Sends the recognizer_loop:audio_output_end message (indicating that speaking is done for the moment) as well as trigger listening if it has been requested. It also checks if cache directory needs cleaning to free up disk space.
- Parameters
listen (bool) – indication if listening trigger should be sent.
- execute(sentence, ident=None, listen=False)[source]¶
Convert sentence to speech, preprocessing out unsupported ssml
The method caches results if possible using the hash of the sentence.
- Parameters
sentence – (str) Sentence to be spoken
ident – (str) Id reference to current interaction
listen – (bool) True if listen should be triggered at the end of the utterance.
- get_tts(sentence, wav_file)[source]¶
Abstract method that a tts implementation needs to implement.
Should get data from tts.
- Parameters
sentence (str) – Sentence to synthesize
wav_file (str) – output file
- Returns
(wav_file, phoneme)
- Return type
tuple
- init(bus)[source]¶
Performs intial setup of TTS object.
- Parameters
bus – Mycroft messagebus connection
- load_phonemes(key)[source]¶
Load phonemes from cache file.
- Parameters
key (str) – Key identifying phoneme cache
- modify_tag(tag)[source]¶
Override to modify each supported ssml tag.
- Parameters
tag (str) – SSML tag to check and possibly transform.
- static remove_ssml(text)[source]¶
Removes SSML tags from a string.
- Parameters
text (str) – input string
- Returns
input string stripped from tags.
- Return type
str
- save_phonemes(key, phonemes)[source]¶
Cache phonemes
- Parameters
key (str) – Hash key for the sentence
phonemes (str) – phoneme string to save
STT - base for STT plugins¶
- class mycroft.stt.STT[source]¶
STT Base class, all STT backends derive from this one.
- abstract execute(audio, language=None)[source]¶
Implementation of STT functionallity.
This method needs to be implemented by the derived class to implement the specific STT engine connection.
The method gets passed audio and optionally a language code and is expected to return a text string.
- Parameters
audio (AudioData) – audio recorded by mycroft.
language (str) – optional language code
- Returns
parsed text
- Return type
str
- class mycroft.stt.StreamingSTT[source]¶
ABC class for threaded streaming STT implemenations.
- abstract create_streaming_thread()[source]¶
Create thread for parsing audio chunks.
This method should be implemented by the derived class to return an instance derived from StreamThread to handle the audio stream and send it to the STT engine.
- Returns
Thread to handle audio data.
- Return type
- class mycroft.stt.StreamThread(queue, language)[source]¶
ABC class to be used with StreamingSTT class implementations.
This class reads audio chunks from a queue and sends it to a parsing STT engine.
- Parameters
queue (Queue) – Input Queue
language (str) – language code for the current language.
HotWordEngine - Base for Hotword engine plugins¶
- class mycroft.client.speech.hotword_factory.HotWordEngine(key_phrase='hey mycroft', config=None, lang='en-us')[source]¶
Hotword/Wakeword base class to be implemented by all wake word plugins.
- Parameters
key_phrase (str) – string representation of the wake word
config (dict) – Configuration block for the specific wake word
lang (str) – language code (BCP-47)
- found_wake_word(frame_data)[source]¶
Check if wake word has been found.
Checks if the wake word has been found. Should reset any internal tracking of the wake word state.
- Parameters
frame_data (binary data) – Deprecated. Audio data for large chunk of audio to be processed. This should not be used to detect audio data instead use update() to incrementaly update audio
- Returns
True if a wake word was detected, else False
- Return type
bool
AudioBackend - Base for audioservice backend plugins¶
- class mycroft.audio.services.AudioBackend(config, bus)[source]¶
Base class for all audio backend implementations.
- Parameters
config (dict) – configuration dict for the instance
bus (MessageBusClient) – Mycroft messagebus emitter
- abstract add_list(tracks)[source]¶
Add tracks to backend’s playlist.
- Parameters
tracks (list) – list of tracks.
- lower_volume()[source]¶
Lower volume.
This method is used to implement audio ducking. It will be called when Mycroft is listening or speaking to make sure the media playing isn’t interfering.
- pause()[source]¶
Pause playback.
Stops playback but may be resumed at the exact position the pause occured.
- abstract play(repeat=False)[source]¶
Start playback.
Starts playing the first track in the playlist and will contiune until all tracks have been played.
- Parameters
repeat (bool) – Repeat playlist, defaults to False
- restore_volume()[source]¶
Restore normal volume.
Called when to restore the playback volume to previous level after Mycroft has lowered it using lower_volume().
- seek_backward(seconds=1)[source]¶
Rewind X seconds.
- Parameters
seconds (int) – number of seconds to seek, if negative jump forward.
- seek_forward(seconds=1)[source]¶
Skip X seconds.
- Parameters
seconds (int) – number of seconds to seek, if negative rewind
- set_track_start_callback(callback_func)[source]¶
Register callback on track start.
This method should be called as each track in a playlist is started.
- shutdown()[source]¶
Perform clean shutdown.
Implements any audio backend specific shutdown procedures.
- abstract stop()[source]¶
Stop playback.
Stops the current playback.
- Returns
True if playback was stopped, otherwise False
- Return type
bool
- class mycroft.audio.services.RemoteAudioBackend(config, bus)[source]¶
Base class for remote audio backends.
RemoteAudioBackends will always be checked after the normal AudioBackends to make playback start locally by default.
An example of a RemoteAudioBackend would be things like Chromecasts, mopidy servers, etc.