1 """Handle legacy speech-to-text platforms."""
3 from __future__
import annotations
5 from abc
import ABC, abstractmethod
6 from collections.abc
import AsyncIterable, Coroutine
16 async_prepare_setup_platform,
29 from .models
import SpeechMetadata, SpeechResult
31 _LOGGER = logging.getLogger(__name__)
36 """Return the domain of the default provider."""
37 providers = hass.data[DATA_PROVIDERS]
38 return next(iter(providers),
None)
43 hass: HomeAssistant, domain: str |
None =
None
45 """Return provider."""
46 providers = hass.data[DATA_PROVIDERS]
48 return providers.get(domain)
51 return providers[provider]
if provider
is not None else None
56 hass: HomeAssistant, config: ConfigType
57 ) -> list[Coroutine[Any, Any,
None]]:
58 """Set up legacy speech-to-text providers."""
59 providers = hass.data[DATA_PROVIDERS] = {}
63 p_config: ConfigType |
None =
None,
64 discovery_info: DiscoveryInfoType |
None =
None,
66 """Set up an STT platform."""
72 _LOGGER.error(
"Unknown speech-to-text platform specified")
79 group=
str(id(p_config)),
80 phase=SetupPhases.PLATFORM_SETUP,
82 provider = await platform.async_get_engine(
83 hass, p_config, discovery_info
86 provider.name = p_type
89 providers[provider.name] = provider
91 _LOGGER.exception(
"Error setting up platform: %s", p_type)
95 async
def async_platform_discovered(
96 platform: str, info: DiscoveryInfoType |
None
98 """Handle for discovered platform."""
101 discovery.async_listen_platform(hass, DOMAIN, async_platform_discovered)
111 """Represent a single STT provider."""
113 hass: HomeAssistant |
None =
None
114 name: str |
None =
None
119 """Return a list of supported languages."""
124 """Return a list of supported formats."""
129 """Return a list of supported codecs."""
134 """Return a list of supported bit rates."""
139 """Return a list of supported sample rates."""
144 """Return a list of supported channels."""
148 self, metadata: SpeechMetadata, stream: AsyncIterable[bytes]
150 """Process an audio stream to STT service.
152 Only streaming of content are allow!
157 """Check if given metadata supported by this provider."""
bool check_metadata(self, SpeechMetadata metadata)
list[AudioBitRates] supported_bit_rates(self)
list[AudioSampleRates] supported_sample_rates(self)
list[AudioChannels] supported_channels(self)
list[AudioFormats] supported_formats(self)
list[AudioCodecs] supported_codecs(self)
SpeechResult async_process_audio_stream(self, SpeechMetadata metadata, AsyncIterable[bytes] stream)
list[str] supported_languages(self)
None async_setup_platform(HomeAssistant hass, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None discovery_info=None)
list[Coroutine[Any, Any, None]] async_setup_legacy(HomeAssistant hass, ConfigType config)
str|None async_default_provider(HomeAssistant hass)
Provider|None async_get_provider(HomeAssistant hass, str|None domain=None)
Iterable[tuple[str|None, ConfigType]] config_per_platform(ConfigType config, str domain)
ModuleType|None async_prepare_setup_platform(core.HomeAssistant hass, ConfigType hass_config, str domain, str platform_name)
Generator[None] async_start_setup(core.HomeAssistant hass, str integration, SetupPhases phase, str|None group=None)