Scrape Microsoft TTS supported languages (#91988)
* Update Microsoft TTS supported languages `script.microsoft_tts` scrapes Microsoft Azure documentation for the list of supported languages and saves them to `homeassistant.generated.microsoft_tts` for use in the component. This adds support for more TTS languages, like fa-ir (Persian). * Improve xpath query for Microsoft TTS languages * Remove asserts for Microsoft TTS languages * Add more tests for Microsoft TTS languages
This commit is contained in:
parent
6e8472b90f
commit
663f66a2b2
4 changed files with 265 additions and 76 deletions
25
script/microsoft_tts.py
Normal file
25
script/microsoft_tts.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
"""Helper script to update supported languages for Microsoft Text-to-Speech (TTS)."""
|
||||
from pathlib import Path
|
||||
|
||||
from lxml import html
|
||||
import requests
|
||||
|
||||
from .hassfest.serializer import format_python_namespace
|
||||
|
||||
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()"
|
||||
|
||||
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,
|
||||
},
|
||||
generator="script.microsoft_tts",
|
||||
)
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue