feat: TTS backend abstraction + 4 'imba' features + Lua packs
Big push driven by user feedback ("делай имбу") and web research on what
voice assistants need to be the ideal:
TTS backend abstraction (P0.1)
- new module crates/jarvis-core/src/tts/{mod,sapi,piper,silero}.rs
- TtsBackend trait with SapiBackend (current PowerShell), PiperBackend
(rhasspy/piper, neural quality), SileroBackend (python subprocess)
- JARVIS_TTS env var picks (sapi|piper|silero). Auto-detect Piper if
binary + voice present in tools/piper/. Falls back to SAPI on missing.
- SpeakOpts {lang, detached, raw} replaces ad-hoc args. text_utils
sanitiser applied unless raw=true.
- llm_fallback + lua/api/tts both routed through tts::backend().
- tools/piper/install.ps1 downloads piper.exe + ru_RU-irina-medium.onnx
from rhasspy releases + huggingface. Smoke-test included.
- tools/silero/silero_tts.py helper (PyTorch); rust spawns it as subprocess.
IMBA-1 Agentic LLM router
- crates/jarvis-app/src/llm_router.rs
- When fuzzy/intent matcher fails, LLM picks the closest command from the
full registry. Returns JSON {command_id, confidence, reason}.
- Threshold-gated re-dispatch via substitute phrase. JARVIS_LLM_ROUTER=1
enables; JARVIS_LLM_ROUTER_THRESHOLD overrides 0.55 default.
- Inserted in app.rs::execute_command between "no match" and existing
llm_fallback chat fallback.
IMBA-2 Long-term memory
- crates/jarvis-core/src/long_term_memory.rs — JSON store at
APP_CONFIG_DIR/long_term_memory.json. Atomic write-through.
- remember/recall/search/forget/all/build_context API.
- Lua bindings: jarvis.memory.* (5 functions).
- llm_fallback auto-injects relevant facts (substring search of prompt)
into system message before LLM call.
- Pack resources/commands/memory_pack/ with 4 commands: remember, recall,
forget, list.
IMBA-3 Profile switching (work/game/sleep/driving/default)
- crates/jarvis-core/src/profiles.rs — JSON profiles at APP_CONFIG_DIR/profiles/
Auto-seeds 5 defaults on first run with personality + allow/deny lists +
greetings + emoji icons.
- active_profile.txt persists choice across restart.
- Lua bindings: jarvis.profile.{active,set,list,allows,active_name}.
- llm_fallback prepends profile personality to system prompt.
- Pack resources/commands/profile_switch/ with 6 voice triggers.
IMBA-4 Multimodal screenshot + vision LLM
- crates/jarvis-core/src/lua/api/vision.rs — gated on HTTP sandbox.
- jarvis.vision.screenshot() captures via PowerShell System.Drawing.
- jarvis.vision.describe(prompt?) sends base64 PNG to Groq vision model
(default llama-3.2-11b-vision-preview, override via GROQ_VISION_MODEL).
- Pack resources/commands/vision/ with 2 commands: describe + read_error.
P0.2 Continuous conversation grace window
- config::CONVERSATION_GRACE_MS = 30_000.
- app.rs: after command result, if grace_ms > 0 keep listening WITHOUT
re-wake for the grace duration. Existing CMS_WAIT_DELAY back-dated so
the existing timeout fires at start + grace_ms.
Tests: 24/24 jarvis-core unit tests pass (including 5 text_utils).
Build: cargo build --release -p jarvis-app and -p jarvis-gui both succeed
on Windows MSVC (VS 2026 Enterprise vcvars64).
Notes for setup:
- Piper voice install: pwsh tools/piper/install.ps1 (downloads ~90 MB).
- GROQ_TOKEN needed for IMBA-1 (router) and IMBA-4 (vision).
- All features are opt-in via env vars or auto-detect; existing SAPI +
fuzzy match path remains the default.
This commit is contained in:
parent
80b54af1ee
commit
0b1f1d4480
34 changed files with 2304 additions and 90 deletions
64
tools/piper/README.md
Normal file
64
tools/piper/README.md
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
# Piper TTS (neural voice for J.A.R.V.I.S.)
|
||||
|
||||
Drop-in replacement for the robotic SAPI voice. ~30 MB binary + ~60 MB Russian voice (Irina). Latency 200-500ms on i5.
|
||||
|
||||
## Install
|
||||
|
||||
```powershell
|
||||
cd C:\Jarvis\rust\tools\piper
|
||||
pwsh -File install.ps1
|
||||
```
|
||||
|
||||
By default installs `ru_RU-irina-medium` (Russian female). To pick a different voice:
|
||||
|
||||
```powershell
|
||||
pwsh -File install.ps1 -Voice ru_RU-denis-medium
|
||||
pwsh -File install.ps1 -Voice ru_RU-dmitri-medium
|
||||
pwsh -File install.ps1 -Voice ru_RU-ruslan-medium
|
||||
pwsh -File install.ps1 -Voice en_US-amy-medium # English female
|
||||
```
|
||||
|
||||
Force re-download:
|
||||
|
||||
```powershell
|
||||
pwsh -File install.ps1 -Force
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
If `piper.exe` + a voice file are present in `tools/piper/`, J.A.R.V.I.S. auto-detects Piper on startup. No env vars required.
|
||||
|
||||
To force a specific backend:
|
||||
|
||||
```bat
|
||||
set JARVIS_TTS=piper :: use Piper
|
||||
set JARVIS_TTS=sapi :: force SAPI fallback
|
||||
set JARVIS_TTS=silero :: use Silero (needs tools/silero/silero_tts.py)
|
||||
```
|
||||
|
||||
Override paths:
|
||||
|
||||
```bat
|
||||
set JARVIS_TTS_PIPER_BIN=D:\custom\piper.exe
|
||||
set JARVIS_TTS_PIPER_VOICE=D:\voices\my-voice.onnx
|
||||
```
|
||||
|
||||
## Voices catalogue
|
||||
|
||||
Full list: https://huggingface.co/rhasspy/piper-voices
|
||||
|
||||
Recommended for Russian:
|
||||
- `ru_RU-irina-medium` — natural female, default
|
||||
- `ru_RU-dmitri-medium` — male, clear diction
|
||||
- `ru_RU-ruslan-medium` — male, slightly deeper
|
||||
- `ru_RU-denis-medium` — male, "newsreader" tone
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**"piper.exe not found"** — install script failed; check `install.ps1` output. The fallback is SAPI — assistant still works, just with the robotic voice.
|
||||
|
||||
**"no .onnx voice in voices/"** — voice download failed (HuggingFace blocked?). Manually download from https://huggingface.co/rhasspy/piper-voices/tree/main/ru/ru_RU/irina/medium and drop both `.onnx` + `.onnx.json` into `voices/`.
|
||||
|
||||
**Voice sounds wrong** — try a different model. Each Russian voice has a different timbre.
|
||||
|
||||
**No audio output** — Piper writes to a temp wav, then plays via `System.Media.SoundPlayer` synchronously. Check that the default playback device isn't muted.
|
||||
108
tools/piper/install.ps1
Normal file
108
tools/piper/install.ps1
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
#requires -Version 5.1
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Download Piper TTS engine + Russian voice into tools/piper/.
|
||||
|
||||
.DESCRIPTION
|
||||
Fetches the latest piper_windows_amd64.zip from rhasspy/piper-binary and
|
||||
the Irina (ru_RU) voice .onnx + .json from huggingface rhasspy/piper-voices.
|
||||
Idempotent — skips if files already exist. Pass -Force to re-download.
|
||||
|
||||
.PARAMETER Voice
|
||||
Voice name to install. Default "ru_RU-irina-medium". Other options:
|
||||
ru_RU-denis-medium, ru_RU-dmitri-medium, ru_RU-ruslan-medium, en_US-amy-medium, ...
|
||||
|
||||
.PARAMETER Force
|
||||
Re-download even if files exist.
|
||||
|
||||
.EXAMPLE
|
||||
pwsh -File install.ps1
|
||||
pwsh -File install.ps1 -Voice ru_RU-denis-medium
|
||||
pwsh -File install.ps1 -Force
|
||||
#>
|
||||
|
||||
param(
|
||||
[string]$Voice = "ru_RU-irina-medium",
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
$InformationPreference = "Continue"
|
||||
|
||||
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||
$BinPath = Join-Path $Root "piper.exe"
|
||||
$VoiceDir = Join-Path $Root "voices"
|
||||
$VoiceFile = Join-Path $VoiceDir "$Voice.onnx"
|
||||
$VoiceJson = Join-Path $VoiceDir "$Voice.onnx.json"
|
||||
|
||||
# ─── Piper binary ──────────────────────────────────────────────────────────
|
||||
if ((Test-Path $BinPath) -and -not $Force) {
|
||||
Write-Information "[skip] piper.exe already present at $BinPath"
|
||||
} else {
|
||||
Write-Information "[fetch] piper_windows_amd64.zip..."
|
||||
$zip = Join-Path $env:TEMP "piper_windows_amd64.zip"
|
||||
$url = "https://github.com/rhasspy/piper/releases/latest/download/piper_windows_amd64.zip"
|
||||
Invoke-WebRequest -Uri $url -OutFile $zip -UseBasicParsing
|
||||
Write-Information "[unzip] -> $Root"
|
||||
Expand-Archive -Path $zip -DestinationPath $Root -Force
|
||||
# piper distributes inside a "piper/" subfolder — flatten it
|
||||
$inner = Join-Path $Root "piper"
|
||||
if (Test-Path $inner) {
|
||||
Get-ChildItem -Path $inner -Force | Move-Item -Destination $Root -Force
|
||||
Remove-Item -Path $inner -Recurse -Force
|
||||
}
|
||||
Remove-Item $zip -Force
|
||||
if (-not (Test-Path $BinPath)) {
|
||||
throw "piper.exe not found after extraction"
|
||||
}
|
||||
Write-Information "[ok] piper installed at $BinPath"
|
||||
}
|
||||
|
||||
# ─── Voice files ───────────────────────────────────────────────────────────
|
||||
if (-not (Test-Path $VoiceDir)) {
|
||||
New-Item -ItemType Directory -Path $VoiceDir | Out-Null
|
||||
}
|
||||
|
||||
# Voice naming: ru_RU-irina-medium -> lang=ru_RU, name=irina, quality=medium
|
||||
$parts = $Voice -split "-"
|
||||
if ($parts.Length -lt 3) {
|
||||
throw "Bad voice name '$Voice' — expected <lang>-<name>-<quality>"
|
||||
}
|
||||
$lang = $parts[0]
|
||||
$name = $parts[1]
|
||||
$quality = $parts[2]
|
||||
$langCode = ($lang -split "_")[0]
|
||||
|
||||
$Base = "https://huggingface.co/rhasspy/piper-voices/resolve/main/$langCode/$lang/$name/$quality"
|
||||
|
||||
foreach ($pair in @(
|
||||
@{ url = "$Base/$Voice.onnx"; out = $VoiceFile },
|
||||
@{ url = "$Base/$Voice.onnx.json"; out = $VoiceJson }
|
||||
)) {
|
||||
if ((Test-Path $pair.out) -and -not $Force) {
|
||||
Write-Information "[skip] $(Split-Path -Leaf $pair.out) already present"
|
||||
continue
|
||||
}
|
||||
Write-Information "[fetch] $($pair.url)"
|
||||
Invoke-WebRequest -Uri $pair.url -OutFile $pair.out -UseBasicParsing
|
||||
Write-Information "[ok] $(Split-Path -Leaf $pair.out) -> $($pair.out)"
|
||||
}
|
||||
|
||||
# ─── Smoke test ────────────────────────────────────────────────────────────
|
||||
$testWav = Join-Path $env:TEMP "jarvis-piper-test.wav"
|
||||
try {
|
||||
Write-Information "[test] synthesizing 'Привет, Дмитрий'..."
|
||||
"Привет, Дмитрий" | & $BinPath --model $VoiceFile --output_file $testWav 2>$null
|
||||
if ((Test-Path $testWav) -and ((Get-Item $testWav).Length -gt 1000)) {
|
||||
Write-Information "[ok] Piper works! Test wav: $testWav"
|
||||
Write-Information ""
|
||||
Write-Information "Next: set environment variable JARVIS_TTS=piper"
|
||||
Write-Information " (or just leave it unset — auto-detect will pick Piper)"
|
||||
} else {
|
||||
Write-Warning "Test wav empty or missing — synthesis may have failed"
|
||||
}
|
||||
} catch {
|
||||
Write-Warning "Smoke test failed: $_"
|
||||
} finally {
|
||||
if (Test-Path $testWav) { Remove-Item $testWav -Force }
|
||||
}
|
||||
85
tools/silero/silero_tts.py
Normal file
85
tools/silero/silero_tts.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
"""Silero TTS helper for J.A.R.V.I.S.
|
||||
|
||||
Reads text from stdin, synthesises with snakers4/silero-models, writes the result
|
||||
to a temp wav, and prints the path on stdout. The Rust side then plays + deletes it.
|
||||
|
||||
Install:
|
||||
pip install torch soundfile numpy
|
||||
|
||||
Usage (called by jarvis-core/src/tts/silero.rs):
|
||||
echo "привет" | python silero_tts.py --voice xenia
|
||||
|
||||
Voices for ru_v3:
|
||||
xenia (female, default), baya (female), aidar (male), eugene (male), kseniya (female).
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
try:
|
||||
import torch # type: ignore
|
||||
except ImportError:
|
||||
print("silero_tts: torch not installed. Run `pip install torch`.", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
|
||||
import warnings
|
||||
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
_MODEL = None
|
||||
|
||||
|
||||
def load_model(device: str = "cpu"):
|
||||
global _MODEL
|
||||
if _MODEL is None:
|
||||
torch.set_num_threads(4)
|
||||
_MODEL, _ = torch.hub.load(
|
||||
repo_or_dir="snakers4/silero-models",
|
||||
model="silero_tts",
|
||||
language="ru",
|
||||
speaker="v3_1_ru",
|
||||
trust_repo=True,
|
||||
)
|
||||
_MODEL.to(torch.device(device))
|
||||
return _MODEL
|
||||
|
||||
|
||||
def synth(text: str, voice: str, sample_rate: int = 48000) -> str:
|
||||
"""Synth text → return path to temp wav."""
|
||||
model = load_model()
|
||||
audio = model.apply_tts(text=text, speaker=voice, sample_rate=sample_rate)
|
||||
|
||||
import numpy as np
|
||||
import soundfile as sf # type: ignore
|
||||
|
||||
fd, path = tempfile.mkstemp(prefix="jarvis-silero-", suffix=".wav")
|
||||
os.close(fd)
|
||||
sf.write(path, audio.numpy().astype(np.float32), sample_rate)
|
||||
return path
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--voice", default="xenia", help="speaker name (xenia, baya, aidar, eugene, kseniya)")
|
||||
ap.add_argument("--sample-rate", type=int, default=48000)
|
||||
args = ap.parse_args()
|
||||
|
||||
text = sys.stdin.read().strip()
|
||||
if not text:
|
||||
print("silero_tts: empty input", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
try:
|
||||
path = synth(text, args.voice, args.sample_rate)
|
||||
except Exception as exc:
|
||||
print(f"silero_tts: synth failed: {exc}", file=sys.stderr)
|
||||
return 3
|
||||
|
||||
print(path)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Loading…
Add table
Add a link
Reference in a new issue