refactor(app): rewrite the M2 Discord voice core in Rust
The user asked for a faster, real app instead of Electron. The app is now a Rust crate (serenity + songbird); the GUI in M5 will be a Tauri 2 shell on the system WebView2. - Same behaviour as the Electron core: one voice channel, per-speaker PCM to the voice worker, speaking_end and speaker_leave, sentence playback with stop and cancel, transcription notice on join, slash command join/leave/stop (create-or-update), registered chat channels with live events, history and sends that never ping, worker process with a fresh token and restart backoff. - songbird 0.6.1 garbles about a third of received frames under DAVE (its decoder keeps the bytes DAVE decryption leaves at the end of the payload; a 20 ms stepped test tone showed repeats, skips and reordering, while sending was exact). songbird now only decrypts; the core reorders packets in a small window (Opus FEC for the last lost frame) and decodes them with libopus itself. - Live test on real Discord with two bots: five sentences heard (CER 0/0/0/5/12.5%), 0.71-0.90 s from end of speech to final, speech read back at 3.4%, sound gone 0.08 s after stop. The release binary uses about 16 MB of memory; a Windows build (MinGW) logs in under Wine. - Spec moved to app/src/discord_core.spec.md; architecture, decisions, roadmap and pc-features updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
49
app/src/main.rs
Normal file
49
app/src/main.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
//! Jarvis app (headless until the Tauri GUI arrives in M5): jarvis-app <data folder>
|
||||
//! The data folder can also come from JARVIS_DATA_DIR; the bot token from JARVIS_DISCORD_TOKEN.
|
||||
|
||||
use jarvis_app::discord::CoreEvent;
|
||||
use jarvis_app::services::start_services;
|
||||
use jarvis_app::{debug_log, error_log};
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let data_dir = std::env::args().nth(1).or_else(|| std::env::var("JARVIS_DATA_DIR").ok());
|
||||
let Some(data_dir) = data_dir else {
|
||||
error_log!("app", "usage: jarvis-app <data folder> (or set JARVIS_DATA_DIR)");
|
||||
std::process::exit(2);
|
||||
};
|
||||
let mut services = match start_services(std::path::Path::new(&data_dir)).await {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
error_log!("app", "could not start: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
loop {
|
||||
tokio::select! {
|
||||
ev = services.events.recv() => match ev {
|
||||
// The brain (M3) consumes these; for now only their shape is logged, never the text.
|
||||
Some(CoreEvent::Final(f)) => debug_log!("app", "heard {} utt={} chars={}", f.heard.speaker_id, f.heard.utt, f.text.chars().count()),
|
||||
Some(_) => {}
|
||||
None => break,
|
||||
},
|
||||
_ = shutdown_signal() => break,
|
||||
}
|
||||
}
|
||||
services.stop().await;
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let mut term = tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate()).expect("signal");
|
||||
tokio::select! {
|
||||
_ = tokio::signal::ctrl_c() => {}
|
||||
_ = term.recv() => {}
|
||||
}
|
||||
}
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let _ = tokio::signal::ctrl_c().await;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user