-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdev.bat
More file actions
542 lines (471 loc) · 15.2 KB
/
Copy pathdev.bat
File metadata and controls
542 lines (471 loc) · 15.2 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
@echo off
setlocal
chcp 65001 >nul
title webUTAU - Dev Launcher
REM ========================================
REM Paths and defaults
REM ========================================
set "ROOT=%~dp0"
set "SELF=%~f0"
set "PROJECT=%ROOT%server\DiffSingerApi\DiffSingerApi.csproj"
set "OPENUTAU_CORE=%ROOT%OpenUtau\OpenUtau.Core\OpenUtau.Core.csproj"
set "BACKEND_RUNTIME_EXE=%ROOT%server\DiffSingerApi.exe"
set "BACKEND_RUNTIME_DLL=%ROOT%server\DiffSingerApi.dll"
set "BACKEND_RUNTIME_CONFIG=%ROOT%server\DiffSingerApi.runtimeconfig.json"
set "BACKEND_DEPS=%ROOT%server\DiffSingerApi.deps.json"
set "SEEDVC_APP=%ROOT%scripts\seedvc_service\app.py"
set "SEEDVC_ROOT=%ROOT%external\seed-vc"
set "SEEDVC_PYTHON=%SEEDVC_ROOT%\.venv\Scripts\python.exe"
set "DEFAULT_VOICEBANKS_DIR=%ROOT%server\voicebanks"
if defined MELODY_VOICEBANKS_DIR (
set "VOICEBANKS_DIR=%MELODY_VOICEBANKS_DIR%"
) else (
set "VOICEBANKS_DIR=%DEFAULT_VOICEBANKS_DIR%"
)
set "BACKEND_HEALTH_URL=http://127.0.0.1:38510/api/voicebanks"
set "SEEDVC_HEALTH_URL=http://127.0.0.1:38511/health"
if not defined MELODY_FRONTEND_PORT set "MELODY_FRONTEND_PORT=3000"
set "FRONTEND_PORT=%MELODY_FRONTEND_PORT%"
if not defined MELODY_BACKEND_START_TIMEOUT set "MELODY_BACKEND_START_TIMEOUT=180"
if not defined MELODY_SEEDVC_START_TIMEOUT set "MELODY_SEEDVC_START_TIMEOUT=60"
if not defined MELODY_FRONTEND_START_TIMEOUT set "MELODY_FRONTEND_START_TIMEOUT=90"
if not defined MELODY_TUNNEL set "MELODY_TUNNEL=1"
if not defined MELODY_TUNNEL_START_TIMEOUT set "MELODY_TUNNEL_START_TIMEOUT=120"
set "TUNNEL_SCRIPT=%ROOT%scripts\start-tunnel.mjs"
REM ========================================
REM Command dispatch
REM ========================================
set "COMMAND=%~1"
if "%COMMAND%"=="" set "COMMAND=all"
if /I "%COMMAND%"=="all" goto cmd_all
if /I "%COMMAND%"=="full" goto cmd_full
if /I "%COMMAND%"=="check" goto cmd_check
if /I "%COMMAND%"=="backend" goto cmd_backend
if /I "%COMMAND%"=="backend-runtime" goto cmd_backend_runtime
if /I "%COMMAND%"=="backend-source" goto cmd_backend_source
if /I "%COMMAND%"=="seedvc" goto cmd_seedvc
if /I "%COMMAND%"=="frontend" goto cmd_frontend
if /I "%COMMAND%"=="help" goto cmd_help
if /I "%COMMAND%"=="-h" goto cmd_help
if /I "%COMMAND%"=="--help" goto cmd_help
echo [error] unsupported command: %COMMAND%
goto cmd_help
REM ========================================
REM help
REM ========================================
:cmd_help
echo.
echo Usage:
echo dev.bat Backend + Frontend
echo dev.bat all same; also starts SeedVC if available
echo dev.bat full force Backend + SeedVC + Frontend
echo dev.bat check check dev environment
echo dev.bat backend auto-pick runtime or source
echo dev.bat backend-runtime published runtime only
echo dev.bat backend-source source project only
echo dev.bat seedvc SeedVC service only
echo dev.bat frontend [port] frontend only, default 3000
echo dev.bat help show this help
echo.
echo Environment variables:
echo MELODY_VOICEBANKS_DIR voicebank dir (default .\server\voicebanks)
echo MELODY_FRONTEND_PORT frontend port (default 3000)
echo MELODY_ONNX_PROVIDER ONNX provider: Cuda (default) or DirectML
echo MELODY_ONNX_RUNNER runtime override: CUDA, DirectML, or CPU
echo MELODY_BACKEND_START_TIMEOUT backend health timeout seconds (default 180)
echo MELODY_SEEDVC_START_TIMEOUT seedvc health timeout seconds (default 60)
echo MELODY_FRONTEND_START_TIMEOUT frontend health timeout seconds (default 90)
echo MELODY_TUNNEL auto-start cloudflare quick tunnel, default 1 (set 0 to disable)
echo MELODY_TUNNEL_START_TIMEOUT tunnel URL wait seconds (default 120)
echo.
goto end_ok
REM ========================================
REM Utility functions
REM ========================================
:port_is_listening
netstat -ano 2>nul | findstr "LISTENING" | findstr ":%~1 " >nul 2>nul
exit /b %ERRORLEVEL%
:http_is_ready
curl -fsS "%~1" >nul 2>nul
exit /b %ERRORLEVEL%
:wait_for_http
set "_wfh_name=%~1"
set "_wfh_url=%~2"
set "_wfh_max=%~3"
set "_wfh_i=0"
:wait_for_http_loop
if %_wfh_i% geq %_wfh_max% (
echo [error] %_wfh_name% failed to start within %_wfh_max%s: %_wfh_url%
exit /b 1
)
curl -fsS "%_wfh_url%" >nul 2>nul
if not errorlevel 1 exit /b 0
timeout /t 1 /nobreak >nul
set /a "_wfh_i+=1"
goto wait_for_http_loop
:pick_frontend_port
for /l %%P in (%~1,1,65535) do (
call :port_is_listening %%P
if errorlevel 1 (
set "FRONTEND_PORT=%%P"
exit /b 0
)
echo [hint] port %%P in use, trying next...
)
echo [error] no available frontend port found starting from %~1
exit /b 1
:start_tunnel_if_enabled
REM args: %1 = port
if "%MELODY_TUNNEL%"=="0" exit /b 0
if not exist "%TUNNEL_SCRIPT%" (
echo [hint] tunnel script not found, skipping cloudflare tunnel
exit /b 0
)
where node >nul 2>nul
if errorlevel 1 (
echo [hint] node not found, skipping cloudflare tunnel; install Node.js to enable
exit /b 0
)
echo [start] tunnel
echo [hint] a separate "WebUTAU Tunnel" window will open
echo [hint] download progress and public URL also appear in the "share link" panel inside the app
echo [hint] first run downloads ~30 MB; backend/frontend keep running even if tunnel preparation fails
echo [hint] set MELODY_TUNNEL=0 to disable on next launch
start "WebUTAU Tunnel" /d "%ROOT%" cmd /k "node ""%TUNNEL_SCRIPT%"" --port %~1"
exit /b 0
:warn_if_no_voicebanks
if not exist "%VOICEBANKS_DIR%" (
echo [warn] voicebank dir not found: "%VOICEBANKS_DIR%"
echo [hint] /api/voicebanks may return empty after backend starts.
exit /b 0
)
set "_has_vb="
for /f %%I in ('dir /b /ad "%VOICEBANKS_DIR%" 2^>nul') do (
set "_has_vb=1"
goto _warn_vb_done
)
:_warn_vb_done
if not defined _has_vb (
echo [warn] voicebank dir is empty: "%VOICEBANKS_DIR%"
echo [hint] /api/voicebanks may return empty after backend starts.
)
exit /b 0
:resolve_dotnet
where dotnet >nul 2>nul
if not errorlevel 1 exit /b 0
echo [error] dotnet not found in PATH. Please install .NET 8 SDK.
exit /b 1
:backend_runtime_is_available
if not exist "%BACKEND_RUNTIME_CONFIG%" exit /b 1
if not exist "%BACKEND_DEPS%" exit /b 1
if exist "%BACKEND_RUNTIME_EXE%" exit /b 0
if exist "%BACKEND_RUNTIME_DLL%" exit /b 0
exit /b 1
:seedvc_is_available
if not exist "%SEEDVC_ROOT%" exit /b 1
if not exist "%SEEDVC_APP%" exit /b 1
if not exist "%SEEDVC_PYTHON%" exit /b 1
exit /b 0
:pick_backend_mode
call :backend_runtime_is_available
if not errorlevel 1 (
set "RESOLVED_BACKEND_MODE=runtime"
exit /b 0
)
if exist "%PROJECT%" if exist "%OPENUTAU_CORE%" (
set "RESOLVED_BACKEND_MODE=source"
exit /b 0
)
set "RESOLVED_BACKEND_MODE=source"
exit /b 0
REM ========================================
REM Prerequisites
REM ========================================
:ensure_backend_runtime_prereqs
call :backend_runtime_is_available
if errorlevel 1 (
echo [error] published runtime files not found.
echo [hint] use "dev.bat backend-source" or run dotnet publish first.
exit /b 1
)
call :resolve_dotnet
if not errorlevel 1 exit /b 0
REM dotnet missing - self-contained exe does not need it
if exist "%BACKEND_RUNTIME_EXE%" exit /b 0
exit /b 1
:ensure_backend_source_prereqs
call :resolve_dotnet
if errorlevel 1 exit /b 1
if not exist "%PROJECT%" (
echo [error] source project not found: "%PROJECT%"
exit /b 1
)
if not exist "%OPENUTAU_CORE%" (
echo [error] OpenUtau source not found: "%OPENUTAU_CORE%"
echo [hint] place OpenUtau under repo root OpenUtau\
exit /b 1
)
exit /b 0
:ensure_seedvc_prereqs
if not exist "%SEEDVC_ROOT%" (
echo [error] SeedVC source dir not found: "%SEEDVC_ROOT%"
exit /b 1
)
if not exist "%SEEDVC_APP%" (
echo [error] SeedVC entry not found: "%SEEDVC_APP%"
exit /b 1
)
if not exist "%SEEDVC_PYTHON%" (
echo [error] SeedVC Python env not found: "%SEEDVC_PYTHON%"
echo [hint] install external\seed-vc\.venv dependencies first.
exit /b 1
)
exit /b 0
:ensure_frontend_prereqs
where npm >nul 2>nul
if errorlevel 1 (
echo [error] npm not found. Please install Node.js.
exit /b 1
)
if not exist "%ROOT%node_modules" (
echo [error] node_modules not found. Run npm install first.
exit /b 1
)
exit /b 0
REM ========================================
REM check
REM ========================================
:cmd_check
echo [check] validating dev environment...
echo.
set "_check_ok=1"
where dotnet >nul 2>nul
if errorlevel 1 (
echo dotnet: not installed
set "_check_ok="
) else (
for /f "delims=" %%V in ('dotnet --version 2^>nul') do echo dotnet: %%V
)
where npm >nul 2>nul
if errorlevel 1 (
echo npm: not installed
set "_check_ok="
) else (
for /f "delims=" %%V in ('npm --version 2^>nul') do echo npm: %%V
)
if exist "%ROOT%node_modules" (
echo modules: ok
) else (
echo modules: node_modules missing
set "_check_ok="
)
call :warn_if_no_voicebanks
call :backend_runtime_is_available
if not errorlevel 1 (
echo backend: published runtime available
echo mode: runtime
) else (
if exist "%PROJECT%" if exist "%OPENUTAU_CORE%" (
echo backend: runtime not found, source project available
echo mode: source
) else (
echo backend: neither runtime nor source available
set "_check_ok="
)
)
call :seedvc_is_available
if not errorlevel 1 (
echo seedvc: ready (optional)
) else (
echo seedvc: not ready (optional, won't block startup)
)
echo.
if defined _check_ok (
echo [pass] dev environment is ready.
) else (
echo [fail] missing dependencies, see hints above.
)
goto end_ok
REM ========================================
REM backend (auto)
REM ========================================
:cmd_backend
call :pick_backend_mode
call :warn_if_no_voicebanks
echo [mode] backend using %RESOLVED_BACKEND_MODE%
if "%RESOLVED_BACKEND_MODE%"=="runtime" goto _run_backend_runtime
goto _run_backend_source
REM ========================================
REM backend-runtime
REM ========================================
:cmd_backend_runtime
call :ensure_backend_runtime_prereqs
if errorlevel 1 goto end_fail
call :warn_if_no_voicebanks
goto _run_backend_runtime
:_run_backend_runtime
if exist "%BACKEND_RUNTIME_EXE%" (
echo [start] backend (exe runtime)
cd /d "%ROOT%server"
"%BACKEND_RUNTIME_EXE%"
) else (
echo [start] backend (dll runtime)
cd /d "%ROOT%server"
dotnet "%BACKEND_RUNTIME_DLL%"
)
goto end_ok
REM ========================================
REM backend-source
REM ========================================
:cmd_backend_source
call :ensure_backend_source_prereqs
if errorlevel 1 goto end_fail
call :warn_if_no_voicebanks
goto _run_backend_source
:_run_backend_source
echo [start] backend (source)
echo [info] voicebanks: "%VOICEBANKS_DIR%"
if not defined MELODY_ONNX_PROVIDER set "MELODY_ONNX_PROVIDER=Cuda"
echo [info] ONNX provider: %MELODY_ONNX_PROVIDER%
cd /d "%ROOT%server\DiffSingerApi"
dotnet run -p:OnnxProvider=%MELODY_ONNX_PROVIDER% -- --VoicebanksPath="%VOICEBANKS_DIR%"
goto end_ok
REM ========================================
REM seedvc
REM ========================================
:cmd_seedvc
call :ensure_seedvc_prereqs
if errorlevel 1 goto end_fail
echo [start] SeedVC service
cd /d "%ROOT%scripts\seedvc_service"
"%SEEDVC_PYTHON%" app.py
goto end_ok
REM ========================================
REM frontend
REM ========================================
:cmd_frontend
call :ensure_frontend_prereqs
if errorlevel 1 goto end_fail
set "_fe_port=%~2"
if "%_fe_port%"=="" set "_fe_port=%FRONTEND_PORT%"
echo [start] frontend on port %_fe_port%
cd /d "%ROOT%"
npm run dev -- --host 127.0.0.1 --port %_fe_port%
goto end_ok
REM ========================================
REM all / full
REM ========================================
:cmd_all
set "_seedvc_mode=auto"
goto _run_all
:cmd_full
set "_seedvc_mode=always"
goto _run_all
:_run_all
call :pick_backend_mode
if "%RESOLVED_BACKEND_MODE%"=="runtime" goto _all_check_runtime
goto _all_check_source
:_all_check_runtime
call :ensure_backend_runtime_prereqs
if errorlevel 1 goto end_fail
goto _all_backend_prereqs_ok
:_all_check_source
call :ensure_backend_source_prereqs
if errorlevel 1 goto end_fail
:_all_backend_prereqs_ok
call :ensure_frontend_prereqs
if errorlevel 1 goto end_fail
call :warn_if_no_voicebanks
set "_start_seedvc=0"
if "%_seedvc_mode%"=="always" goto _all_seedvc_always
if "%_seedvc_mode%"=="auto" goto _all_seedvc_auto
goto _all_seedvc_decided
:_all_seedvc_always
call :ensure_seedvc_prereqs
if errorlevel 1 goto end_fail
set "_start_seedvc=1"
goto _all_seedvc_decided
:_all_seedvc_auto
call :seedvc_is_available
if not errorlevel 1 set "_start_seedvc=1"
goto _all_seedvc_decided
:_all_seedvc_decided
call :pick_frontend_port %FRONTEND_PORT%
REM ---- launch backend ----
call :http_is_ready "%BACKEND_HEALTH_URL%"
if not errorlevel 1 (
echo [reuse] backend already running: http://127.0.0.1:38510
goto _all_backend_ready
)
call :port_is_listening 5000
if not errorlevel 1 (
echo [error] port 38510 in use but not a valid DiffSinger backend.
goto end_fail
)
echo [mode] backend using %RESOLVED_BACKEND_MODE%
if "%RESOLVED_BACKEND_MODE%"=="runtime" goto _all_start_backend_runtime
goto _all_start_backend_source
:_all_start_backend_runtime
start "Backend" /d "%ROOT%" "%SELF%" backend-runtime
goto _all_wait_backend
:_all_start_backend_source
start "Backend" /d "%ROOT%" "%SELF%" backend-source
:_all_wait_backend
echo [wait] backend health check...
call :wait_for_http "Backend" "%BACKEND_HEALTH_URL%" %MELODY_BACKEND_START_TIMEOUT%
if errorlevel 1 goto end_fail
echo [ready] backend: http://127.0.0.1:38510
:_all_backend_ready
REM ---- launch seedvc ----
if "%_start_seedvc%"=="0" (
echo [skip] SeedVC not configured, skipping.
goto _all_seedvc_done
)
call :http_is_ready "%SEEDVC_HEALTH_URL%"
if not errorlevel 1 (
echo [reuse] SeedVC already running: http://127.0.0.1:38511
goto _all_seedvc_done
)
call :port_is_listening 5001
if not errorlevel 1 (
echo [error] port 38511 in use but not a valid SeedVC service.
goto end_fail
)
start "SeedVC" /d "%ROOT%" "%SELF%" seedvc
echo [wait] SeedVC health check...
call :wait_for_http "SeedVC" "%SEEDVC_HEALTH_URL%" %MELODY_SEEDVC_START_TIMEOUT%
if errorlevel 1 goto _all_seedvc_warn
echo [ready] SeedVC: http://127.0.0.1:38511
goto _all_seedvc_done
:_all_seedvc_warn
echo [warn] SeedVC startup timed out, continuing without it.
:_all_seedvc_done
REM ---- launch frontend ----
start "Frontend" /d "%ROOT%" "%SELF%" frontend %FRONTEND_PORT%
echo [wait] frontend health check...
call :wait_for_http "Frontend" "http://127.0.0.1:%FRONTEND_PORT%" %MELODY_FRONTEND_START_TIMEOUT%
if errorlevel 1 goto end_fail
echo [ready] frontend: http://127.0.0.1:%FRONTEND_PORT%
call :start_tunnel_if_enabled %FRONTEND_PORT%
REM ---- summary ----
echo.
echo ========================================
echo All services launched:
echo Backend: http://127.0.0.1:38510
if "%_start_seedvc%"=="1" echo SeedVC: http://127.0.0.1:38511
echo Frontend: http://127.0.0.1:%FRONTEND_PORT%
echo ========================================
echo.
echo Closing this window will NOT stop the launched services.
goto end_ok
REM ========================================
REM Exit
REM ========================================
:end_fail
echo.
if "%MELODY_DEV_NO_PAUSE%"=="1" exit /b 1
pause
exit /b 1
:end_ok
if "%MELODY_DEV_NO_PAUSE%"=="1" exit /b 0
pause