Skip to content

Commit

Permalink
Add error handling for failed voice parsing (#59)
Browse files Browse the repository at this point in the history
The updates in this pull request include:

- Updating the launch.json file to correct the debugging configuration.

- Updating the import statements in __main__.py to use the correct module names.

- Adding error handling for failed voice parsing in download.py. This ensures that any errors encountered during voice parsing are logged and the program continues running.

These changes improve the overall functionality and robustness of the voice downloading utility.
  • Loading branch information
hugobloem authored May 15, 2024
2 parents 236e4da + 7b2ac4d commit 428d9bd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
11 changes: 6 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions wyoming_microsoft_tts/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
38 changes: 22 additions & 16 deletions wyoming_microsoft_tts/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utility for downloading Microsoft voices."""

import json
import logging
from pathlib import Path
Expand Down Expand Up @@ -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


Expand All @@ -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:
Expand Down

0 comments on commit 428d9bd

Please sign in to comment.