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:
javis-bot
2026-11-11 11:57:53 +09:00
parent 8479112ddd
commit f25c26cf53
54 changed files with 8454 additions and 5135 deletions

43
app/src/log.rs Normal file
View File

@@ -0,0 +1,43 @@
//! Debug logging, the Rust side of `src/jarvis/debug.py`.
//!
//! On only when `JARVIS_DEBUG=1`. Messages carry ids, sizes, counts and timings, never what anyone
//! said or wrote (no transcripts, no chat text, no reply text).
use std::sync::OnceLock;
pub fn debug_enabled() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var("JARVIS_DEBUG").as_deref() == Ok("1"))
}
/// `[ category ] message`, the category centred in 10 columns like the Python `debug_log`.
pub fn line(category: &str, message: &str) -> String {
format!("[{category:^10}] {message}")
}
#[macro_export]
macro_rules! debug_log {
($cat:expr, $($arg:tt)*) => {
if $crate::log::debug_enabled() {
eprintln!("{}", $crate::log::line($cat, &format!($($arg)*)));
}
};
}
/// Errors are always printed; the same rule applies: no transcript or chat text in the message.
#[macro_export]
macro_rules! error_log {
($cat:expr, $($arg:tt)*) => {
eprintln!("[{}] ERROR {}", $cat, format!($($arg)*));
};
}
#[cfg(test)]
mod tests {
#[test]
fn category_is_centred_like_python() {
// Python: f"[{'voice':^10}]" == "[ voice ]"
assert_eq!(super::line("voice", "x"), "[ voice ] x");
assert_eq!(super::line("worker", "x"), "[ worker ] x");
}
}