tts.say to use media source URLs (#70382)

This commit is contained in:
Paulus Schoutsen 2022-04-26 13:49:32 -07:00 committed by GitHub
parent e387e6d332
commit 9303e35a7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 215 additions and 101 deletions

View file

@ -2,7 +2,7 @@
from __future__ import annotations
import mimetypes
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any
from yarl import URL
@ -46,17 +46,19 @@ class TTSMediaSource(MediaSource):
raise Unresolvable("No message specified.")
options = dict(parsed.query)
kwargs = {
kwargs: dict[str, Any] = {
"engine": parsed.name,
"message": options.pop("message"),
"language": options.pop("language", None),
"options": options,
}
if "cache" in options:
kwargs["cache"] = options.pop("cache") == "true"
manager: SpeechManager = self.hass.data[DOMAIN]
try:
url = await manager.async_get_url_path(**kwargs) # type: ignore[arg-type]
url = await manager.async_get_url_path(**kwargs)
except HomeAssistantError as err:
raise Unresolvable(str(err)) from err