aqt.tts#

Basic text to speech support.

Users can use the following in their card template:

{{tts en_US:Field}}

or

{{tts ja_JP voices=Kyoko,Otoya,Another_name:Field}}

The first argument must be an underscored language code, eg en_US.

If provided, voices is a comma-separated list of one or more voices that the user would prefer. Spaces must not be included. Underscores will be converted to spaces.

AVPlayer decides which TTSPlayer to use based on the returned rank. In the default implementation, the TTS player is chosen based on the order of voices the user has specified. When adding new TTS players, your code can either expose the underlying names the TTS engine provides, or simply expose the name of the engine, which would mean the user could write {{tts en_AU voices=MyEngine}} to prioritize your engine.

Attributes#

Classes#

TTSVoice

TTSVoiceMatch

TTSPlayer

TTSProcessPlayer

MacVoice

MacTTSPlayer

Invokes a process to play the audio in the background.

MacTTSFilePlayer

Generates an .aiff file, which is played using av_player.

WindowsVoice

Functions#

all_tts_voices(→ list[TTSVoice])

on_tts_voices(→ str)

Module Contents#

class aqt.tts.TTSVoice#
name: str#
lang: str#
unavailable() bool#
class aqt.tts.TTSVoiceMatch#
voice: TTSVoice#
rank: int#
class aqt.tts.TTSPlayer#
default_rank = 0#
get_available_voices() list[TTSVoice]#
voices() list[TTSVoice]#
voice_for_tag(tag: anki.sound.TTSTag) TTSVoiceMatch | None#
temp_file_for_tag_and_voice(tag: anki.sound.AVTag, voice: TTSVoice) str#

Return a hashed filename, to allow for caching generated files.

No file extension is included.

class aqt.tts.TTSProcessPlayer#

Bases: aqt.sound.SimpleProcessPlayer, TTSPlayer

rank_for_tag(tag: anki.sound.AVTag) int | None#
aqt.tts.all_tts_voices() list[TTSVoice]#
aqt.tts.on_tts_voices(text: str, field: str, filter: str, ctx: anki.template.TemplateRenderContext) str#
class aqt.tts.MacVoice#

Bases: TTSVoice

original_name: str#
class aqt.tts.MacTTSPlayer#

Bases: TTSProcessPlayer

Invokes a process to play the audio in the background.

VOICE_HELP_LINE_RE#
get_available_voices() list[TTSVoice]#
class aqt.tts.MacTTSFilePlayer#

Bases: MacTTSPlayer

Generates an .aiff file, which is played using av_player.

tmppath#
class aqt.tts.WindowsVoice#

Bases: TTSVoice

handle: Any#
aqt.tts.LCIDS#