Home Assistant Unofficial Reference 2024.12.1
homeassistant.components.tts Namespace Reference

Namespaces

 const
 
 helper
 
 legacy
 
 media_source
 
 models
 
 notify
 

Classes

class  SpeechManager
 
class  TextToSpeechEntity
 
class  TextToSpeechUrlView
 
class  TextToSpeechView
 
class  TTSCache
 

Functions

bytes _convert_audio (str ffmpeg_binary, str from_extension, bytes audio_bytes, str to_extension, int|None to_sample_rate=None, int|None to_sample_channels=None, int|None to_sample_bytes=None)
 
dict[str, str] _get_cache_files (str cache_dir)
 
str _hash_options (dict options)
 
str _init_tts_cache_dir (HomeAssistant hass, str cache_dir)
 
bytes async_convert_audio (HomeAssistant hass, str from_extension, bytes audio_bytes, str to_extension, int|None to_sample_rate=None, int|None to_sample_channels=None, int|None to_sample_bytes=None)
 
str|None async_default_engine (HomeAssistant hass)
 
tuple[str, bytes] async_get_media_source_audio (HomeAssistant hass, str media_source_id)
 
set[str] async_get_text_to_speech_languages (HomeAssistant hass)
 
str|None async_resolve_engine (HomeAssistant hass, str|None engine)
 
bool async_setup (HomeAssistant hass, ConfigType config)
 
bool async_setup_entry (HomeAssistant hass, ConfigEntry entry)
 
bool async_support_options (HomeAssistant hass, str engine, str|None language=None, dict|None options=None)
 
bool async_unload_entry (HomeAssistant hass, ConfigEntry entry)
 
