Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

33 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Laguna Translator

🌊 Laguna Translator

TraduΓ§Γ£o de voz em tempo real Β· 100% local Β· PT ↔ EN Β· feito pra Discord

Fale portuguΓͺs β€” seus amigos ouvem em inglΓͺs.
Eles falam em inglΓͺs β€” vocΓͺ ouve em portuguΓͺs.

Sem nuvem. Sem API key. Sem latΓͺncia de internet. Sua voz nunca sai da sua mΓ‘quina.


Site GitHub

Python Windows CUDA FastAPI Whisper License Offline Stars Last commit

p50 ~450ms Β· p95 ~550ms (GPU small, fala β†’ traduΓ§Γ£o sintetizada)

🌐 Site Β· πŸ‡§πŸ‡· PortuguΓͺs Β· πŸ‡ΊπŸ‡Έ English


πŸ‡§πŸ‡· PortuguΓͺs

Índice β€” Β  O que Γ© Β· Em aΓ§Γ£o Β· Arquitetura Β· Os dois painΓ©is Β· Destaques Β· Comparativo Β· Performance Β· Stack Β· Quick start Β· Discord Β· Estrutura Β· UI Β· Problemas Β· FAQ Β· Roadmap Β· Notas tΓ©cnicas Β· Contribuindo Β· LicenΓ§a

✨ O que é

Laguna Γ© um tradutor de voz em tempo real pensado pra chamadas no Discord (mas serve pra qualquer coisa). VocΓͺ fala no microfone, o Laguna transcreve, traduz e ressintetiza β€” tudo na sua mΓ‘quina, em menos de meio segundo β€” e entrega o Γ‘udio traduzido num microfone virtual que o Discord enxerga como se fosse seu.

O caminho contrΓ‘rio tambΓ©m funciona: captura o Γ‘udio do Discord, transcreve e traduz pra vocΓͺ ouvir no fone.

NΓ£o-metas: isto nΓ£o Γ© um produto SaaS, nΓ£o Γ© um competidor de Google Translate, e nΓ£o tenta ser. Γ‰ uma ferramenta pra quem joga/conversa com gente que fala outro idioma e quer uma ponte sem depender de cloud.

🌐 Tem um site de apresentaΓ§Γ£o: lagunatranslate.vercel.app β€” bilΓ­ngue, com o pipeline animado e a UI em destaque.


🎬 Veja em ação (fluxo FALAR)

sequenceDiagram
    autonumber
    participant πŸŽ™ as Microfone
    participant VAD as WebRTC VAD<br/>(30ms frames)
    participant STT as faster-whisper<br/>(CUDA fp16)
    participant MT as Argos Translate
    participant TTS as Piper TTS
    participant πŸ”Š as Cabo Virtual<br/>(Laguna Mic)
    participant 🎧 as Discord

    πŸŽ™->>VAD: PCM 16kHz mono
    Note over VAD: detecta fala,<br/>buffer 300ms prΓ©-fala
    VAD->>STT: segmento de voz<br/>(~2-10s)
    STT-->>MT: "olΓ‘ pessoal, teste de traduΓ§Γ£o"<br/>(~450ms)
    MT-->>TTS: "hello everyone, translation test"<br/>(~30ms)
    TTS-->>πŸ”Š: PCM sintetizado<br/>(~40ms)
    πŸ”Š->>🎧: entra como microfone
Loading

🧭 Arquitetura

