mirror of
https://github.com/pstrueb/piper.git
synced 2026-04-17 22:05:30 +00:00
Update voices.json and add --update-voices
This commit is contained in:
@@ -71,6 +71,12 @@ def main() -> None:
|
||||
help="Directory to download voices into (default: first data dir)",
|
||||
)
|
||||
#
|
||||
parser.add_argument(
|
||||
"--update-voices",
|
||||
action="store_true",
|
||||
help="Download latest voices.json during startup",
|
||||
)
|
||||
#
|
||||
parser.add_argument(
|
||||
"--debug", action="store_true", help="Print DEBUG messages to console"
|
||||
)
|
||||
@@ -86,7 +92,7 @@ def main() -> None:
|
||||
model_path = Path(args.model)
|
||||
if not model_path.exists():
|
||||
# Load voice info
|
||||
voices_info = get_voices()
|
||||
voices_info = get_voices(args.download_dir, update_voices=args.update_voices)
|
||||
|
||||
# Resolve aliases for backwards compatibility with old voice names
|
||||
aliases_info: Dict[str, Any] = {}
|
||||
|
||||
@@ -20,9 +20,28 @@ class VoiceNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def get_voices() -> Dict[str, Any]:
|
||||
"""Loads available voices from embedded JSON file."""
|
||||
with open(_DIR / "voices.json", "r", encoding="utf-8") as voices_file:
|
||||
def get_voices(
|
||||
download_dir: Union[str, Path], update_voices: bool = False
|
||||
) -> Dict[str, Any]:
|
||||
"""Loads available voices from downloaded or embedded JSON file."""
|
||||
download_dir = Path(download_dir)
|
||||
voices_download = download_dir / "voices.json"
|
||||
|
||||
if update_voices:
|
||||
# Download latest voices.json
|
||||
voices_url = URL_FORMAT.format(file="voices.json")
|
||||
_LOGGER.debug("Downloading %s to %s", voices_url, voices_download)
|
||||
with urlopen(voices_url) as response, open(
|
||||
voices_download, "wb"
|
||||
) as download_file:
|
||||
shutil.copyfileobj(response, download_file)
|
||||
|
||||
# Prefer downloaded file to embedded
|
||||
voices_embedded = _DIR / "voices.json"
|
||||
voices_path = voices_download if voices_download.exists() else voices_embedded
|
||||
|
||||
_LOGGER.debug("Loading %s", voices_path)
|
||||
with open(voices_path, "r", encoding="utf-8") as voices_file:
|
||||
return json.load(voices_file)
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,7 @@ data_files = [module_dir / "voices.json"]
|
||||
|
||||
setup(
|
||||
name="piper-tts",
|
||||
version="1.1.0",
|
||||
version="1.2.0",
|
||||
description="A fast, local neural text to speech system that sounds great and is optimized for the Raspberry Pi 4.",
|
||||
url="http://github.com/rhasspy/piper",
|
||||
author="Michael Hansen",
|
||||
|
||||
Reference in New Issue
Block a user