From f1238c8a79d19f2f1ae5476174ffd76c61121cb1 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Wed, 18 Nov 2026 20:25:45 +0100 Subject: [PATCH] Update supported regions in microsoft tts (#193322) --- homeassistant/generated/microsoft_tts.py | 36 ++++++++++++++++++++++++ script/microsoft_tts.py | 31 ++++++++++++++------ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/homeassistant/generated/microsoft_tts.py b/homeassistant/generated/microsoft_tts.py index 69c425dec398..c4c8e149d910 100644 --- a/homeassistant/generated/microsoft_tts.py +++ b/homeassistant/generated/microsoft_tts.py @@ -159,3 +159,39 @@ SUPPORTED_LANGUAGES = { "zh-tw", "zu-za", } + +SUPPORTED_REGIONS = { + "australiaeast", + "brazilsouth", + "canadacentral", + "canadaeast", + "centralindia", + "centralus", + "eastasia", + "eastus", + "eastus2", + "francecentral", + "germanywestcentral", + "italynorth", + "japaneast", + "japanwest", + "koreacentral", + "northcentralus", + "northeurope", + "norwayeast", + "qatarcentral", + "southafricanorth", + "southcentralus", + "southeastasia", + "swedencentral", + "switzerlandnorth", + "switzerlandwest", + "uaenorth", + "uksouth", + "ukwest", + "westcentralus", + "westeurope", + "westus", + "westus2", + "westus3", +} diff --git a/script/microsoft_tts.py b/script/microsoft_tts.py index 50be33ac34cf..aa54da1f2f6c 100644 --- a/script/microsoft_tts.py +++ b/script/microsoft_tts.py @@ -1,4 +1,4 @@ -"""Helper script to update supported languages for Microsoft text-to-speech (TTS).""" +"""Helper script to update supported languages and regions for Microsoft text-to-speech (TTS).""" from pathlib import Path @@ -6,19 +6,32 @@ from hassfest.serializer import format_python_namespace from lxml import html import requests -URL = "https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/language-support" -XPATH_QUERY = "//section[@data-tab='tts']/table[1]/tbody/tr/td[1]/code/text()" +LANGUAGES_URL = "https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support" +LANGUAGES_XPATH_QUERY = "//section[@data-tab='tts']/table[1]/tbody/tr/td[1]/code/text()" + +REGIONS_URL = ( + "https://learn.microsoft.com/en-us/azure/ai-services/speech-service/regions" +) +REGIONS_XPATH_QUERY = ( + "//section[@data-tab='geographies']/table[1]/tbody/tr/td[3]/code/text()" +) + + +def query_documentation(url: str, xpath_query: str) -> set[str]: + """Return the lowercase results of an XPath query on a documentation page.""" + req = requests.get(url) + req.raise_for_status() + tree = html.fromstring(req.content) + return {s.lower() for s in tree.xpath(xpath_query)} -req = requests.get(URL) -req.raise_for_status() -tree = html.fromstring(req.content) -supported_languages_raw = tree.xpath(XPATH_QUERY) -supported_languages = {s.lower() for s in supported_languages_raw} Path("homeassistant/generated/microsoft_tts.py").write_text( format_python_namespace( { - "SUPPORTED_LANGUAGES": supported_languages, + "SUPPORTED_LANGUAGES": query_documentation( + LANGUAGES_URL, LANGUAGES_XPATH_QUERY + ), + "SUPPORTED_REGIONS": query_documentation(REGIONS_URL, REGIONS_XPATH_QUERY), }, generator="script.microsoft_tts", )