Full-Duplex Speech-to-Speech Systems: Parallel Audio-Text Streams (Moshi), Inner Monologue & WebSocket Barge-In
Traditional voice assistants chain three separate models across rigid turn boundaries: an Automatic Speech Recognition (ASR) transcriber, a text LLM, and a Text-to-Speech (TTS) synthesizer. That cascaded pipeline suffers from two fatal flaws in real-world clinical and conversational deployments: (1) multi-second end-of-turn VAD latency ($1.5\text{–}3.0\,\text{s}$), and (2) state desynchronization on user barge-in – when the user interrupts the assistant mid-sentence, the server's LLM context still contains the full unuttered text buffer that never actually played through the user's speaker!
Moshi (Défossez et al., 2024, arXiv:2410.00037; GitHub) and modern full-duplex /ws/live audio proxies eliminate turn-taking altogether by modeling the user's incoming audio stream and the assistant's outgoing audio stream as joint parallel token sequences at $12.5\,\text{Hz}$ ($80\,\text{ms}$ frames), prefixed by a time-aligned semantic text stream (Inner Monologue).
0. Joint Dual-Stream Autoregression & Inner Monologue Prefixing
At each $80\,\text{ms}$ frame step $t$, a neural audio codec (such as Mimi with $Q = 8$ Residual Vector Quantization codebooks) encodes both the user's microphone audio $U_t = (u_{t,1}, \dots, u_{t,Q})$ and the system's generated audio $S_t = (s_{t,1}, \dots, s_{t,Q})$. Rather than predicting $Q$ acoustic tokens flatly across sequence length, an RQ-Transformer splits autoregression into a Temporal Transformer across frame index $t$ and a tiny Depth Transformer across codebook level $q \in \{0, \dots, Q\}$:
By predicting the time-aligned text token $w_t$ (or a PAD/EPAD silence token) at depth step $q=0$ before sampling the semantic and acoustic RVQ tokens $s_{t, 1..Q}$ in the Depth Transformer, the model anchors its spoken prosody in linguistic reasoning while keeping theoretical frame latency at $80\,\text{ms}$ ($160\text{–}200\,\text{ms}$ end-to-end).
Moshi & /ws/live Proxies):
(1) Phantom Context after Barge-In Queue Flush: Because GPU inference generates audio chunks faster than $1\times$ wall-clock playback, flushing the browser's AudioWorklet ring buffer on interruption drops frames $[t_{\text{ack}} + 1, t_{\text{gen}}]$. Your /ws/live proxy must track client playback_frame_ack heartbeats and truncate the KV-cache position pointer back to $t_{\text{ack}}$ before ingesting the barge-in audio!
(2) Acoustic Codebook Delay Pattern: In Moshi, acoustic codebooks $q \in \{2..Q\}$ are delayed by $\tau_q = 1\text{–}2$ steps relative to the semantic codebook $q=1$ to improve intra-frame coherence – forgetting to shift the delay ring buffer during KV rollback misaligns residual quantizer levels and produces metallic click artifacts.
1. Runnable Python Reference: Full-Duplex Barge-In State Machine & KV-Cache Rollback
The self-contained Python script below implements the server-side full-duplex audio ring buffer and KV-cache rollback controller, verifying exact state synchronization when a user interrupts mid-utterance:
💻 Python: Full-Duplex WebSocket Audio Proxy & Barge-In KV-Cache RollbackPython
from dataclasses import dataclass, field
import numpy as np
@dataclass
class FullDuplexSession:
"""Server-side state machine for 12.5 Hz (80ms) dual-stream speech-to-speech with KV rollback."""
frame_hz: float = 12.5
d_kv: int = 16
kv_cache: list[np.ndarray] = field(default_factory=list)
inner_monologue_tokens: list[str] = field(default_factory=list)
outbound_audio_queue: list[int] = field(default_factory=list)
client_playback_ack: int = 0
def step_generation(self, text_tok: str, kv_vec: np.ndarray) -> int:
self.kv_cache.append(kv_vec)
self.inner_monologue_tokens.append(text_tok)
frame_id = len(self.kv_cache)
self.outbound_audio_queue.append(frame_id)
return frame_id
def handle_user_barge_in(self, client_ack_frame: int) -> dict[str, int]:
"""Flush unheard audio frames > client_ack_frame and roll back KV-cache & text history."""
gen_cursor_before = len(self.kv_cache)
flushed_frames = gen_cursor_before - client_ack_frame
# 1. Flush unplayed outbound audio frames from WebSocket transmit queue
self.outbound_audio_queue = [f for f in self.outbound_audio_queue if f <= client_ack_frame]
# 2. Truncate KV-cache and Inner Monologue transcript to exact heard timestamp
self.kv_cache = self.kv_cache[:client_ack_frame]
self.inner_monologue_tokens = self.inner_monologue_tokens[:client_ack_frame]
self.client_playback_ack = client_ack_frame
return {
"gen_before": gen_cursor_before,
"rolled_back_to": len(self.kv_cache),
"flushed_ms": int(flushed_frames * (1000.0 / self.frame_hz)),
}
if __name__ == "__main__":
rng = np.random.default_rng(42)
session = FullDuplexSession()
for t in range(1, 46): # Server generates 45 frames (3.60s) of speech ahead of playback
session.step_generation(f"tok_{t}", rng.standard_normal(16))
# User interrupts when client speaker has only played up to frame 20 (1.60s)
stats = session.handle_user_barge_in(client_ack_frame=20)
print(f"[PASS] Server Cursor Before Barge-In : Frame {stats['gen_before']} (3600 ms)")
print(f"[PASS] KV-Cache Rolled Back To : Frame {stats['rolled_back_to']} (1600 ms)")
print(f"[PASS] Flushed Unheard Speculative Ms: {stats['flushed_ms']} ms (Zero Phantom Context!)")
# Output:
# [PASS] Server Cursor Before Barge-In : Frame 45 (3600 ms)
# [PASS] KV-Cache Rolled Back To : Frame 20 (1600 ms)
# [PASS] Flushed Unheard Speculative Ms: 2000 ms (Zero Phantom Context!)
2. Real-Time Conversational Voice Architectures: Head-to-Head
| Architecture | Cascaded ASR → LLM → TTS | Textless Audio LM (GSLM) | Dual-Stream + Inner Monologue (Moshi) |
|---|---|---|---|
| End-to-End Turn Latency | $1500\text{–}3200\,\text{ms}$ (VAD endpointing bottleneck) | $200\text{–}400\,\text{ms}$ | $160\text{–}200\,\text{ms}$ ($80\,\text{ms}$ Mimi codec stride) |
| Linguistic & Reasoning IQ | High (text LLM backbone) | Collapses on multi-step reasoning | High (time-aligned Inner Monologue text prefix $w_t$) |
| Overlapping Speech & Barge-In | Requires hard VAD cut + manual transcript diff | Single-stream turn-based | Native parallel $(U_t, S_t)$ streams + exact KV frame rollback |