1 """The ElevenLabs text-to-speech integration."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
7 from elevenlabs
import Model
8 from elevenlabs.client
import AsyncElevenLabs
9 from elevenlabs.core
import ApiError
17 from .const
import CONF_MODEL
19 PLATFORMS: list[Platform] = [Platform.TTS]
22 async
def get_model_by_id(client: AsyncElevenLabs, model_id: str) -> Model |
None:
23 """Get ElevenLabs model from their API by the model_id."""
24 models = await client.models.get_all()
25 for maybe_model
in models:
26 if maybe_model.model_id == model_id:
31 @dataclass(kw_only=True, slots=True)
33 """ElevenLabs data type."""
35 client: AsyncElevenLabs
39 type EleventLabsConfigEntry = ConfigEntry[ElevenLabsData]
43 """Set up ElevenLabs text-to-speech from a config entry."""
44 entry.add_update_listener(update_listener)
46 client = AsyncElevenLabs(
47 api_key=entry.data[CONF_API_KEY], httpx_client=httpx_client
49 model_id = entry.options[CONF_MODEL]
52 except ApiError
as err:
55 if model
is None or (
not model.languages):
59 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
65 hass: HomeAssistant, entry: EleventLabsConfigEntry
67 """Unload a config entry."""
68 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
72 hass: HomeAssistant, config_entry: EleventLabsConfigEntry
74 """Handle options update."""
75 await hass.config_entries.async_reload(config_entry.entry_id)
None update_listener(HomeAssistant hass, EleventLabsConfigEntry config_entry)
Model|None get_model_by_id(AsyncElevenLabs client, str model_id)
bool async_setup_entry(HomeAssistant hass, EleventLabsConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, EleventLabsConfigEntry entry)
httpx.AsyncClient get_async_client(HomeAssistant hass, bool verify_ssl=True)