TTS Engines

Engine interface

class talkey.base.AbstractTTSEngine(**_options)

Generic parent class for all speakers

SLUG = None

The SLUG is used to identify the engine as text

classmethod _get_init_options()

AbstractMethod: Returns dict of engine options

_get_languages()

AbstractMethod: Returns dict of supported languages and voices

_get_options()

AbstractMethod: Returns dict of voice options

_is_available()

AbstractMethod: Boolean on if engine is available

_say(phrase, language, voice, voiceinfo, options)

AbstractMethod: Let engin actually says the phrase

Phrase:The text phrase to say
Language:The requested language
Voice:The requested voice
Voiceinfo:Data about the requested voice
Options:Extra options
configure(**_options)

Sets language-specific configuration.

Raises TTSError on error.

configure_default(**_options)

Sets default configuration.

Raises TTSError on error.

classmethod get_init_options()

Returns a dict describing the engine options.

Uses cls._get_init_options()

get_languages()

Returns dict of supported languages and voices.

Raises TTSError if not available.

get_options()

Returns dict of voice options.

Raises TTSError if not available.

is_available()

Boolean on if engine available.

Checks if enabled, can output audio and self._is_available()

play(filename, translate=False)

Plays the sounds.

Filename:The input file name
Translate:If True, it runs it through audioread which will translate from common compression formats to raw WAV.
say(phrase, **_options)

Says the phrase, optionally allows to select/override any voice options.

Creating your own engine

Subclass talkey.base.AbstractTTSEngine, and provide the abstract methods:

from talkey.base import AbstractTTSEngine

class SampleTTS(AbstractTTSEngine):
    SLUG = "sample"

    @classmethod
    def _get_init_options(cls):
        # Engine options
        return {
            'enabled': {
                'description': 'Disabled by default',
                'type': 'bool',
                'default': False,
            },
        }

    def _is_available(self):
        # Checks for engine availability/readiness
        return True

    def _get_options(self):
        # Same format as _get_init_options
        # This is the voice options
        return {
            'mooing': {
                'description': 'Cows sound effect',
                'type': 'bool',
                'default': False,
            },
        }

    def _get_languages(self):
        # Dict of languages containing voices
        return {
            'en': {
                'default': 'english',
                'voices': {
                    'english': {
                        # Any extra options describing this voice
                        # (for private use)
                    },
                    'cowlish': {
                        # Any extra options describing this voice
                        # (for private use)
                    }
                }
            },
            ...
        }

    def _say(self, phrase, language, voice, voiceinfo, options):
        # Actually run the phrase through the TTS Engine.
        # All parameters will be always provided for you
        ...