Engineering BlueprintAILocal AIFastAPIOllamaWhisperTTSSpeakOnReliability

SpeakOn Phase 1: Modular Local AI Pipeline Under 1.3s and 6 GB VRAM on an RTX 3070

Engineering the modular STT -> LLM -> TTS + VAD pipeline for SpeakOn using faster-whisper, Ollama, Kokoro-82M, MIT Piper, and Silero VAD within an 8 GB VRAM…

Célio Vieira604 words4 min read

Key Takeaways (TL;DR)

Summary
  • Measuring Real 8 GB VRAM Co-Residency Instead of Guessing — Running a full conversational voice pipeline (faster-whisper -> Ollama -> Kokoro/Piper + Silero VAD) concurrently…
  • Architecture: Pluggable Protocols, Shared GPU Weights, and CPU Offload — Every AI stage sits behind a strict interface in app/*/base.py, paired with deterministic in-memory…
  • What the RTX 3070 Benchmark Actually Measured — Initial benchmarks uncovered three empirical realities on an active Linux workstation (~0.86–1.21 GB desktop VRAM baseline…

Measuring Real 8 GB VRAM Co-Residency Instead of Guessing#

Running a full conversational voice pipeline (faster-whisper -> Ollama -> Kokoro/Piper + Silero VAD) concurrently on a single 8 GB RTX 3070 looks straightforward on paper until real hardware measurements expose where the memory and milliseconds go.

In Phase 1 of SpeakOn, we built clean Python Protocol interfaces behind app/stt/, app/llm/, app/tts/, and app/vad/, cached open-source weights locally, and built an automated NVML + end-to-end latency benchmark (scripts/bench_turn.py) that forced several concrete architectural improvements.

Architecture: Pluggable Protocols, Shared GPU Weights, and CPU Offload#

Every AI stage sits behind a strict interface in app/*/base.py, paired with deterministic in-memory fakes in tests/fakes.py so GitHub Actions executes unit and contract tests without a GPU:

  1. STT (app/stt/faster_whisper.py): Decodes arbitrary browser/mobile audio (WAV, WebM, Opus, M4A) to 16 kHz mono float32 in memory via PyAV (av)—removing any external ffmpeg binary dependency—and runs faster-whisper-small (int8_float16) with word-level timestamps and confidence probabilities.
  2. LLM (app/llm/): Talks to host ollama serve via httpx.AsyncClient(trust_env=False) with JSON-schema enforcement (TutorReply), delimiter-isolated user utterances (<user_utterance>), one automated JSON-repair pass, and deterministic pypinyin tone-mark validation on every Mandarin turn.
  3. Multilingual TTS Router (app/tts/): Shares a single Kokoro-82M KModel instance across six language KPipeline instances (en, es, zh, fr, it, pt) to avoid duplicating ~0.3 GB of weights per language, chunks CJK (。!?) and Latin punctuation without splitting short exclamations, caches synthesized WAV files atomically on disk by SHA-256, and falls back to CPU Piper (de primary and zero-VRAM fallback).
  4. Streaming VAD (app/vad/silero.py): Runs Silero VAD (VADIterator, 16 kHz, 600 ms silence threshold) single-threaded on CPU (0 additional GPU VRAM).

What the RTX 3070 Benchmark Actually Measured#

Initial benchmarks uncovered three empirical realities on an active Linux workstation (~0.86–1.21 GB desktop VRAM baseline and OLLAMA_MODELS stored on a SATA HDD):

  • Cold HDD Loading vs. Steady-State Turns: Loading multi-gigabyte GGUF blobs from an HDD took ~50–90 seconds on the first turn (tripping a 45 s timeout), whereas keep_alive=30m kept warm turns fast. Raising SPEAKON_LLM_TIMEOUT_SEC to 120.0 prevents cold-start timeouts.
  • qwen3.5-fast:9b vs. llama3.1:latest Co-Residency: Co-resident alongside faster-whisper-small and Kokoro, qwen3.5-fast:9b (6.2 GB) spilled 35% of its layers to CPU RAM, pushing total turn latency to 6.68 s (7.27 GB total VRAM). By contrast, llama3.1:latest (4.9 GB, num_ctx=4096, num_predict=180) stayed 88% on GPU and delivered 1,212.7 ms total uncached turn latency (stt: 142.3 ms, llm: 988.1 ms, tts: 82.3 ms) at 5.882 GB SpeakOn VRAM delta (7.088 GB peak). SpeakOn defaults real-time voice turns to llama3.1:latest while exposing qwen3.5:9b and qwen3.5-fast:9b for Mandarin & deep Studio coaching.
  • MIT Piper 2023.11.14-2 Phoneme Guardrail: To keep the Apache-2.0 repository free of GPL-3.0 piper-tts >= 1.3, we pinned the archived MIT standalone piper binary (2023.11.14-2, SHA-256 verified) and discovered it aborts (Phonemes must be one codepoint) on newer diphthong ONNX configs (['aɪ', 'aʊ', ...]). Selecting single-codepoint MIT voices from rhasspy/piper-voices enabled reliable CPU synthesis across all seven languages.

Security & Reliability Hardening#

  • Prompt-Injection Delimiters & Schema Repair: Untrusted learner transcripts are sanitized and wrapped inside <user_utterance> delimiters, validated against TutorReply JSON Schema, and protected by 5-failure / 30 s circuit breakers (app/core/resilience.py), per-stage timeouts (30 s STT, 120 s LLM, 20 s TTS), and tenacity retries.
  • Zero-Leak CUDA & Model Hygiene: app/core/cuda.py resolves nvidia.cublas / nvidia.cudnn wheel shared libraries dynamically via LD_LIBRARY_PATH and RTLD_GLOBAL, keeping model weights in git-ignored SPEAKON_HF_HOME and audio caches under git-ignored data/.
  • Verification: 18/18 CPU unit tests (ruff, mypy --strict, OpenAPI drift check) and 9/9 GPU regression & 7-language synthetic-TTS round-trip STT tests (en, es, zh, pt, de, it, fr, plus Silero VAD) passed on the RTX 3070.
Célio Vieira

Célio Vieira

Founder & Architect

Engineering applied AI systems, distributed cloud platforms, and the Aldeon umbrella venture ecosystem.

Related Technical Dispatches

View all 90