Refinements on the Kyutai STT integration after debugging session:
- dtype: BF16 on accelerators (matches checkpoint storage), F32 on CPU.
Previously F16 on Metal which can overflow in the LM's RmsNorm.
- examples/stt_demo: pad input with 0.5s silence suffix per the HF
stt_config.audio_delay_seconds, matching the Python reference loop.
- src/stt.rs: tightened module docs with debugging notes for the
remaining all-pad-output issue. Removed RTX_STT_DEBUG callback path
(was useful for one-off debugging; can be re-added with cleaner shape).
Status: weights load cleanly, LM forward advances every frame, but
predictions are all-pad on real speech. Bisection plan documented in
the module rustdoc — next session should diff against the official
delayed-streams-modeling Python reference at frame-by-frame granularity.
77 lib tests + 2 stt tests all pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Integrates the moshi crate (0.6.4, candle 0.9.1) for streaming STT.
Module + demo + custom config for kyutai/stt-1b-en_fr. Model loads
cleanly, LM forward pass advances (model_step_idx increments correctly),
but word events don't yet emit on a 10s CSM speech sample.
What works:
- moshi 0.6.4 added as dependency (candle 0.9.1, version-compatible)
- src/stt.rs wraps moshi::asr::State + moshi::lm + moshi::mimi
- Stt::load_default downloads kyutai/stt-1b-en_fr (~3 GB) from HF
- Custom config_stt_1b_en_fr() matching the released checkpoint:
d_model=2048, num_layers=16, dim_feedforward=8192 (moshi's SwiGLU
hidden = 11/4 * d_model = 5632 — verified vs safetensors), text vocab
8001/8000, audio vocab 2049, 32 codebooks, no depformer
- AsrEvent enum + From<moshi::asr::AsrMsg> conversion
- examples/stt_demo.rs streams a WAV through the pipeline
- 2 unit tests for AsrEvent conversion
What needs more work:
- Word emission: 0 words detected on 10s of clean CSM speech, even
though LM forward advances every frame. Likely culprits:
a) asr_delay_in_tokens 6 vs HF stt_config.audio_delay_seconds=0.5
(6.25 frames). Off-by-one possible.
b) Sentencepiece detok not yet wired (tokens emitted but text=None).
c) Subtle weight-key remap differences between moshi's expected
layout and the released checkpoint that don't trip a shape check.
d) renormalize/audio preprocessing mismatch.
Next step (Phase 6a polish): compare against the official
delayed-streams-modeling/scripts/stt_from_file_pytorch.py reference to
identify the missing piece. The integration framework is sound; only
the final LM-output-to-text-event step needs work.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Watermarker trait gains embed_with_message(audio, message) with a
default impl forwarding to embed (no-op for watermarkers without a
payload). AudioSealWatermarker overrides to use the requested message
instead of self.message; ResampledWatermarker forwards through the
resample dance.
TtsRequest gains optional watermark_message: Option<String> (decimal or
0xHEX). Useful for clawsample to tag each generation with a unique ID
(e.g. job_id mod 0x10000) for audit trails. When omitted, falls back
to the server-startup --audioseal-message default.
Verified end-to-end: override "0xBEEF" -> detect 0xBEEF (mean_presence
0.9995, 16/16 bits). Default fallback also decodes correctly.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Two real bugs found via code inspection against HF source:
1. candle's .gelu() is the tanh approximation; PyTorch's default 'gelu'
activation (used in WavLM via ACT2FN['gelu']) is the exact erf-based
version. Switched all 3 sites (feature extractor convs, pos_conv,
FFN) from .gelu() to .gelu_erf() to match the reference.
2. gru_rel_pos_const lookup used vb.pp("name").get(shape, "") which
resolves to "<prefix>.name." (trailing dot) and fails to find the
tensor. The .or_else(|_| zeros) silently swallowed the failure,
leaving all 12 layers' gating constants at zero instead of the
trained values. Fixed to attn.get(shape, "gru_rel_pos_const") which
resolves correctly.
examples/wavlm_sv_inspect.rs: utility for sanity-checking specific
tensors inside converted safetensors (e.g. layer_weights).
Same-content same-speaker cosine: 0.9985 -> 0.9963 (≈unchanged).
Cross-content same-speaker cosine: 0.4882 -> 0.4118 (still drifting).
Phase 5d (Python reference comparison) remains the gate for
identifying the residual numerical drift.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Adds the long-form analogue of generate_to_wav. generate_long previously
returned raw PCM and bypassed the Generator-bound watermarker hook,
meaning long-form output skipped watermarking entirely if installed.
generate_long_to_wav mirrors generate_to_wav exactly:
chunked-generation -> post-process -> watermark -> WAV write.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Wraps the WavLM-SV port from Phase 5c. Full 100M-param X-vector head
running in-process; previously returned a typed error.
- WavLmSimilarity::load(path, device) loads converted safetensors.
- WavLmSimilarity::embed(samples) caches a 512-d embedding for repeat
comparisons.
- score(a, b) embeds both inputs and cosines them.
- Module docs updated; SpectralCentroidSimilarity kept as a weak-baseline
check.
Caller-facing change: any code using the SpeakerSimilarity trait now
gets a real speaker model with one constructor swap.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
A single \`generate\` invocation now produces a watermarked WAV when
AudioSeal weights are passed via CLI. End-to-end verified on real CSM
speech: mean_presence=1.0000, 16/16 message bits decoded.
- Generator gains \`watermarker: Option<Box<dyn Watermarker>>\` slot;
\`generate_to_wav\` runs \`wm.embed(&pcm)\` after post-process, before
WAV write. Field is Send+Sync so the existing Arc<Mutex<Generator>>
tts_server pattern still works.
- watermark.rs ships ResampledWatermarker<W> adapter for handling rate
mismatches (CSM 24 kHz ↔ AudioSeal 16 kHz). Output length is normalized
to input length so it's a transparent drop-in.
- examples/generate.rs gains --watermark-generator/--watermark-detector/
--watermark-message flags. Loads AudioSeal, wraps in resampler, installs.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>