Gerador de vídeos narrativos (Godot + FFmpeg), painel Next.js, serviço de voz, Clipador de lives e Publicador para YouTube, TikTok e Instagram. Inclui a leitura das visualizações dos posts para o Dashboard e o botão "Publicar no <rede>" nos cartões das publicações. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
274 lines
15 KiB
PowerShell
274 lines
15 KiB
PowerShell
# Instalação do CenaForge no Windows (chamado pelo setup.bat na raiz).
|
|
#
|
|
# O que faz, nesta ordem (pode rodar de novo: o que já está pronto é pulado):
|
|
# 1. Node.js + pnpm e as dependências do projeto (pnpm install)
|
|
# 2. uv + Python 3.12 isolado em voice/.venv (não mexe no Python do sistema)
|
|
# 3. Serviço de voz: dependências; DLLs do CUDA se houver GPU NVIDIA
|
|
# 4. voice/.env com chave aleatória (Whisper large-v3-turbo com GPU, small sem GPU)
|
|
# 5. Pesos dos modelos (Piper + Whisper) com conferência de sha256
|
|
# 6. Applio 3.7.0 (vozes de personagem/RVC): torch CUDA ou CPU + pré-requisitos [pule com -NoRvc]
|
|
# 6b. Clipador e 6b2. Publicador (venv + chave em clipper/.env e publisher/.env)
|
|
# 6c. Clonagem de voz (Chatterbox, venv próprio voice/.venv-clone) [só com -Clone]
|
|
# 7. pnpm run doctor (Godot/FFmpeg)
|
|
#
|
|
# Uso: setup.bat instalação completa
|
|
# setup.bat -NoRvc sem Applio (economiza ~4 GB; vozes de personagem ficam desligadas)
|
|
# setup.bat -Cpu força CPU mesmo com GPU NVIDIA
|
|
# setup.bat -Clone também instala a clonagem de voz (~4 GB: torch 2.6 + Chatterbox)
|
|
param(
|
|
[switch]$NoRvc,
|
|
[switch]$Cpu,
|
|
[switch]$Clone
|
|
)
|
|
|
|
# "Continue" e não "Stop": no PowerShell 5.1 o stderr de um executável (o uv escreve progresso lá) vira
|
|
# NativeCommandError. Cada comando externo é conferido pelo código de saída em Run().
|
|
$ErrorActionPreference = "Continue"
|
|
$Root = Split-Path -Parent $PSScriptRoot
|
|
$Voice = Join-Path $Root "voice"
|
|
$VenvPython = Join-Path $Voice ".venv\Scripts\python.exe"
|
|
$ApplioDir = Join-Path $Voice "vendor\applio"
|
|
$ApplioTag = "3.7.0"
|
|
$TorchVersion = "2.11.0"
|
|
|
|
function Step($text) { Write-Host ""; Write-Host "==> $text" -ForegroundColor Cyan }
|
|
function Ok($text) { Write-Host " ok: $text" -ForegroundColor Green }
|
|
function Warn($text) { Write-Host " aviso: $text" -ForegroundColor Yellow }
|
|
function Fail($text) { Write-Host ""; Write-Host "ERRO: $text" -ForegroundColor Red; exit 1 }
|
|
function Has($cmd) { return [bool](Get-Command $cmd -ErrorAction SilentlyContinue) }
|
|
function Run($exe, [string[]]$arguments) {
|
|
& $exe @arguments
|
|
if ($LASTEXITCODE -ne 0) { Fail "$exe $($arguments -join ' ') terminou com código $LASTEXITCODE" }
|
|
}
|
|
function Set-EnvValue($file, $name, $value) {
|
|
$lines = Get-Content $file -Encoding utf8
|
|
if ($lines -match "^$name=") { $lines = $lines -replace "^$name=.*$", "$name=$value" }
|
|
else { $lines += "$name=$value" }
|
|
Set-Content -Path $file -Value $lines -Encoding utf8
|
|
}
|
|
|
|
Write-Host "CenaForge — instalação" -ForegroundColor White
|
|
Write-Host "Pasta: $Root"
|
|
|
|
# ---------- 1. Node + pnpm ----------
|
|
Step "Node.js e pnpm"
|
|
if (-not (Has "node")) { Fail "Node.js 20.10+ não encontrado. Instale em https://nodejs.org (versão LTS) e rode o setup de novo." }
|
|
$nodeVersion = (node --version).TrimStart("v")
|
|
if ([version]$nodeVersion -lt [version]"20.10.0") { Fail "Node.js $nodeVersion é antigo; o CenaForge exige 20.10+." }
|
|
Ok "node $nodeVersion"
|
|
if (-not (Has "pnpm")) {
|
|
Warn "pnpm ausente; ativando pelo corepack"
|
|
Run "corepack" @("enable")
|
|
if (-not (Has "pnpm")) { Run "npm" @("install", "-g", "pnpm") }
|
|
}
|
|
Ok "pnpm $(pnpm --version)"
|
|
Push-Location $Root
|
|
Run "pnpm" @("install")
|
|
Pop-Location
|
|
|
|
# ---------- 2. uv + Python 3.12 ----------
|
|
Step "Python 3.12 isolado (uv)"
|
|
if (-not (Has "uv")) {
|
|
Warn "uv ausente; instalando (https://astral.sh/uv)"
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command "irm https://astral.sh/uv/install.ps1 | iex"
|
|
$env:Path = "$env:USERPROFILE\.local\bin;$env:Path"
|
|
if (-not (Has "uv")) { Fail "não consegui instalar o uv; instale à mão e rode o setup de novo" }
|
|
}
|
|
Ok "uv $((uv --version) -replace 'uv ', '')"
|
|
if (-not (Test-Path $VenvPython)) { Run "uv" @("venv", (Join-Path $Voice ".venv"), "--python", "3.12") }
|
|
Ok "voice/.venv ($(& $VenvPython --version))"
|
|
|
|
# ---------- 3. Dependências do serviço de voz ----------
|
|
Step "Dependências do serviço de voz"
|
|
Run "uv" @("pip", "install", "--python", $VenvPython, "-r", (Join-Path $Voice "requirements.txt"))
|
|
$Gpu = $false
|
|
if (-not $Cpu -and (Has "nvidia-smi")) {
|
|
# Sem "| Select-Object -First 1" direto no nvidia-smi: cortar o pipeline mata o processo e o
|
|
# $LASTEXITCODE deixa de ser 0 (foi assim que uma RTX 2060 passou por "sem GPU").
|
|
$gpuLines = @(nvidia-smi --query-gpu=name --format=csv,noheader 2>$null)
|
|
if ($LASTEXITCODE -eq 0 -and $gpuLines.Count -gt 0 -and $gpuLines[0]) { $Gpu = $true; Ok "GPU NVIDIA: $($gpuLines[0])" }
|
|
}
|
|
if ($Gpu) {
|
|
Run "uv" @("pip", "install", "--python", $VenvPython, "-r", (Join-Path $Voice "requirements-cuda.txt"))
|
|
Ok "DLLs do CUDA 12 (cuBLAS, cuDNN)"
|
|
} else {
|
|
Warn "sem GPU NVIDIA utilizável: tudo roda na CPU (mais lento na legenda e nas vozes de personagem)"
|
|
}
|
|
|
|
# ---------- 4. voice/.env ----------
|
|
Step "Configuração (voice/.env)"
|
|
$EnvFile = Join-Path $Voice ".env"
|
|
if (-not (Test-Path $EnvFile)) {
|
|
Copy-Item (Join-Path $Voice ".env.example") $EnvFile
|
|
$key = & $VenvPython -c "import secrets; print(secrets.token_urlsafe(48))"
|
|
Set-EnvValue $EnvFile "VOICE_SERVICE_KEY" $key
|
|
Set-EnvValue $EnvFile "VOICE_STT_MODEL" ($(if ($Gpu) { "large-v3-turbo" } else { "small" }))
|
|
Ok "voice/.env criado com chave nova"
|
|
} else {
|
|
Ok "voice/.env já existe (mantido)"
|
|
}
|
|
Set-EnvValue $EnvFile "VOICE_DEVICE" ($(if ($Cpu) { "cpu" } else { "auto" }))
|
|
$sttModel = ((Get-Content $EnvFile -Encoding utf8) -match "^VOICE_STT_MODEL=" | Select-Object -First 1) -replace "^VOICE_STT_MODEL=", ""
|
|
if (-not $sttModel) { $sttModel = "small" }
|
|
|
|
# ---------- 5. Pesos ----------
|
|
Step "Modelos de voz e transcrição (Whisper $sttModel)"
|
|
Run $VenvPython @((Join-Path $Voice "scripts\fetch_models.py"), "--group", "v1", "--group", "stt-$sttModel")
|
|
|
|
# ---------- 6. Applio (RVC) ----------
|
|
if ($NoRvc) {
|
|
Step "Applio (RVC): pulado (-NoRvc)"
|
|
Set-EnvValue $EnvFile "VOICE_ENABLE_RVC" "0"
|
|
} else {
|
|
Step "Applio $ApplioTag (vozes de personagem / RVC)"
|
|
if (-not (Test-Path (Join-Path $ApplioDir "rvc\infer\infer.py"))) {
|
|
New-Item -ItemType Directory -Force (Split-Path $ApplioDir) | Out-Null
|
|
if (Has "git") {
|
|
Run "git" @("clone", "--depth", "1", "--branch", $ApplioTag, "https://github.com/IAHispano/Applio.git", $ApplioDir)
|
|
} else {
|
|
$zip = Join-Path $env:TEMP "applio-$ApplioTag.zip"
|
|
Invoke-WebRequest -UseBasicParsing "https://github.com/IAHispano/Applio/archive/refs/tags/$ApplioTag.zip" -OutFile $zip
|
|
Expand-Archive $zip (Split-Path $ApplioDir) -Force
|
|
Rename-Item (Join-Path (Split-Path $ApplioDir) "Applio-$ApplioTag") $ApplioDir
|
|
Remove-Item $zip
|
|
}
|
|
}
|
|
Ok "Applio em voice/vendor/applio"
|
|
# Variante explícita (+cu128/+cpu): "torch==2.11.0" sozinho aceitaria a variante errada já instalada.
|
|
$variant = if ($Gpu) { "cu128" } else { "cpu" }
|
|
$index = "https://download.pytorch.org/whl/$variant"
|
|
Run "uv" @("pip", "install", "--python", $VenvPython, "--index-url", $index, "torch==$TorchVersion+$variant", "torchaudio==$TorchVersion+$variant")
|
|
Ok "torch $TorchVersion ($(if ($Gpu) { 'CUDA 12.8' } else { 'CPU' }))"
|
|
Run "uv" @("pip", "install", "--python", $VenvPython, "-r", (Join-Path $Voice "requirements-rvc.txt"))
|
|
# Pré-requisitos de inferência (contentvec, rmvpe, fcpe). Os pré-treinados de treino ficam para quando treinarmos.
|
|
Push-Location $ApplioDir
|
|
Run $VenvPython @("-c", "from rvc.lib.tools.prerequisites_download import prequisites_download_pipeline as p; p(False, True, False)")
|
|
Pop-Location
|
|
Set-EnvValue $EnvFile "VOICE_ENABLE_RVC" "1"
|
|
Ok "RVC ligado"
|
|
}
|
|
|
|
# ---------- 6b. Clipador (cortes de live) ----------
|
|
Step "Clipador (cortes de live: Streamlink + chat + IA)"
|
|
$Clipper = Join-Path $Root "clipper"
|
|
$ClipperPython = Join-Path $Clipper ".venv\Scripts\python.exe"
|
|
if (-not (Test-Path $ClipperPython)) { Run "uv" @("venv", (Join-Path $Clipper ".venv"), "--python", "3.12") }
|
|
Run "uv" @("pip", "install", "--python", $ClipperPython, "-r", (Join-Path $Clipper "requirements.txt"))
|
|
$ClipperEnv = Join-Path $Clipper ".env"
|
|
if (-not (Test-Path $ClipperEnv)) {
|
|
Copy-Item (Join-Path $Clipper ".env.example") $ClipperEnv
|
|
$key = & $ClipperPython -c "import secrets; print(secrets.token_urlsafe(48))"
|
|
Set-EnvValue $ClipperEnv "CLIPPER_SERVICE_KEY" $key
|
|
Ok "clipper/.env criado com chave nova"
|
|
} else {
|
|
Ok "clipper/.env já existe (mantido)"
|
|
}
|
|
Ok "Streamlink $(& (Join-Path $Clipper '.venv\Scripts\streamlink.exe') --version)"
|
|
if (-not (Has "codex") -and -not (Has "claude")) {
|
|
Warn "nem Codex nem Claude CLI no PATH: o juiz de IA dos cortes fica desligado até instalar e fazer login"
|
|
}
|
|
# Rastreio de reação: o cv2 tem de vir do opencv-contrib-python (puxado pelo MediaPipe), com FaceDetectorYN.
|
|
& $ClipperPython -c "import cv2, mediapipe; cv2.FaceDetectorYN; from mediapipe.tasks.python import vision; vision.FaceLandmarker"
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Warn "cv2/MediaPipe não importam no clipper/.venv (opencv-python-headless instalado junto?): rastreio de reação fica desligado"
|
|
}
|
|
# Pesos do rastreio (YuNet, MediaPipe, OpenSeeFace): URL fixa + sha256 em clipper/models.lock.json.
|
|
$ModelLock = Get-Content (Join-Path $Clipper "models.lock.json") -Raw -Encoding utf8 | ConvertFrom-Json
|
|
$ModelDir = Join-Path $Root $ModelLock.dir
|
|
New-Item -ItemType Directory -Force $ModelDir | Out-Null
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
|
$oldProgress = $ProgressPreference
|
|
$ProgressPreference = "SilentlyContinue" # a barra de progresso do Invoke-WebRequest deixa o download lento no 5.1
|
|
foreach ($m in $ModelLock.models) {
|
|
$dest = Join-Path $ModelDir $m.file
|
|
if ((Test-Path $dest) -and ((Get-FileHash $dest -Algorithm SHA256).Hash -eq $m.sha256.ToUpper())) {
|
|
Ok "modelo $($m.file) (sha256 confere)"
|
|
continue
|
|
}
|
|
$tmp = "$dest.part"
|
|
try {
|
|
Invoke-WebRequest -Uri $m.url -OutFile $tmp -UseBasicParsing
|
|
} catch {
|
|
Warn "não consegui baixar $($m.file): $($_.Exception.Message) (o Clipador tenta de novo quando precisar)"
|
|
Remove-Item $tmp -Force -ErrorAction SilentlyContinue
|
|
continue
|
|
}
|
|
if ((Get-FileHash $tmp -Algorithm SHA256).Hash -ne $m.sha256.ToUpper()) {
|
|
Remove-Item $tmp -Force
|
|
Warn "sha256 de $($m.file) não confere com clipper/models.lock.json; arquivo descartado"
|
|
continue
|
|
}
|
|
Move-Item $tmp $dest -Force
|
|
Ok "modelo $($m.file) baixado (sha256 confere)"
|
|
}
|
|
$ProgressPreference = $oldProgress
|
|
|
|
# ---------- 6b2. Publicador (envio para YouTube, TikTok e Instagram) ----------
|
|
Step "Publicador (envio para as redes: API oficial ou sessão logada)"
|
|
$Publisher = Join-Path $Root "publisher"
|
|
$PublisherPython = Join-Path $Publisher ".venv\Scripts\python.exe"
|
|
if (-not (Test-Path $PublisherPython)) { Run "uv" @("venv", (Join-Path $Publisher ".venv"), "--python", "3.12") }
|
|
# Só o pacote do Playwright (driver). NÃO rodamos "playwright install": o modo sessão usa o Chrome/Edge já instalado.
|
|
Run "uv" @("pip", "install", "--python", $PublisherPython, "-r", (Join-Path $Publisher "requirements.txt"))
|
|
$PublisherEnv = Join-Path $Publisher ".env"
|
|
if (-not (Test-Path $PublisherEnv)) {
|
|
Copy-Item (Join-Path $Publisher ".env.example") $PublisherEnv
|
|
$key = & $PublisherPython -c "import secrets; print(secrets.token_urlsafe(48))"
|
|
Set-EnvValue $PublisherEnv "PUBLISHER_SERVICE_KEY" $key
|
|
Ok "publisher/.env criado com chave nova"
|
|
} else {
|
|
Ok "publisher/.env já existe (mantido)"
|
|
}
|
|
# Segredos do Publicador (chave do serviço, cofre de tokens, banco, sessões logadas do navegador, capturas):
|
|
# só o usuário atual do Windows lê. Sem herança de permissões; pasta com (OI)(CI) para valer nos arquivos de dentro.
|
|
$PublisherData = Join-Path $Root "data\publisher"
|
|
New-Item -ItemType Directory -Force $PublisherData | Out-Null
|
|
$MySid = [System.Security.Principal.WindowsIdentity]::GetCurrent().User.Value
|
|
& icacls $PublisherEnv /inheritance:r /grant:r "*${MySid}:F" | Out-Null
|
|
$aclEnvOk = $LASTEXITCODE -eq 0
|
|
& icacls $PublisherData /inheritance:r /grant:r "*${MySid}:(OI)(CI)F" | Out-Null
|
|
$aclDataOk = $LASTEXITCODE -eq 0
|
|
# Os filhos que já existem passam a herdar SÓ da pasta. (Não use /T com (OI)(CI): em arquivo isso vira ACL vazia.)
|
|
if (Get-ChildItem $PublisherData -Force -ErrorAction SilentlyContinue) {
|
|
& icacls (Join-Path $PublisherData "*") /reset /T /C | Out-Null
|
|
$aclDataOk = $aclDataOk -and $LASTEXITCODE -eq 0
|
|
}
|
|
if ($aclEnvOk -and $aclDataOk) { Ok "permissões de publisher/.env e data/publisher restritas ao seu usuário" }
|
|
else { Warn "não consegui restringir as permissões de publisher/.env ou data/publisher (icacls); siga, mas confira depois" }
|
|
$chromePaths = @("$env:ProgramFiles\Google\Chrome\Application\chrome.exe", "${env:ProgramFiles(x86)}\Google\Chrome\Application\chrome.exe",
|
|
"$env:LOCALAPPDATA\Google\Chrome\Application\chrome.exe", "${env:ProgramFiles(x86)}\Microsoft\Edge\Application\msedge.exe",
|
|
"$env:ProgramFiles\Microsoft\Edge\Application\msedge.exe")
|
|
if (-not ($chromePaths | Where-Object { Test-Path $_ })) {
|
|
Warn "Chrome/Edge não encontrado: o modo Sessão logada fica indisponível (a API oficial funciona)"
|
|
}
|
|
|
|
# ---------- 6c. Clonagem de voz (opcional) ----------
|
|
# O Chatterbox fixa torch 2.6, numpy < 2 e outro transformers: não cabe no voice/.venv, então ganha o seu.
|
|
$CloneVenv = Join-Path $Voice ".venv-clone"
|
|
$ClonePython = Join-Path $CloneVenv "Scripts\python.exe"
|
|
if ($Clone) {
|
|
Step "Clonagem de voz (Chatterbox Multilingual, MIT)"
|
|
if (-not (Test-Path $ClonePython)) { Run "uv" @("venv", $CloneVenv, "--python", "3.12") }
|
|
$cloneVariant = if ($Gpu) { "cu124" } else { "cpu" }
|
|
$cloneIndex = "https://download.pytorch.org/whl/$cloneVariant"
|
|
Run "uv" @("pip", "install", "--python", $ClonePython, "--index-url", $cloneIndex, "torch==2.6.0+$cloneVariant", "torchaudio==2.6.0+$cloneVariant")
|
|
Run "uv" @("pip", "install", "--python", $ClonePython, "-r", (Join-Path $Voice "clone\requirements.txt"),
|
|
"torch==2.6.0+$cloneVariant", "torchaudio==2.6.0+$cloneVariant",
|
|
"--extra-index-url", $cloneIndex, "--index-strategy", "unsafe-best-match")
|
|
Ok "Chatterbox instalado ($(if ($Gpu) { 'CUDA 12.4' } else { 'CPU: cada fala leva bem mais tempo' })); os pesos (~3 GB) baixam na primeira subida"
|
|
} elseif (Test-Path $ClonePython) {
|
|
Ok "clonagem de voz já instalada (voice/.venv-clone)"
|
|
} else {
|
|
Ok "clonagem de voz não instalada (opcional: setup.bat -Clone)"
|
|
}
|
|
|
|
# ---------- 7. Diagnóstico ----------
|
|
Step "Diagnóstico do projeto (Godot, FFmpeg)"
|
|
Push-Location $Root
|
|
pnpm run doctor
|
|
if ($LASTEXITCODE -ne 0) { Warn "o doctor apontou pendências acima (render de vídeo); a voz já está instalada" }
|
|
Pop-Location
|
|
|
|
Write-Host ""
|
|
Write-Host "Pronto. Para subir o CenaForge (painel 4500 + voz 4510 + Clipador 4520 + Publicador 4530): start.bat (ou: pnpm dev)" -ForegroundColor Green
|