From ffbfa282f7986a26600cc531f02191e4dbfa48a9 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 15 May 2024 10:26:34 +0100 Subject: [PATCH 1/3] Update launch.json for debugging configuration --- .vscode/launch.json | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index efdcefc..b366ffa 100755 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -3,25 +3,26 @@ "configurations": [ { "name": "Debug __main__", - "type": "python", + "type": "debugpy", "request": "launch", - "program": "${workspaceFolder}/wyoming-microsoft-tts/__main__.py", + "program": "${workspaceFolder}/wyoming_microsoft_tts/__main__.py", "console": "integratedTerminal", "env": { "PYTHONPATH": "${workspaceFolder}", }, "args": [ - "--microsoft", "./microsoft_tts.py", + // "--microsoft", "./microsoft_tts.py", "--voice", "en-GB-SoniaNeural", "--download-dir", "./temp/", "--service-region", "uksouth", "--debug", - "--uri", "tcp://0.0.0.0:10200" + "--uri", "tcp://0.0.0.0:10200", + "--update-voices" ] }, { "name": "Debug microsoft_tts.py", - "type": "python", + "type": "debugpy", "request": "launch", "program": "${workspaceFolder}/microsoft_tts.py", "console": "integratedTerminal", From 526309524aa2737661408583fd52477b8d507e27 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 15 May 2024 10:26:50 +0100 Subject: [PATCH 2/3] chore: update import statements in __main__.py The import statements in __main__.py have been updated to use the correct module names. --- wyoming_microsoft_tts/__main__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/wyoming_microsoft_tts/__main__.py b/wyoming_microsoft_tts/__main__.py index f2b31ac..7b818a4 100755 --- a/wyoming_microsoft_tts/__main__.py +++ b/wyoming_microsoft_tts/__main__.py @@ -8,9 +8,9 @@ from wyoming.info import Attribution, Info, TtsProgram, TtsVoice from wyoming.server import AsyncServer -from .download import get_voices -from .handler import MicrosoftEventHandler -from .version import __version__ +from wyoming_microsoft_tts.download import get_voices +from wyoming_microsoft_tts.handler import MicrosoftEventHandler +from wyoming_microsoft_tts.version import __version__ _LOGGER = logging.getLogger(__name__) From 7b2ac4d003358f8372b598c6357afe6018ba2fd7 Mon Sep 17 00:00:00 2001 From: Hugo Date: Wed, 15 May 2024 10:27:13 +0100 Subject: [PATCH 3/3] feat: Add error handling for failed voice parsing The code changes in `download.py` add error handling for failed voice parsing. This ensures that if there is an error parsing a voice, it will be logged and the program will continue running. This change improves the robustness of the voice downloading utility. --- wyoming_microsoft_tts/download.py | 38 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/wyoming_microsoft_tts/download.py b/wyoming_microsoft_tts/download.py index f9c4971..fdfb75e 100755 --- a/wyoming_microsoft_tts/download.py +++ b/wyoming_microsoft_tts/download.py @@ -1,4 +1,5 @@ """Utility for downloading Microsoft voices.""" + import json import logging from pathlib import Path @@ -37,22 +38,26 @@ def transform_voices_files(response): voices = {} for entry in json_response: country = countries.get(alpha_2=entry["Locale"].split("-")[1]) - voices[entry["ShortName"]] = { - "key": entry["ShortName"], - "name": entry["LocalName"], - "language": { - "code": entry["Locale"], - "family": entry["Locale"].split("-")[0], - "region": country.alpha_2, - "name_native": entry["LocaleName"], - "name_english": entry["LocaleName"], - "country_english": country.name, - }, - "quality": entry["VoiceType"], - "num_speakers": 1, - "speaker_id_map": {}, - "aliases": [], - } + try: + voices[entry["ShortName"]] = { + "key": entry["ShortName"], + "name": entry["LocalName"], + "language": { + "code": entry["Locale"], + "family": entry["Locale"].split("-")[0], + "region": country.alpha_2, + "name_native": entry["LocaleName"], + "name_english": entry["LocaleName"], + "country_english": country.name, + }, + "quality": entry["VoiceType"], + "num_speakers": 1, + "speaker_id_map": {}, + "aliases": [], + } + except Exception as e: + _LOGGER.error("Failed to parse voice %s", entry["ShortName"]) + _LOGGER.debug("%s: %s", entry["ShortName"], e) return voices @@ -64,6 +69,7 @@ def get_voices( ) -> dict[str, Any]: """Load available voices from downloaded or embedded JSON file.""" download_dir = Path(download_dir) + download_dir.mkdir(parents=True, exist_ok=True) voices_download = download_dir / "voices.json" if update_voices: