﻿# Mimi streaming frames: network chunks must be buffered before codec input

Preserve Mimi streaming frame-size requirements and cache continuity instead of forwarding arbitrary network packet lengths or reusing offline padding for each packet.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-mimi-streaming-frame-buffer-contract/
Language: en

## Identify the streaming artifact and mode

The [official Mimi model card](https://huggingface.co/kyutai/mimi) describes a neural audio codec used for speech representation. A codec supports a representation and an execution interface, not merely a bag of interchangeable audio chunks. When moving from whole-file use to streaming, record the exact implementation and mode. A successful offline encode-decode test cannot establish that an application feeds partial audio correctly while retaining causal context across successive calls.

## Inspect the frame-size requirement

The [original codec source](https://raw.githubusercontent.com/kyutai-labs/moshi/main/moshi/moshi/models/compression.py) derives frame size from sample rate and representation frame rate. Its streaming encoder requires a positive input length that is a multiple of that frame size and explicitly assigns buffering responsibility to the caller. A network message boundary has no inherent relationship to this requirement. Accumulate decoded waveform samples until a valid model input exists, and retain the remainder for a later call.

## Do not pad every transport packet independently

The source handles non-streaming input padding separately from the streaming path. Reusing that offline preparation for each packet would insert artificial samples and repeatedly alter boundaries. A stream is a continuous sample sequence, not an independent collection of complete recordings. The [integration documentation](https://huggingface.co/docs/transformers/model_doc/mimi) also distinguishes streaming behavior and caches. Follow the interface of the selected implementation rather than assuming that cache objects and padding conventions are identical across libraries.

## Diagnose packet-size-sensitive output

Consider the same recorded waveform delivered with different network packet splits. After buffering into the same valid codec frames, compare the effective model inputs and outputs. If arbitrary packetization changes inserted silence or drops samples, inspect the application's remainder buffer before tuning codec quantization. Handle stream completion with an explicit supported policy for remaining samples. This comparison diagnoses transport preparation; it does not claim mathematical equivalence between every whole-file and streaming implementation on every recording.

## Keep continuity and lifecycle explicit

Store sample rate, channels, frame size, buffering policy, codec revision, cache lifecycle, and end-of-stream handling. Guides to [audio codec representations](/journal/audio-codec-token-generation/) and [tensor axes](/journal/tensor-axes-batch-sequence-hidden/) supply background. Reset at genuine stream boundaries and preserve context within a stream. Acceptance should show consistent sample accounting under varied packet splits, rather than treating a codec that runs on one convenient packet length as a fully validated streaming audio service.
