Update supported regions in microsoft tts (#193322)

This commit is contained in:
Michael
2026-11-18 20:25:45 +01:00
committed by GitHub
parent 8b357edbae
commit f1238c8a79
2 changed files with 58 additions and 9 deletions
+36
View File
@@ -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",
}
+22 -9
View File
@@ -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",
)