-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_models.py
More file actions
139 lines (115 loc) · 4.15 KB
/
Copy pathsetup_models.py
File metadata and controls
139 lines (115 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"""
Downloads required models into the models/ directory.
Run once before first use: python setup_models.py
- Piper TTS voice model → models/
- openWakeWord ONNX models → openwakeword package resources dir
Whisper models are downloaded automatically by faster-whisper on first run.
Ollama models are pulled via: ollama pull <model-name>
"""
import os
import sys
import urllib.request
from pathlib import Path
MODELS_DIR = Path("models")
# Piper voices are hosted on Hugging Face.
# Format: (filename, hf_path)
PIPER_BASE = "https://huggingface.co/rhasspy/piper-voices/resolve/main"
PIPER_VOICES = {
"en_US-lessac-medium": {
"hf_dir": "en/en_US/lessac/medium",
"files": [
"en_US-lessac-medium.onnx",
"en_US-lessac-medium.onnx.json",
],
},
"en_US-amy-medium": {
"hf_dir": "en/en_US/amy/medium",
"files": [
"en_US-amy-medium.onnx",
"en_US-amy-medium.onnx.json",
],
},
"en_GB-alan-medium": {
"hf_dir": "en/en_GB/alan/medium",
"files": [
"en_GB-alan-medium.onnx",
"en_GB-alan-medium.onnx.json",
],
},
}
DEFAULT_VOICE = "en_US-lessac-medium"
def download_file(url: str, dest: Path):
if dest.exists():
print(f" Already exists: {dest.name}")
return
print(f" Downloading {dest.name} ...", end="", flush=True)
dest.parent.mkdir(parents=True, exist_ok=True)
try:
urllib.request.urlretrieve(url, dest)
print(f" done ({dest.stat().st_size // 1024} KB)")
except Exception as e:
print(f"\n ERROR: {e}")
sys.exit(1)
def download_voice(voice_name: str):
if voice_name not in PIPER_VOICES:
print(f"Unknown voice '{voice_name}'. Available: {list(PIPER_VOICES)}")
sys.exit(1)
info = PIPER_VOICES[voice_name]
print(f"\nDownloading Piper voice: {voice_name}")
for filename in info["files"]:
url = f"{PIPER_BASE}/{info['hf_dir']}/{filename}"
dest = MODELS_DIR / filename
download_file(url, dest)
COMPUTER_WAKE_WORD_URL = (
"https://raw.githubusercontent.com/fwartner/home-assistant-wakewords-collection"
"/main/en/computer/computer_v2.onnx"
)
def download_wake_word_models(model_name: str = "hey_jarvis_v0.1"):
"""Download openWakeWord ONNX models (feature models + the named wake word).
For the 'computer_v2' model, fetches directly from the community collection repo.
"""
# Always download the openWakeWord feature/embedding models (needed by all wake words)
print(f"\nDownloading openWakeWord feature models...")
from openwakeword.utils import download_models
download_models([]) # empty list = feature models only
print(" Feature models OK.")
if model_name == "computer_v2":
print(f"\nDownloading wake word model: computer_v2 (community model)")
download_file(COMPUTER_WAKE_WORD_URL, MODELS_DIR / "computer_v2.onnx")
else:
print(f"\nDownloading openWakeWord model: {model_name}")
download_models([model_name])
def main():
import argparse
parser = argparse.ArgumentParser(description="Download all required models")
parser.add_argument(
"--voice",
default=DEFAULT_VOICE,
choices=list(PIPER_VOICES),
help=f"Piper voice to download (default: {DEFAULT_VOICE})",
)
parser.add_argument(
"--wake-word",
default="computer_v2",
help="openWakeWord model to download (default: computer_v2)",
)
parser.add_argument(
"--list-voices",
action="store_true",
help="List available Piper voices and exit",
)
args = parser.parse_args()
if args.list_voices:
print("Available Piper voices:")
for name in PIPER_VOICES:
print(f" {name}")
return
download_voice(args.voice)
download_wake_word_models(args.wake_word)
print("\nAll models downloaded.")
if args.voice != DEFAULT_VOICE:
print(f"Update config.yaml: tts.model_path: models/{args.voice}.onnx")
if args.wake_word != "computer_v2":
print(f"Update config.yaml: wake_word.model: {args.wake_word}")
if __name__ == "__main__":
main()