aqt.tts
=======

.. py:module:: aqt.tts

.. autoapi-nested-parse::

   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
----------

.. autoapisummary::

   aqt.tts.LCIDS


Classes
-------

.. autoapisummary::

   aqt.tts.TTSVoice
   aqt.tts.TTSVoiceMatch
   aqt.tts.TTSPlayer
   aqt.tts.TTSProcessPlayer
   aqt.tts.MacVoice
   aqt.tts.MacTTSPlayer
   aqt.tts.MacTTSFilePlayer
   aqt.tts.WindowsVoice


Functions
---------

.. autoapisummary::

   aqt.tts.all_tts_voices
   aqt.tts.on_tts_voices


Module Contents
---------------

.. py:class:: TTSVoice

   .. py:attribute:: name
      :type:  str


   .. py:attribute:: lang
      :type:  str


   .. py:method:: unavailable() -> bool


.. py:class:: TTSVoiceMatch

   .. py:attribute:: voice
      :type:  TTSVoice


   .. py:attribute:: rank
      :type:  int


.. py:class:: TTSPlayer

   .. py:attribute:: default_rank
      :value: 0



   .. py:method:: get_available_voices() -> list[TTSVoice]


   .. py:method:: voices() -> list[TTSVoice]


   .. py:method:: voice_for_tag(tag: anki.sound.TTSTag) -> TTSVoiceMatch | None


   .. py:method:: 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.



.. py:class:: TTSProcessPlayer

   Bases: :py:obj:`aqt.sound.SimpleProcessPlayer`, :py:obj:`TTSPlayer`


   .. py:method:: rank_for_tag(tag: anki.sound.AVTag) -> int | None


.. py:function:: all_tts_voices() -> list[TTSVoice]

.. py:function:: on_tts_voices(text: str, field: str, filter: str, ctx: anki.template.TemplateRenderContext) -> str

.. py:class:: MacVoice

   Bases: :py:obj:`TTSVoice`


   .. py:attribute:: original_name
      :type:  str


.. py:class:: MacTTSPlayer

   Bases: :py:obj:`TTSProcessPlayer`


   Invokes a process to play the audio in the background.


   .. py:attribute:: VOICE_HELP_LINE_RE


   .. py:method:: get_available_voices() -> list[TTSVoice]


.. py:class:: MacTTSFilePlayer

   Bases: :py:obj:`MacTTSPlayer`


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


   .. py:attribute:: tmppath


.. py:class:: WindowsVoice

   Bases: :py:obj:`TTSVoice`


   .. py:attribute:: handle
      :type:  Any


.. py:data:: LCIDS

