This module contains the following classes:

class aeneas.ttswrappers.basettswrapper.BaseTTSWrapper(rconf=None, logger=None)[source]

An abstract wrapper for a TTS engine.

It calls the TTS executable or library, passing parameters like the text string and languages, and it produces a WAVE file on disk and a list of time anchors.

In case of multiple text fragments, the resulting WAVE files will be joined together in a single WAVE file.

The TTS parameters, their order, and the switches can be configured in the concrete subclass for a specific TTS engine.

For example, it might perform one or more calls like

$ echo "text" | tts -v voice_code -w output_file.wav
$ tts -eval "(voice_code)" -i text_file.txt -o output_file.wav

The call methods will be attempted in the following order:

  1. direct Python call
  2. Python C extension
  3. TTS executable via subprocess

NotImplementedError: if none of the call methods is available


Placeholder to specify the path to the UTF-8 encoded file containing the text to be synthesized, to be read by the TTS engine.


Placeholder to specify that the TTS engine reads the text to be synthesized from stdin.


Placeholder to specify a list of arguments for the TTS engine to select the TTS voice to be used for synthesizing the text.


Placeholder for the voice code string.


Placeholder to specify the path to the audio file to be synthesized by the TTS engine.


Placeholder to specify that the TTS engine outputs the audio data to stdout.


Map from voice code to human-readable name.


List of all language codes with their human-readable names.


If the TTS wrapper can invoke the TTS engine via a C extension call, set here the name of the corresponding Python C/C++ extension.


The default language for this TTS engine. Concrete subclasses must populate this class field, according to the languages supported by the TTS engine they wrap.


The default path for this TTS engine, when called via subprocess, otherwise set it to None.


If True, the TTS wrapper can invoke the TTS engine via a C extension call.


If True, the TTS wrapper can invoke the TTS engine via a direct Python call.


If True, the TTS wrapper can invoke the TTS engine via subprocess.


Map a language code to a voice code. Concrete subclasses must populate this class field, according to the language and voice codes supported by the TTS engine they wrap.


A tuple (codec, channels, rate) specifying the format of the audio file generated by the TTS engine, for example ("pcm_s16le", 1, 22050). If unknown, set it to None: in this case, the audio file will be converted to PCM16 mono WAVE (RIFF) as needed.


Clear the TTS cache, removing all cache files from disk.

New in version 1.6.0.


Set the list of arguments that the wrapper will pass to subprocess.

Placeholders CLI_PARAMETER_* can be used, and they will be replaced by actual values in the _synthesize_multiple_subprocess() and _synthesize_single_subprocess() built-in functions. Literal parameters will be passed unchanged.

The list should start with the path to the TTS engine.

This function should be called in the constructor of concrete subclasses.

Parameters:subprocess_arguments (list) – the list of arguments to be passed to the TTS engine via subprocess
synthesize_multiple(text_file, output_file_path, quit_after=None, backwards=False)[source]

Synthesize the text contained in the given fragment list into a WAVE file.

Return a tuple (anchors, total_time, num_chars).

Concrete subclasses must implement at least one of the following private functions:

  1. _synthesize_multiple_python()
  2. _synthesize_multiple_c_extension()
  3. _synthesize_multiple_subprocess()
  • text_file (TextFile) – the text file to be synthesized
  • output_file_path (string) – the path to the output audio file
  • quit_after (TimeValue) – stop synthesizing as soon as reaching this many seconds
  • backwards (bool) – if > 0, synthesize from the end of the text file
Return type:

tuple (anchors, total_time, num_chars)


TypeError: if text_file is None or one of the text fragments is not a Unicode string


ValueError: if self.rconf[RuntimeConfiguration.ALLOW_UNLISTED_LANGUAGES] is False and a fragment has a language code not supported by the TTS engine, or if text_file has no fragments or all its fragments are empty


OSError: if output file cannot be written to output_file_path


RuntimeError: if both the C extension and the pure Python code did not succeed.

class aeneas.ttswrappers.basettswrapper.TTSCache(rconf=None, logger=None)[source]

A TTS cache, that is, a dictionary whose keys are pairs (fragment_language, fragment_text) and whose values are pairs (file_handler, file_path).

An item in the cache means that the text of the key has been synthesized to the file located at the path of the corresponding value.

Note that it is not enough to store the string of the text as the key, since the same text might be pronounced in a different language.

Also note that the values also store the file handler, since we might want to close it explicitly before removing the file from disk.

add(fragment_info, file_info)[source]

Add the given (key, value) pair to the cache.

  • fragment_info (tuple of str (language, text)) – the text key
  • file_info (tuple (handler, path)) – the path value

ValueError if the key is already present in the cache


Clear the cache and remove all the files from disk.


Get the value associated with the given key.

Parameters:fragment_info (tuple of str (language, text)) – the text key
Raises:KeyError if the key is not present in the cache

Return True if the given (language, text) key is present in the cache, or False otherwise.

Return type:bool

Return the sorted list of keys currently in the cache.

Return type:list of tuples (language, text)