None websocket_get_engine (HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
None websocket_list_engine_voices (HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 
None websocket_list_engines (HomeAssistant hass, websocket_api.ActiveConnection connection, dict msg)
 

Variables

list __all__
 
string _DEFAULT_FORMAT = "mp3"
 
 _LOGGER = logging.getLogger(__name__)
 
 _RE_LEGACY_VOICE_FILE
 
 _RE_VOICE_FILE
 
string ATTR_AUDIO_OUTPUT = "audio_output"
 
string ATTR_MEDIA_PLAYER_ENTITY_ID = "media_player_entity_id"
 
string ATTR_PLATFORM = "platform"
 
string ATTR_PREFERRED_FORMAT = "preferred_format"
 
string ATTR_PREFERRED_SAMPLE_BYTES = "preferred_sample_bytes"
 
string ATTR_PREFERRED_SAMPLE_CHANNELS = "preferred_sample_channels"
 
string ATTR_PREFERRED_SAMPLE_RATE = "preferred_sample_rate"
 
string ATTR_VOICE = "voice"
 
dictionary CACHED_PROPERTIES_WITH_ATTR_
 
string CONF_LANG = "language"
 
string KEY_PATTERN = "{0}_{1}_{2}_{3}"
 
 SCHEMA_SERVICE_CLEAR_CACHE = vol.Schema({})
 
string SERVICE_CLEAR_CACHE = "clear_cache"
 

Detailed Description

Provide functionality for TTS.

Function Documentation

◆ _convert_audio()

bytes homeassistant.components.tts._convert_audio ( str  ffmpeg_binary,
str  from_extension,
bytes  audio_bytes,
str  to_extension,
int | None   to_sample_rate = None,
int | None   to_sample_channels = None,
int | None   to_sample_bytes = None 
)
private
Convert audio to a preferred format using ffmpeg.

Definition at line 240 of file __init__.py.

◆ _get_cache_files()

dict[str, str] homeassistant.components.tts._get_cache_files ( str  cache_dir)
private
Return a dict of given engine files.

Definition at line 1022 of file __init__.py.

◆ _hash_options()

str homeassistant.components.tts._hash_options ( dict  options)
private
Hashes an options dictionary.

Definition at line 514 of file __init__.py.

◆ _init_tts_cache_dir()

str homeassistant.components.tts._init_tts_cache_dir ( HomeAssistant  hass,
str  cache_dir 
)
private
Init cache folder.

Definition at line 1012 of file __init__.py.

◆ async_convert_audio()

bytes homeassistant.components.tts.async_convert_audio ( HomeAssistant  hass,
str  from_extension,
bytes  audio_bytes,
str  to_extension,
int | None   to_sample_rate = None,
int | None   to_sample_channels = None,
int | None   to_sample_bytes = None 
)
Convert audio to a preferred format using ffmpeg.

Definition at line 216 of file __init__.py.

◆ async_default_engine()

str | None homeassistant.components.tts.async_default_engine ( HomeAssistant  hass)
Return the domain or entity id of the default engine.

Returns None if no engines found.

Definition at line 138 of file __init__.py.

◆ async_get_media_source_audio()

tuple[str, bytes] homeassistant.components.tts.async_get_media_source_audio ( HomeAssistant  hass,
str  media_source_id 
)
Get TTS audio as extension, data.

Definition at line 190 of file __init__.py.

◆ async_get_text_to_speech_languages()

set[str] homeassistant.components.tts.async_get_text_to_speech_languages ( HomeAssistant  hass)
Return a set with the union of languages supported by tts engines.

Definition at line 201 of file __init__.py.

◆ async_resolve_engine()

str | None homeassistant.components.tts.async_resolve_engine ( HomeAssistant  hass,
str | None  engine 
)
Resolve engine.

Returns None if no engines found or invalid engine passed in.

Definition at line 156 of file __init__.py.

◆ async_setup()

bool homeassistant.components.tts.async_setup ( HomeAssistant  hass,
ConfigType  config 
)
Set up TTS.

Definition at line 301 of file __init__.py.

◆ async_setup_entry()

bool homeassistant.components.tts.async_setup_entry ( HomeAssistant  hass,
ConfigEntry  entry 
)
Set up a config entry.

Definition at line 368 of file __init__.py.

◆ async_support_options()

bool homeassistant.components.tts.async_support_options ( HomeAssistant  hass,
str  engine,
str | None   language = None,
dict | None   options = None 
)
Return if an engine supports options.

Definition at line 172 of file __init__.py.

◆ async_unload_entry()

bool homeassistant.components.tts.async_unload_entry ( HomeAssistant  hass,
ConfigEntry  entry 
)
Unload a config entry.

Definition at line 373 of file __init__.py.

◆ websocket_get_engine()

None homeassistant.components.tts.websocket_get_engine ( HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
Get text to speech engine info.

Definition at line 1163 of file __init__.py.

◆ websocket_list_engine_voices()

None homeassistant.components.tts.websocket_list_engine_voices ( HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
List voices for a given language.

Definition at line 1209 of file __init__.py.

◆ websocket_list_engines()

None homeassistant.components.tts.websocket_list_engines ( HomeAssistant  hass,
websocket_api.ActiveConnection  connection,
dict   msg 
)
List text to speech engines and, optionally, if they support a given language.

Definition at line 1115 of file __init__.py.

Variable Documentation

◆ __all__

list homeassistant.components.tts.__all__
private
Initial value:
1 = [
2  "async_default_engine",
3  "async_get_media_source_audio",
4  "async_support_options",
5  "ATTR_AUDIO_OUTPUT",
6  "ATTR_PREFERRED_FORMAT",
7  "ATTR_PREFERRED_SAMPLE_RATE",
8  "ATTR_PREFERRED_SAMPLE_CHANNELS",
9  "ATTR_PREFERRED_SAMPLE_BYTES",
10  "CONF_LANG",
11  "DEFAULT_CACHE_DIR",
12  "generate_media_source_id",
13  "PLATFORM_SCHEMA_BASE",
14  "PLATFORM_SCHEMA",
15  "SampleFormat",
16  "Provider",
17  "TtsAudioType",
18  "Voice",
19 ]

Definition at line 75 of file __init__.py.

◆ _DEFAULT_FORMAT

string homeassistant.components.tts._DEFAULT_FORMAT = "mp3"
private

Definition at line 106 of file __init__.py.

◆ _LOGGER

homeassistant.components.tts._LOGGER = logging.getLogger(__name__)
private

Definition at line 95 of file __init__.py.

◆ _RE_LEGACY_VOICE_FILE

homeassistant.components.tts._RE_LEGACY_VOICE_FILE
private
Initial value:
1 = re.compile(
2  r"([a-f0-9]{40})_([^_]+)_([^_]+)_([a-z_]+)\.[a-z0-9]{3,4}"
3 )

Definition at line 118 of file __init__.py.

◆ _RE_VOICE_FILE

homeassistant.components.tts._RE_VOICE_FILE
private
Initial value:
1 = re.compile(
2  r"([a-f0-9]{40})_([^_]+)_([^_]+)_(tts\.[a-z0-9_]+)\.[a-z0-9]{3,4}"
3 )

Definition at line 121 of file __init__.py.

◆ ATTR_AUDIO_OUTPUT

string homeassistant.components.tts.ATTR_AUDIO_OUTPUT = "audio_output"

Definition at line 98 of file __init__.py.

◆ ATTR_MEDIA_PLAYER_ENTITY_ID

string homeassistant.components.tts.ATTR_MEDIA_PLAYER_ENTITY_ID = "media_player_entity_id"

Definition at line 103 of file __init__.py.

◆ ATTR_PLATFORM

string homeassistant.components.tts.ATTR_PLATFORM = "platform"

Definition at line 97 of file __init__.py.

◆ ATTR_PREFERRED_FORMAT

string homeassistant.components.tts.ATTR_PREFERRED_FORMAT = "preferred_format"

Definition at line 99 of file __init__.py.

◆ ATTR_PREFERRED_SAMPLE_BYTES

string homeassistant.components.tts.ATTR_PREFERRED_SAMPLE_BYTES = "preferred_sample_bytes"

Definition at line 102 of file __init__.py.

◆ ATTR_PREFERRED_SAMPLE_CHANNELS

string homeassistant.components.tts.ATTR_PREFERRED_SAMPLE_CHANNELS = "preferred_sample_channels"

Definition at line 101 of file __init__.py.

◆ ATTR_PREFERRED_SAMPLE_RATE

string homeassistant.components.tts.ATTR_PREFERRED_SAMPLE_RATE = "preferred_sample_rate"

Definition at line 100 of file __init__.py.

◆ ATTR_VOICE

string homeassistant.components.tts.ATTR_VOICE = "voice"

Definition at line 104 of file __init__.py.

◆ CACHED_PROPERTIES_WITH_ATTR_

dictionary homeassistant.components.tts.CACHED_PROPERTIES_WITH_ATTR_
Initial value:
1 = {
2  "default_language",
3  "default_options",
4  "supported_languages",
5  "supported_options",
6 }

Definition at line 378 of file __init__.py.

◆ CONF_LANG

string homeassistant.components.tts.CONF_LANG = "language"

Definition at line 114 of file __init__.py.

◆ KEY_PATTERN

string homeassistant.components.tts.KEY_PATTERN = "{0}_{1}_{2}_{3}"

Definition at line 124 of file __init__.py.

◆ SCHEMA_SERVICE_CLEAR_CACHE

homeassistant.components.tts.SCHEMA_SERVICE_CLEAR_CACHE = vol.Schema({})

Definition at line 126 of file __init__.py.

◆ SERVICE_CLEAR_CACHE

string homeassistant.components.tts.SERVICE_CLEAR_CACHE = "clear_cache"

Definition at line 116 of file __init__.py.