flowchart LR
    subgraph UI["πŸ–₯️ Web UI (navegador)"]
        HTML[index.html<br/>JS + CSS]
    end

    subgraph SRV["βš™οΈ Servidor FastAPI (127.0.0.1:7531)"]
        REST[REST /api/*]
        WS[WebSocket /ws]
    end

    subgraph CORE["🧠 Laguna Core"]
        W1[DirectionWorker<br/>FALAR πŸŽ™οΈ]
        W2[DirectionWorker<br/>ESCUTAR πŸ‘‚]
    end

    subgraph PIPE["πŸ” Pipeline por worker"]
        direction TB
        CAP[sounddevice<br/>InputStream]
        VAD[WebRTC VAD]
        STT[faster-whisper]
        MT[Argos Translate]
        TTS[Piper TTS]
        OUT[sounddevice<br/>OutputStream]
        CAP --> VAD --> STT --> MT --> TTS --> OUT
    end

    subgraph HW["🎚️ Áudio / Windows"]
        MIC[πŸŽ™ Mic real]
        LOOP[WASAPI Loopback]
        VCBL[VB-CABLE<br/>🌊 Laguna Mic / Output]
        FONE[🎧 Fone]
    end

    HTML <-->|REST start/stop/gain| REST
    HTML <-.->|live events| WS
    REST --> W1 & W2
    W1 -.eventos.-> WS
    W2 -.eventos.-> WS
    W1 --> PIPE
    W2 --> PIPE

    MIC --> CAP
    LOOP --> CAP
    OUT --> VCBL
    OUT --> FONE

    classDef dim fill:#eef,stroke:#99f,color:#223
    class UI,SRV,CORE,PIPE,HW dim
Loading

Dois workers rodam simultΓ’neos e independentes β€” cada um com seus modelos, configs, devices e mΓ©tricas. O servidor FastAPI sΓ³ orquestra: REST pra controle, WebSocket pra live updates (STT parcial, traduΓ§Γ£o, latΓͺncia rolling, medidores de nΓ­vel).


🧩 Como os dois painéis se encaixam

flowchart TB
    subgraph VOCE["πŸ‘€ VocΓͺ"]
        VMIC[πŸŽ™ Mic real]
        VFONE[🎧 Fone real]
    end

    subgraph LAGUNA["🌊 Laguna Translator"]
        FALAR[Painel FALAR<br/>PT β†’ EN]
        ESCUTAR[Painel ESCUTAR<br/>EN β†’ PT]
    end

    subgraph VBCABLE["πŸ”Œ VB-CABLE (renomeado)"]
        LAGMIC[Laguna Mic<br/>virtual input]
        LAGOUT[Laguna Output<br/>virtual output]
    end

    subgraph DISCORD["πŸ’¬ Discord"]
        DIN[Input: Laguna Mic]
        DOUT[Output: seu fone real]
    end

    VMIC -->|sua voz PT| FALAR
    FALAR -->|voz sintetizada EN| LAGMIC
    LAGMIC --> DIN

    DOUT -->|Γ‘udio dos amigos EN<br/>via loopback| ESCUTAR
    ESCUTAR -->|voz sintetizada PT| VFONE

    style LAGUNA fill:#e6f7ff,stroke:#1890ff,color:#003a8c
    style VBCABLE fill:#fff7e6,stroke:#fa8c16,color:#612500
Loading

πŸš€ Destaques

πŸ”’ 100% local Nenhum dado sai da mΓ‘quina. Sem API key, sem cloud, sem telemetria.
⚑ p50 ~450ms Small + CUDA fp16 Γ© o sweet spot β€” rΓ‘pido e preciso.
πŸ” Bidirecional simultΓ’neo Dois pipelines independentes: FALAR e ESCUTAR rodam ao mesmo tempo.
🌐 DetecΓ§Γ£o de idioma Se vocΓͺ jΓ‘ falou no idioma alvo, pula a traduΓ§Γ£o (~130ms overhead, zero latΓͺncia extra de MT/TTS).
🎚️ Passthrough opcional Mandar também sua voz original junto com a tradução (útil pra mixar canal bilíngue).
πŸŽ›οΈ UI web reativa WebSocket + medidores de nΓ­vel + latΓͺncia p50/p95 em tempo real.
πŸŒ— Temas claro/escuro Shift+T pra alternar.
🌎 i18n PT/EN Toggle 🌐 no topo.
🎧 WASAPI loopback Captura saída do PC direto (sem "Stereo Mix").
πŸͺΆ Lean Sem torch. DependΓͺncias bem definidas em requirements.txt.

βš–οΈ Como se compara

🌊 Laguna ☁️ Bots / SaaS de cloud πŸ“± Google Translate (app) πŸ€– Bots de traduΓ§Γ£o do Discord
Roda 100% local βœ… ❌ ❌ ❌
Entra como microfone no Discord βœ… ⚠️ varia ❌ ❌ (precisa de bot no servidor)
LatΓͺncia tΓ­pica ~450ms 2–5s β€” (Γ© uma tela) 1–3s+
Privacidade da voz total ❌ ❌ ❌
Bidirecional simultΓ’neo βœ… ⚠️ ❌ ⚠️
Sem API key / sem conta βœ… ❌ βœ… ⚠️
Custo grΓ‘tis Β· MIT $/mΓͺs grΓ‘tis grΓ‘tis/$

Honestidade: serviΓ§os de cloud podem ter traduΓ§Γ£o de qualidade superior em frases longas. A Laguna troca um pouco disso por latΓͺncia baixa, privacidade total e zero dependΓͺncia de internet β€” que Γ© o que faz uma conversa fluir.


πŸ“Š Performance medida

Frase teste: "Hello everyone, this is a real-time translator test for Discord." (sintetizada via Piper pt_BR, ~4s de Γ‘udio).

Stack STT MT TTS Total Qualidade
tiny CPU int8 410 ms 317 ms 272 ms 999 ms ❌ baixa (muitos erros)
small CPU int8 2179 ms 292 ms 296 ms 2767 ms βœ… perfeita
small CUDA fp16 ⭐ 568 ms 269 ms 276 ms 1113 ms βœ… perfeita
medium CUDA fp16 775 ms 317 ms 246 ms 1338 ms ⚠ leve hallucination

Stress (200 segmentos contΓ­nuos, GPU small)

DireΓ§Γ£o p50 p95 p99
PT → EN (pb→en) 458 ms 562 ms 600 ms
EN → PT (en→pb) 424 ms 496 ms 534 ms

"Medium ficou com 'tradutora' e traduziu 'Discord' β†’ 'discΓ³rdia'; small acertou tudo." Small Γ© o ponto Γ³timo: mais rΓ‘pido e mais preciso pro caso de uso.


βš™οΈ Stack tΓ©cnica

flowchart LR
    subgraph ML["🧠 Machine Learning"]
        FW[faster-whisper 1.2<br/>+ CTranslate2 4.6]
        AR[Argos Translate 1.10<br/>pb ↔ en]
        PI[Piper TTS 1.4<br/>en_US-lessac Β· pt_BR-faber]
    end

    subgraph AUDIO["🎚️ Áudio"]
        SD[sounddevice]
        WV[webrtcvad-wheels]
        NP[numpy Β· scipy]
    end

    subgraph WEB["🌐 Web"]
        FA[FastAPI]
        UV[uvicorn]
        WS[WebSocket]
    end

    subgraph GPU["⚑ GPU (opcional)"]
        CB[nvidia-cublas-cu12 12.9]
        CD[nvidia-cudnn-cu12 9.19]
    end

    subgraph OPT["πŸ“¦ Opcionais"]
        PW[pywebview<br/>janela nativa]
        VB[VB-CABLE<br/>mic virtual]
    end
Loading

πŸƒ Quick start

PrΓ©-requisitos

  • Windows 10/11 (o launcher .vbs/.bat e WASAPI loopback sΓ£o Windows-especΓ­ficos)
  • Python 3.13 em C:\Python313\ (ou ajuste os caminhos nos scripts)
  • GPU NVIDIA com CUDA 12 (opcional, mas fortemente recomendado β€” roda em CPU tambΓ©m)
  • VB-CABLE pra integrar com Discord: https://vb-audio.com/Cable/

Instalar

git clone https://github.com/caioross/Laguna_Translate.git
cd Laguna_Translate
C:/Python313/python.exe -m pip install -r requirements.txt

# Para GPU (opcional β€” skip se sΓ³ for rodar em CPU)
C:/Python313/python.exe -m pip install nvidia-cublas-cu12 nvidia-cudnn-cu12

# Para janela nativa em vez do navegador (opcional β€” sem ele, laguna_app.py cai no navegador padrΓ£o)
C:/Python313/python.exe -m pip install pywebview

Para uma instalaΓ§Γ£o reproduzΓ­vel com as versΓ΅es exatas comprovadas, use o requirements.lock no lugar do requirements.txt: C:/Python313/python.exe -m pip install -r requirements.lock.

Modelos baixam sozinhos no primeiro run (~800MB total): Whisper small, vozes Piper, pacotes Argos pb↔en.

Rodar a UI web

C:/Python313/python.exe laguna_server.py

Abre http://127.0.0.1:7531 automaticamente. Dois painΓ©is β€” FALAR e ESCUTAR β€” com tudo configurΓ‘vel e mΓ©tricas ao vivo.

Rodar com janela nativa (WebView2)

C:/Python313/python.exe laguna_app.py

Atalhos no Desktop + Menu Iniciar

powershell -ExecutionPolicy Bypass -File .\install_shortcuts.ps1

Cria Laguna Translator.lnk no Desktop e Menu Iniciar. Usa Laguna.vbs (launcher silencioso, sem console). Pra remover: uninstall_shortcuts.ps1.

Modos CLI, offline e stress tests (clique pra expandir)

Modo CLI (sem UI, ΓΊtil pra debug)

# Listar devices
C:/Python313/python.exe fase0_poc.py --list-devices

# PT β†’ EN
C:/Python313/python.exe fase0_poc.py --direction pt2en --model small --device cuda

# EN β†’ PT
C:/Python313/python.exe fase0_poc.py --direction en2pt --model small --device cuda

# Debug (salva WAVs dos segmentos)
C:/Python313/python.exe fase0_poc.py --direction pt2en --debug

Ctrl+C encerra e imprime estatΓ­sticas p50/p95/p99 por estΓ‘gio.

Teste offline (sem microfone)

C:/Python313/python.exe test_offline.py dry_en2pt.wav --direction pt2en --model small --device cuda -o out.wav

Stress tests

C:/Python313/python.exe stress_fase0.py --rounds 20 --model small --device cuda   # PT β†’ EN
C:/Python313/python.exe stress_en2pt.py --rounds 20 --model small --device cuda   # EN β†’ PT

πŸ’¬ Configurar Discord (VB-CABLE + renomear)

sequenceDiagram
    participant U as πŸ‘€ UsuΓ‘rio
    participant W as πŸͺŸ Windows Sound
    participant L as 🌊 Laguna
    participant D as πŸ’¬ Discord

    U->>W: instala VB-CABLE
    U->>W: renomeia "CABLE Output" β†’ "Laguna Translator Mic"
    U->>W: renomeia "CABLE Input" β†’ "Laguna Translator Output"
    U->>L: abre UI, badge mostra "🌊 Laguna OK"
    U->>D: Input = Laguna Translator Mic
    U->>D: Output = seu fone real
    L->>D: voz traduzida entra como mic
    D->>L: Γ‘udio dos amigos (via loopback) β†’ traduz β†’ fone
Loading
Passo a passo
  1. Baixe e instale VB-CABLE: https://vb-audio.com/Cable/ (grΓ‘tis, reinicie depois)
  2. ConfiguraΓ§Γ΅es de som do Windows β†’ Mais opΓ§Γ΅es de som
  3. Aba GravaΓ§Γ£o β†’ direito em CABLE Output β†’ Propriedades β†’ Geral β†’ renomeia pra Laguna Translator Mic
  4. Aba ReproduΓ§Γ£o β†’ direito em CABLE Input β†’ Propriedades β†’ Geral β†’ renomeia pra Laguna Translator Output
  5. No Laguna a badge do topo vira "🌊 Laguna: dispositivos renomeados OK"
  6. No Discord β†’ Voz e VΓ­deo:
    • Entrada: Laguna Translator Mic
    • SaΓ­da: seu fone real (nΓ£o o virtual)
  7. No painel do Laguna:
    • FALAR β†’ "SaΓ­da virtual" = Laguna Translator Output
    • ESCUTAR β†’ "Captura" = Laguna Translator Mic (ou marque loopback e selecione o device que o Discord usa)

Sem VB-CABLE o app ainda funciona β€” sΓ³ nΓ£o aparece "invisΓ­vel" como mic no Discord.


πŸ“ Estrutura do projeto

Árvore de arquivos
Laguna_Translate/
β”œβ”€β”€ laguna_core.py          # DirectionWorker: pipeline bidirecional, VAD/STT/MT/TTS
β”œβ”€β”€ laguna_server.py        # FastAPI + WebSocket (UI web em http://127.0.0.1:7531)
β”œβ”€β”€ laguna_app.py           # Launcher com janela nativa (pywebview + WebView2)
β”œβ”€β”€ laguna_pipeline.py      # Engines e constantes: STT, ArgosMT, PiperTTS, VAD, detect_device
β”œβ”€β”€ fase0_poc.py            # CLI de POC (--list-devices); reexporta laguna_pipeline por compat
β”œβ”€β”€ fase1_app.py            # Painel PySide6 (legado, substituΓ­do pela UI web)
β”‚
β”œβ”€β”€ static/                 # UI web
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ app.js              # controla REST/WS, 2 painΓ©is, medidores, temas
β”‚   β”œβ”€β”€ i18n.js             # PT/EN
β”‚   └── style.css
β”‚
β”œβ”€β”€ Laguna.vbs              # launcher silencioso (pythonw, sem console)
β”œβ”€β”€ Laguna.bat              # launcher com console (debug)
β”œβ”€β”€ install_shortcuts.ps1   # cria atalhos Desktop + Start Menu
β”œβ”€β”€ uninstall_shortcuts.ps1
β”‚
β”œβ”€β”€ bench_fase0.py          # benchmark single-frase comparando stacks
β”œβ”€β”€ stress_fase0.py         # stress PT β†’ EN (200+ segmentos)
β”œβ”€β”€ stress_en2pt.py         # stress EN β†’ PT
β”œβ”€β”€ test_offline.py         # pipeline num WAV (sem mic)
β”œβ”€β”€ test_lang_detect.py     # testa skip-same-lang
β”‚
β”œβ”€β”€ docs/                   # plano tΓ©cnico
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ LICENSE                 # MIT
└── README.md               # vocΓͺ tΓ‘ aqui

O site de apresentaΓ§Γ£o (lagunatranslate.vercel.app) mora num repositΓ³rio separado (LagunaTranslate-site) β€” Next.js + Tailwind.


πŸŽ› UI: o que cada painel faz

FALAR β€” vocΓͺ fala no mic real, Laguna traduz, Γ‘udio sintetizado sai no microfone virtual que o Discord usa como entrada.

ESCUTAR β€” Laguna captura o Γ‘udio que chega ao seu fone (via loopback WASAPI ou um mic virtual pareado), traduz e toca no seu fone.

Cada painel tem:

  • seleΓ§Γ£o de idiomas (origem β†’ alvo)
  • seleΓ§Γ£o de devices (mic/loopback, saΓ­da virtual, fone opcional)
  • toggle passthrough (enviar tambΓ©m o Γ‘udio original)
  • controles de volume (saΓ­da da traduΓ§Γ£o, passthrough) em dB
  • avanΓ§ado: modelo STT, device (auto/cuda/cpu), skip same lang
  • bloco ao vivo: transcriΓ§Γ£o + traduΓ§Γ£o + mΓ©tricas p50/p95 + medidores de nΓ­vel
  • tooltips em tudo (passe o mouse)

🧯 Solução de problemas

CUDA nΓ£o Γ© detectada / cai pra CPU mesmo com GPU NVIDIA

Instale os pacotes CUDA via pip e confirme que estΓ£o no mesmo Python:

C:/Python313/python.exe -m pip install nvidia-cublas-cu12 nvidia-cudnn-cu12

No Windows, laguna_pipeline.py::_register_cuda_dlls() registra os diretΓ³rios bin/ do nvidia.cublas e nvidia.cudnn antes do import faster_whisper. Sem isso, o ctranslate2 nΓ£o acha as DLLs. Force a GPU no painel avanΓ§ado (Device β†’ cuda) pra ver o erro real, se houver.

O Discord nΓ£o escuta a traduΓ§Γ£o / nΓ£o aparece o mic virtual
  • Confirme que o VB-CABLE estΓ‘ instalado e que vocΓͺ reiniciou.
  • No painel FALAR, a "SaΓ­da virtual" precisa ser o CABLE Input (renomeado pra Laguna Translator Output).
  • No Discord β†’ Voz e VΓ­deo, a Entrada tem que ser o CABLE Output (renomeado pra Laguna Translator Mic).
  • Recarregue a pΓ‘gina da UI depois de renomear β€” os devices sΓ³ aparecem marcados com 🌊 apΓ³s o reload.
"loopback indisponΓ­vel" no painel ESCUTAR

O loopback WASAPI exige um device de saΓ­da (nΓ£o de entrada). Marque a opΓ§Γ£o "Captura loopback (WASAPI)" e selecione o dispositivo de reproduΓ§Γ£o que o Discord estΓ‘ usando. Se ainda falhar, use o caminho via VB-CABLE: aponte a saΓ­da do Discord pro Laguna Translator Output e capture pelo Laguna Translator Mic.

Os primeiros fonemas sΓ£o cortados / frases curtas somem

O VAD usa buffer prΓ©-fala de 300ms e segmento mΓ­nimo de 400ms. Falas muito curtas ("oi", "ok") podem cair abaixo do mΓ­nimo. Fale com um leve "respiro" antes β€” ou ajuste as constantes em laguna_pipeline.py (PRE_SPEECH_BUFFER_MS, MIN_SPEECH_MS).

O download dos modelos trava ou estΓ‘ muito lento

Os modelos vΓͺm do Hugging Face Hub no primeiro run e ficam em models_cache/. Em picos, o Hub aplica rate-limit. Tente de novo (o download Γ© retomΓ‘vel) ou rode uma direΓ§Γ£o de cada vez pra baixar menos coisa em paralelo.

Eco / loop de feedback (o app escuta a prΓ³pria traduΓ§Γ£o)

Garanta que a saΓ­da da traduΓ§Γ£o vai pro device virtual (Discord), nΓ£o pro mesmo device que vocΓͺ estΓ‘ capturando. No FALAR, capture do mic real e mande a traduΓ§Γ£o pro Laguna Translator Output. No ESCUTAR, capture do loopback/Discord e toque no seu fone real β€” nunca no mesmo canal.


❓ FAQ

Meu Γ‘udio vai pra nuvem? NΓ£o. Captura, transcriΓ§Γ£o, traduΓ§Γ£o e sΓ­ntese rodam na sua mΓ‘quina. Sem API key, sem servidor externo, sem telemetria.

Preciso de GPU NVIDIA? NΓ£o Γ© obrigatΓ³rio. Com GPU (CUDA fp16) vocΓͺ fica no sweet spot de ~450ms. Sem GPU, o app cai pro caminho de CPU automaticamente β€” funciona, sΓ³ com mais latΓͺncia.

Funciona sΓ³ no Discord? Foi pensado pro Discord, mas como entrega a traduΓ§Γ£o por um microfone virtual, funciona em qualquer app que deixe escolher o device de entrada: Meet, Zoom, OBS, etc.

Quais idiomas? PortuguΓͺs ↔ InglΓͺs, nas duas direΓ§Γ΅es e simultaneamente. Outros pares estΓ£o no roadmap.

Preciso do VB-CABLE? SΓ³ pra entrar "invisΓ­vel" como mic no Discord. Sem ele o app continua funcionando pra testar e ouvir traduΓ§Γ΅es.

Γ‰ de graΓ§a? Posso fazer fork? Sim. LicenΓ§a MIT: comercial, pessoal, fork, remix, rebrand. SΓ³ mantenha o copyright.


πŸ—Ί Roadmap / ideias

  • Empacotar como .exe standalone (PyInstaller --onedir com hooks pra faster_whisper, piper, ctranslate2, nvidia.cublas, nvidia.cudnn, argostranslate β†’ Inno Setup wrapper). Instalador ~1.5GB full, ~300MB com first-run bootstrap.
  • Backend alternativo de MT (NLLB, M2M100) pra melhorar gΓ­ria de jogo ("sick flick", "carry").
  • Mais pares de idiomas (ES, FR, JP...).
  • Modelo Whisper distil-large-v3 como opΓ§Γ£o premium.
  • Push-to-talk opcional.
  • Build Linux (loopback via PulseAudio/PipeWire em vez de WASAPI).

πŸ›  Notas tΓ©cnicas

Argos: pt vs pb

Argos tem dois pacotes portugueses:

  • pt β†’ Europeu ("estΓ‘s", "equipa", "juntar-se")
  • pb β†’ Brasileiro ("estΓ‘", "time", "se juntar")

O cΓ³digo mapeia pt β†’ pb automaticamente via ARGOS_CODE_MAP em laguna_pipeline.py. Whisper STT continua usando pt (o modelo nΓ£o distingue variantes).

DLLs CUDA no Windows

laguna_pipeline.py::_register_cuda_dlls() procura nvidia.cublas e nvidia.cudnn instalados via pip e registra os diretΓ³rios bin/ antes do import faster_whisper. Sem isso, ctranslate2 nΓ£o encontra as DLLs no Windows.

Pipeline de VAD β†’ segmentaΓ§Γ£o

WebRTC VAD com agressividade 2, frames de 30ms. Buffer prΓ©-fala de 300ms, hangover de silΓͺncio de 600ms, segmento mΓ­nimo 400ms, mΓ‘ximo 12s (force flush). ImplementaΓ§Γ£o em laguna_core.py e laguna_pipeline.py.


🀝 Contribuindo

Este projeto Γ© open-source de verdade β€” no sentido "faz fork e se divirta". NΓ£o tem roadmap oficial, nΓ£o tem SLA, nΓ£o tem processo. Se vocΓͺ acha que falta algo:

  1. DΓ‘ fork.
  2. Mexe Γ  vontade.
  3. Se achar que vale compartilhar, manda um PR descrevendo o que mudou e por quΓͺ.
  4. Se quiser seguir um caminho totalmente diferente, siga β€” o fork Γ© seu.

Issues com bugs/ideias tambΓ©m sΓ£o bem-vindas. Sem PR template, sem CLA, sem burocracia. Respeito mΓΊtuo e sΓ³.


πŸ“œ LicenΓ§a

MIT β€” ver LICENSE. Faz o que quiser: comercial, pessoal, fork, remix, rebrand. SΓ³ nΓ£o tire o copyright e nΓ£o me processe se quebrar. 🀝


πŸ‡ΊπŸ‡Έ English

Contents β€” Β  What it is Β· In action Β· Architecture Β· The two panels Β· Highlights Β· Comparison Β· Performance Β· Stack Β· Quick start Β· Discord Β· Structure Β· UI Β· Troubleshooting Β· FAQ Β· Roadmap Β· Technical notes Β· Contributing Β· License

✨ What it is

Laguna is a real-time voice translator built for Discord calls (but works anywhere). You speak into your mic; Laguna transcribes, translates and re-synthesizes it β€” all on your machine, in under half a second β€” and feeds the translated audio into a virtual microphone that Discord sees as if it were you. The reverse direction works too: it captures Discord's audio, transcribes and translates it back for you to hear.

Non-goals: this is not a SaaS product, not a Google Translate competitor, and doesn't try to be. It's a tool for people who game/chat with someone speaking another language and want a bridge that doesn't depend on the cloud.

🌐 There's a landing page: lagunatranslate.vercel.app β€” bilingual, with the animated pipeline and the UI front and center.


🎬 See it in action (SPEAK flow)

sequenceDiagram
    autonumber
    participant πŸŽ™ as Microphone
    participant VAD as WebRTC VAD<br/>(30ms frames)
    participant STT as faster-whisper<br/>(CUDA fp16)
    participant MT as Argos Translate
    participant TTS as Piper TTS
    participant πŸ”Š as Virtual Cable<br/>(Laguna Mic)
    participant 🎧 as Discord

    πŸŽ™->>VAD: PCM 16kHz mono
    Note over VAD: detects speech,<br/>300ms pre-speech buffer
    VAD->>STT: voice segment<br/>(~2-10s)
    STT-->>MT: "olΓ‘ pessoal, teste de traduΓ§Γ£o"<br/>(~450ms)
    MT-->>TTS: "hello everyone, translation test"<br/>(~30ms)
    TTS-->>πŸ”Š: synthesized PCM<br/>(~40ms)
    πŸ”Š->>🎧: comes in as a microphone
Loading

🧭 Architecture

flowchart LR
    subgraph UI["πŸ–₯️ Web UI (browser)"]
        HTML[index.html<br/>JS + CSS]
    end

    subgraph SRV["βš™οΈ FastAPI server (127.0.0.1:7531)"]
        REST[REST /api/*]
        WS[WebSocket /ws]
    end

    subgraph CORE["🧠 Laguna Core"]
        W1[DirectionWorker<br/>SPEAK πŸŽ™οΈ]
        W2[DirectionWorker<br/>LISTEN πŸ‘‚]
    end

    subgraph PIPE["πŸ” Per-worker pipeline"]
        direction TB
        CAP[sounddevice<br/>InputStream]
        VAD[WebRTC VAD]
        STT[faster-whisper]
        MT[Argos Translate]
        TTS[Piper TTS]
        OUT[sounddevice<br/>OutputStream]
        CAP --> VAD --> STT --> MT --> TTS --> OUT
    end

    subgraph HW["🎚️ Audio / Windows"]
        MIC[πŸŽ™ Real mic]
        LOOP[WASAPI Loopback]
        VCBL[VB-CABLE<br/>🌊 Laguna Mic / Output]
        FONE[🎧 Headset]
    end

    HTML <-->|REST start/stop/gain| REST
    HTML <-.->|live events| WS
    REST --> W1 & W2
    W1 -.events.-> WS
    W2 -.events.-> WS
    W1 --> PIPE
    W2 --> PIPE

    MIC --> CAP
    LOOP --> CAP
    OUT --> VCBL
    OUT --> FONE

    classDef dim fill:#eef,stroke:#99f,color:#223
    class UI,SRV,CORE,PIPE,HW dim
Loading

Two workers run simultaneously and independently β€” each with its own models, config, devices and metrics. The FastAPI server only orchestrates: REST for control, WebSocket for live updates (partial STT, translation, rolling latency, level meters).


🧩 How the two panels fit together

flowchart TB
    subgraph VOCE["πŸ‘€ You"]
        VMIC[πŸŽ™ Real mic]
        VFONE[🎧 Real headset]
    end

    subgraph LAGUNA["🌊 Laguna Translator"]
        FALAR[SPEAK panel<br/>PT β†’ EN]
        ESCUTAR[LISTEN panel<br/>EN β†’ PT]
    end

    subgraph VBCABLE["πŸ”Œ VB-CABLE (renamed)"]
        LAGMIC[Laguna Mic<br/>virtual input]
        LAGOUT[Laguna Output<br/>virtual output]
    end

    subgraph DISCORD["πŸ’¬ Discord"]
        DIN[Input: Laguna Mic]
        DOUT[Output: your real headset]
    end

    VMIC -->|your PT voice| FALAR
    FALAR -->|synthesized EN voice| LAGMIC
    LAGMIC --> DIN

    DOUT -->|friends' EN audio<br/>via loopback| ESCUTAR
    ESCUTAR -->|synthesized PT voice| VFONE

    style LAGUNA fill:#e6f7ff,stroke:#1890ff,color:#003a8c
    style VBCABLE fill:#fff7e6,stroke:#fa8c16,color:#612500
Loading

πŸš€ Highlights

πŸ”’ 100% local Nothing leaves your machine. No API key, no cloud, no telemetry.
⚑ p50 ~450ms Small + CUDA fp16 is the sweet spot β€” fast and accurate.
πŸ” Simultaneous bidirectional Two independent pipelines: SPEAK and LISTEN run at the same time.
🌐 Language detection If you already spoke the target language, it skips translation (~130ms overhead, zero extra MT/TTS latency).
🎚️ Optional passthrough Send your original voice alongside the translation (handy for a bilingual channel).
πŸŽ›οΈ Reactive web UI WebSocket + level meters + p50/p95 latency in real time.
πŸŒ— Light/dark themes Shift+T to toggle.
🌎 PT/EN i18n 🌐 toggle at the top.
🎧 WASAPI loopback Captures the PC's output directly (no "Stereo Mix").
πŸͺΆ Lean No torch. Well-defined deps in requirements.txt.

βš–οΈ How it compares

🌊 Laguna ☁️ Cloud bots / SaaS πŸ“± Google Translate (app) πŸ€– Discord translation bots
Runs 100% local βœ… ❌ ❌ ❌
Comes in as a Discord mic βœ… ⚠️ varies ❌ ❌ (needs a server bot)
Typical latency ~450ms 2–5s β€” (it's a screen) 1–3s+
Voice privacy total ❌ ❌ ❌
Simultaneous bidirectional βœ… ⚠️ ❌ ⚠️
No API key / no account βœ… ❌ βœ… ⚠️
Cost free Β· MIT $/mo free free/$

Honesty: cloud services may produce higher-quality translation on long sentences. Laguna trades a bit of that for low latency, total privacy and zero internet dependency β€” which is what actually keeps a conversation flowing.


πŸ“Š Measured performance

Test phrase: "Hello everyone, this is a real-time translator test for Discord." (synthesized via Piper pt_BR, ~4s of audio).

Stack STT MT TTS Total Quality
tiny CPU int8 410 ms 317 ms 272 ms 999 ms ❌ low (many errors)
small CPU int8 2179 ms 292 ms 296 ms 2767 ms βœ… perfect
small CUDA fp16 ⭐ 568 ms 269 ms 276 ms 1113 ms βœ… perfect
medium CUDA fp16 775 ms 317 ms 246 ms 1338 ms ⚠ slight hallucination

Stress (200 continuous segments, GPU small)

Direction p50 p95 p99
PT → EN (pb→en) 458 ms 562 ms 600 ms
EN → PT (en→pb) 424 ms 496 ms 534 ms

"Medium rendered 'tradutora' and translated 'Discord' β†’ 'discΓ³rdia'; small got everything right." Small is the sweet spot: faster and more accurate for the use case.


βš™οΈ Tech stack

faster-whisper 1.2 (+ CTranslate2) Β· Argos Translate (pb ↔ en) Β· Piper TTS (en_US-lessac Β· pt_BR-faber) Β· sounddevice + WebRTC VAD + numpy/scipy Β· FastAPI + uvicorn + WebSocket Β· optional NVIDIA CUDA 12 + pywebview + VB-CABLE.


πŸƒ Quick start

Prerequisites

  • Windows 10/11 (the .vbs/.bat launcher and WASAPI loopback are Windows-specific)
  • Python 3.13 in C:\Python313\ (or adjust the paths in the scripts)
  • NVIDIA GPU with CUDA 12 (optional, but strongly recommended β€” runs on CPU too)
  • VB-CABLE to integrate with Discord: https://vb-audio.com/Cable/

Install

git clone https://github.com/caioross/Laguna_Translate.git
cd Laguna_Translate
C:/Python313/python.exe -m pip install -r requirements.txt

# For GPU (optional β€” skip if running on CPU only)
C:/Python313/python.exe -m pip install nvidia-cublas-cu12 nvidia-cudnn-cu12

# For a native window instead of the browser (optional β€” without it, laguna_app.py falls back to the default browser)
C:/Python313/python.exe -m pip install pywebview

For a reproducible install with the exact proven versions, use requirements.lock instead of requirements.txt: C:/Python313/python.exe -m pip install -r requirements.lock.

Models auto-download on first run (~800 MB total): Whisper small, Piper voices, Argos pb↔en packages.

Run the web UI

C:/Python313/python.exe laguna_server.py   # opens http://127.0.0.1:7531

Two panels — SPEAK (PT→EN) and LISTEN (EN→PT) — with everything configurable and live metrics. For a native window (WebView2): python laguna_app.py. CLI/offline/stress modes are available (fase0_poc.py, test_offline.py, stress_*.py).


πŸ’¬ Discord setup (VB-CABLE + rename)

  1. Download and install VB-CABLE: https://vb-audio.com/Cable/ (free, reboot afterwards)
  2. Windows Sound settings β†’ More sound settings
  3. Recording tab β†’ right-click CABLE Output β†’ Properties β†’ General β†’ rename to Laguna Translator Mic
  4. Playback tab β†’ right-click CABLE Input β†’ Properties β†’ General β†’ rename to Laguna Translator Output
  5. In Laguna, the top badge turns into "🌊 Laguna: devices renamed OK"
  6. In Discord β†’ Voice & Video:
    • Input: Laguna Translator Mic
    • Output: your real headset (not the virtual one)
  7. In the Laguna panel:
    • SPEAK β†’ "Virtual output" = Laguna Translator Output
    • LISTEN β†’ "Capture" = Laguna Translator Mic (or check loopback and pick the device Discord uses)

Without VB-CABLE the app still works β€” it just won't appear "invisible" as a mic in Discord.


πŸ“ Project structure

The Python program lives in this repo (laguna_core.py, laguna_server.py, laguna_app.py, fase0_poc.py, static/ web UI, benchmark/stress scripts). The landing page (lagunatranslate.vercel.app) lives in a separate repo (LagunaTranslate-site, Next.js + Tailwind). See the Portuguese section for the full file tree.


πŸŽ› UI: what each panel does

SPEAK β€” you talk into the real mic, Laguna translates, and synthesized audio goes out through the virtual microphone Discord uses as input.

LISTEN β€” Laguna captures the audio reaching your headset (via WASAPI loopback or a paired virtual mic), translates it and plays it back in your headset.

Each panel has language selection, device selection (mic/loopback, virtual output, optional headset), a passthrough toggle, dB volume controls, an advanced block (STT model, device auto/cuda/cpu, skip same lang), and a live block with transcription + translation + p50/p95 metrics + level meters. Tooltips on everything.


🧯 Troubleshooting

CUDA not detected / falls back to CPU even with an NVIDIA GPU

Install the CUDA packages via pip into the same Python: pip install nvidia-cublas-cu12 nvidia-cudnn-cu12. On Windows, _register_cuda_dlls() registers the bin/ dirs of nvidia.cublas / nvidia.cudnn before importing faster_whisper β€” without it, ctranslate2 can't find the DLLs. Force Device β†’ cuda in the advanced block to surface the real error.

Discord doesn't hear the translation / the virtual mic is missing

Confirm VB-CABLE is installed and you rebooted. In SPEAK, "Virtual output" must be CABLE Input (renamed Laguna Translator Output). In Discord β†’ Voice & Video, Input must be CABLE Output (renamed Laguna Translator Mic). Reload the UI after renaming β€” devices only show the 🌊 mark after a refresh.

"loopback unavailable" in the LISTEN panel

WASAPI loopback needs an output device (not an input). Check "Loopback capture (WASAPI)" and pick the playback device Discord uses. If it still fails, route via VB-CABLE instead.

First phonemes cut off / short phrases vanish

The VAD uses a 300ms pre-speech buffer and a 400ms minimum segment. Very short utterances ("hi", "ok") can fall below the minimum. Tune the constants in laguna_pipeline.py (PRE_SPEECH_BUFFER_MS, MIN_SPEECH_MS).


❓ FAQ

Does my audio go to the cloud? No β€” capture, transcription, translation and synthesis all run on your machine. No API key, no external server, no telemetry.

Do I need an NVIDIA GPU? Not required. With a GPU (CUDA fp16) you stay in the ~450ms sweet spot; without one, the app falls back to CPU automatically.

Does it only work on Discord? It was built for Discord, but since it delivers translation through a virtual mic it works in any app that lets you pick the input device: Meet, Zoom, OBS, etc.

Which languages? Portuguese ↔ English, both directions and simultaneously. More pairs are on the roadmap.

Do I need VB-CABLE? Only to come in "invisible" as a mic in Discord. Without it, the app still works to test and hear translations.

Is it free? Can I fork it? Yes. MIT license: commercial, personal, fork, remix, rebrand. Just keep the copyright.


πŸ—Ί Roadmap / ideas

  • Package as a standalone .exe (PyInstaller --onedir with hooks for faster_whisper, piper, ctranslate2, nvidia.cublas, nvidia.cudnn, argostranslate β†’ Inno Setup wrapper).
  • Alternative MT backend (NLLB, M2M100) for gaming slang.
  • More language pairs (ES, FR, JP…).
  • Whisper distil-large-v3 as a premium option.
  • Optional push-to-talk.
  • Linux build (loopback via PulseAudio/PipeWire instead of WASAPI).

πŸ›  Technical notes

  • Argos pt vs pb: Argos has two Portuguese packages β€” pt (European) and pb (Brazilian). The code maps pt β†’ pb via ARGOS_CODE_MAP in laguna_pipeline.py. Whisper STT keeps using pt (the model doesn't distinguish variants).
  • CUDA DLLs on Windows: _register_cuda_dlls() finds pip-installed nvidia.cublas / nvidia.cudnn and registers their bin/ dirs before importing faster_whisper.
  • VAD β†’ segmentation: WebRTC VAD at aggressiveness 2, 30ms frames. 300ms pre-speech buffer, 600ms silence hangover, 400ms min segment, 12s max (force flush). See laguna_core.py and laguna_pipeline.py.

🀝 Contributing

This project is genuinely open-source β€” "fork it and have fun." No official roadmap, no SLA, no process. Fork, hack freely, and open a PR describing what changed and why if you think it's worth sharing. Issues with bugs/ideas welcome. No PR template, no CLA, no bureaucracy. Mutual respect, that's all.


πŸ“œ License

MIT β€” see LICENSE. Do whatever you want: commercial, personal, fork, remix, rebrand. Just keep the copyright and don't sue me if it breaks. 🀝


ConstruΓ­do com β˜• e muita fΓ© no faster-whisper.

Parte do ecossistema de projetos de Caio.

About

Tradutor Bidirecional Simultaneo de voz de ingles/portugues. Pode ser usado para conversas no Discord ou qualquer outra ferramenta do computador. Traduz a voz em tempo real.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages