Push-to-Talk Latency Timer (src/timing.rs)

jcode · crates/jcode-voice/src/timing.rs · rust · MIT
voice, dev-tools, lang:rust, tag:timing, tag:latency

Opt-in debug timing utility that logs millisecond-precision stage marks for voice push-to-talk latency, gated by JCODE_VOICE_TIMING env var without exposing audio or transcripts.

// Source: https://github.com/1jehuang/jcode | License: MIT | Copyright 2025 Jeremy Huang
// Provided via justclaw.it.com; keep this notice with the code.
//! Opt-in push-to-talk latency marks. Enable with `JCODE_VOICE_TIMING=1`.
//! Prints only stage names and milliseconds since the press (and since the
//! release once it happens), never audio, transcripts, or credentials.
use std::sync::{Mutex, OnceLock};
use std::time::Instant;

static ORIGIN: Mutex<Option<Instant>> = Mutex::new(None);
static RELEASE: Mutex<Option<Instant>> = Mutex::new(None);

pub fn enabled() -> bool {
    static ON: OnceLock<bool> = OnceLock::new();
    *ON.get_or_init(|| std::env::var_os("JCODE_VOICE_TIMING").is_some_and(|v| v != "0"))
}

/// Starts a new attempt. Call at the user's press.
pub fn begin() {
    if e

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key