vignette/scripts/start-higgs-tts.ps1

73 lines
2.6 KiB
PowerShell

param(
[int]$Port = 9881,
[int]$WaitReadySeconds = 180
)
$ErrorActionPreference = 'Stop'
[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false)
$OutputEncoding = [System.Text.UTF8Encoding]::new($false)
$repoRoot = Split-Path -Parent $PSScriptRoot
$serverScript = Join-Path $PSScriptRoot 'higgs-tts-server.py'
$embeddedPython = 'C:\Users\encep\Tools\ComfyUI_windows_portable\python_embeded\python.exe'
$healthUrl = "http://127.0.0.1:$Port/health"
$runtimeLogDir = Join-Path $env:TEMP 'Vignette\higgs-tts'
$stdoutLog = Join-Path $runtimeLogDir 'server.out.log'
$stderrLog = Join-Path $runtimeLogDir 'server.err.log'
if (!(Test-Path -LiteralPath $embeddedPython)) {
throw "ComfyUI embedded Python을 찾지 못했습니다: $embeddedPython"
}
if (!(Test-Path -LiteralPath $serverScript)) {
throw "Higgs 서버 스크립트를 찾지 못했습니다: $serverScript"
}
try {
$currentHealth = Invoke-RestMethod -Uri $healthUrl -Method Get -TimeoutSec 3
if ($currentHealth.status -eq 'ok' -and $currentHealth.reference_policy -eq 'synthetic-seed-only') {
Write-Output "Higgs TTS가 이미 준비됐습니다: $healthUrl"
$currentHealth | ConvertTo-Json -Depth 4 -Compress
return
}
} catch {
# 아직 서버가 없으면 아래에서 시작한다.
}
$listener = Get-NetTCPConnection -State Listen -LocalPort $Port -ErrorAction SilentlyContinue
if ($null -ne $listener) {
throw "포트 $Port 를 다른 프로세스가 사용 중입니다. 임의 종료하지 않았습니다."
}
New-Item -ItemType Directory -Path $runtimeLogDir -Force | Out-Null
$args = @('-X', 'utf8', $serverScript, '--host', '127.0.0.1', '--port', "$Port")
$process = Start-Process -WindowStyle Hidden -FilePath $embeddedPython `
-ArgumentList $args `
-WorkingDirectory $repoRoot `
-RedirectStandardOutput $stdoutLog `
-RedirectStandardError $stderrLog `
-PassThru
Write-Output "Higgs TTS 로드를 시작했습니다. PID=$($process.Id)"
Write-Output "로그: $stdoutLog"
if ($WaitReadySeconds -le 0) {
return
}
$deadline = (Get-Date).AddSeconds($WaitReadySeconds)
while ((Get-Date) -lt $deadline) {
if ($process.HasExited) {
throw "Higgs TTS가 준비되기 전에 종료됐습니다. stderr=$stderrLog"
}
try {
$health = Invoke-RestMethod -Uri $healthUrl -Method Get -TimeoutSec 3
if ($health.status -eq 'ok' -and $health.reference_policy -eq 'synthetic-seed-only') {
Write-Output "Higgs TTS 준비 완료: $healthUrl"
$health | ConvertTo-Json -Depth 4 -Compress
return
}
} catch {
Start-Sleep -Seconds 2
}
}
throw "Higgs TTS 준비 시간이 ${WaitReadySeconds}초를 넘었습니다. 로그: $stdoutLog"