-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-dev.sh
More file actions
196 lines (172 loc) · 7.71 KB
/
run-dev.sh
File metadata and controls
196 lines (172 loc) · 7.71 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/usr/bin/env bash
# =============================================================================
# ReadToMe-TTS - Developer Setup & Launch
# =============================================================================
#
# Complete developer setup script. Creates a virtual environment, installs all
# dependencies (including build tools), downloads the 4 bundled voice models,
# and launches ReadToMe in debug mode.
#
# After running this script once, you can:
# - Run the app: .venv/bin/python -m readtome --debug
# - Build installer: ./build-linux.sh (cross-compile via Wine)
# - Download all 20+ ./download-voices.sh
# US English voices
#
# Usage:
# chmod +x run-dev.sh
# ./run-dev.sh # Full setup + launch in debug mode
# ./run-dev.sh --no-launch # Setup only, don't launch the app
#
set -euo pipefail
PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
VENV_DIR="${PROJECT_DIR}/.venv"
MODELS_DIR="${PROJECT_DIR}/models"
# Required Python version — 3.14+ has known NumPy compatibility issues that
# cause the built executable to crash on target systems.
REQUIRED_PY_MAJOR=3
REQUIRED_PY_MINOR=12
REQUIRED_PY="${REQUIRED_PY_MAJOR}.${REQUIRED_PY_MINOR}"
# The 4 bundled voices (medium quality)
BUNDLED_VOICES=("amy" "kristin" "kusal" "ryan")
QUALITY="medium"
BASE_URL="https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US"
# ── Colors ───────────────────────────────────────────────────────────────
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
CYAN='\033[0;36m'
GRAY='\033[0;90m'
WHITE='\033[1;37m'
NC='\033[0m'
# ── Parse arguments ──────────────────────────────────────────────────────
NO_LAUNCH=false
for arg in "$@"; do
case "$arg" in
--no-launch) NO_LAUNCH=true ;;
esac
done
STEP_COUNT=4
if $NO_LAUNCH; then
STEP_COUNT=3
fi
echo -e "${CYAN}============================================${NC}"
echo -e "${CYAN} ReadToMe-TTS - Developer Setup${NC}"
echo -e "${CYAN}============================================${NC}"
echo ""
# ── Step 1: Create virtual environment with correct Python version ────────
step=1
if [ ! -f "${VENV_DIR}/bin/python" ]; then
echo -e "${YELLOW}[${step}/${STEP_COUNT}] Creating virtual environment (Python ${REQUIRED_PY})...${NC}"
# Try python3.12, then python3, then python
PYTHON_CMD=""
for cmd in "python${REQUIRED_PY}" "python${REQUIRED_PY_MAJOR}" "python3" "python"; do
if command -v "$cmd" &>/dev/null; then
ver=$("$cmd" --version 2>&1 | grep -oP '\d+\.\d+')
if [ "$ver" = "$REQUIRED_PY" ]; then
PYTHON_CMD="$cmd"
break
fi
fi
done
if [ -z "$PYTHON_CMD" ]; then
echo -e "${RED}ERROR: Python ${REQUIRED_PY} not found!${NC}"
echo -e "${RED} Install Python ${REQUIRED_PY} and ensure it's on your PATH.${NC}"
echo -e "${RED} On Ubuntu/Debian: sudo apt install python${REQUIRED_PY} python${REQUIRED_PY}-venv${NC}"
exit 1
fi
"$PYTHON_CMD" -m venv "$VENV_DIR"
echo -e "${GREEN} Created: ${VENV_DIR}${NC}"
else
echo -e "${GREEN}[${step}/${STEP_COUNT}] Virtual environment exists${NC}"
fi
# Verify the venv Python version
venv_ver=$("${VENV_DIR}/bin/python" --version 2>&1 | grep -oP '\d+\.\d+')
if [ "$venv_ver" != "$REQUIRED_PY" ]; then
echo -e "${RED}WARNING: Virtual environment has Python ${venv_ver}, but ${REQUIRED_PY} is required.${NC}"
echo -e "${RED} Delete .venv/ and re-run this script to recreate with the correct version.${NC}"
exit 1
fi
echo -e "${GREEN} Python version: $(${VENV_DIR}/bin/python --version 2>&1)${NC}"
# ── Step 2: Install all dependencies (including dev/build tools) ──────────
step=2
echo -e "${YELLOW}[${step}/${STEP_COUNT}] Installing dependencies...${NC}"
"${VENV_DIR}/bin/pip" install -e ".[dev]" --quiet 2>/dev/null || {
echo -e "${YELLOW} Retrying with verbose output...${NC}"
"${VENV_DIR}/bin/pip" install -e ".[dev]"
}
echo -e "${GREEN} All packages installed (piper-tts, sounddevice, pyinstaller, etc.)${NC}"
# ── Step 3: Download the 4 bundled voice models ──────────────────────────
step=3
mkdir -p "$MODELS_DIR"
all_present=true
for voice in "${BUNDLED_VOICES[@]}"; do
filename="en_US-${voice}-${QUALITY}"
if [ ! -f "${MODELS_DIR}/${filename}.onnx" ] || [ ! -f "${MODELS_DIR}/${filename}.onnx.json" ]; then
all_present=false
break
fi
done
if $all_present; then
voice_list=$(IFS=", "; echo "${BUNDLED_VOICES[*]}")
echo -e "${GREEN}[${step}/${STEP_COUNT}] All 4 bundled voices present (${voice_list})${NC}"
else
echo -e "${YELLOW}[${step}/${STEP_COUNT}] Downloading bundled voice models...${NC}"
for voice in "${BUNDLED_VOICES[@]}"; do
filename="en_US-${voice}-${QUALITY}"
onnx_file="${filename}.onnx"
json_file="${filename}.onnx.json"
onnx_path="${MODELS_DIR}/${onnx_file}"
json_path="${MODELS_DIR}/${json_file}"
if [ -f "$onnx_path" ] && [ -f "$json_path" ]; then
echo -e " ${GRAY}[SKIP] ${filename} (already downloaded)${NC}"
continue
fi
voice_url="${BASE_URL}/${voice}/${QUALITY}"
echo -ne " ${YELLOW}[DOWN] ${filename} ...${NC}"
# Download JSON config
if [ ! -f "$json_path" ]; then
if ! wget -q -O "$json_path" "${voice_url}/${json_file}" 2>/dev/null && \
! curl -sL -o "$json_path" "${voice_url}/${json_file}" 2>/dev/null; then
echo -e "\r ${RED}[FAIL] ${filename} - download error${NC} "
rm -f "$onnx_path" "$json_path"
continue
fi
fi
# Download ONNX model
if [ ! -f "$onnx_path" ]; then
if ! wget -q --show-progress -O "$onnx_path" "${voice_url}/${onnx_file}" 2>/dev/null && \
! curl -L --progress-bar -o "$onnx_path" "${voice_url}/${onnx_file}" 2>/dev/null; then
echo -e "\r ${RED}[FAIL] ${filename} - download error${NC} "
rm -f "$onnx_path" "$json_path"
continue
fi
fi
echo -e "\r ${GREEN}[ OK ] ${filename}${NC} "
done
fi
# ── Summary ──────────────────────────────────────────────────────────────
echo ""
echo -e "${CYAN}============================================${NC}"
echo -e "${CYAN} Setup Complete${NC}"
echo -e "${CYAN}============================================${NC}"
echo ""
voice_count=$(find "$MODELS_DIR" -name "*.onnx" 2>/dev/null | wc -l)
echo -e " ${WHITE}Voice models: ${voice_count} found in models/${NC}"
echo -e " ${WHITE}Virtual env: ${VENV_DIR}${NC}"
echo ""
echo -e " ${WHITE}Run app: .venv/bin/python -m readtome --debug${NC}"
echo -e " ${WHITE}Cross-compile: ./build-linux.sh${NC}"
echo -e " ${WHITE}More voices: ./download-voices.sh${NC}"
echo ""
# ── Step 4: Launch in debug mode ──────────────────────────────────────────
if ! $NO_LAUNCH; then
step=4
echo -e "${YELLOW}[${step}/${STEP_COUNT}] Launching ReadToMe in debug mode...${NC}"
echo ""
echo -e " ${GRAY}Press Ctrl+C to stop.${NC}"
echo ""
"${VENV_DIR}/bin/python" -m readtome --debug
else
echo -e " ${GRAY}Skipping launch (--no-launch).${NC}"
fi