{"record":{"id":"32428d8796205928","repo":"microsoft/VibeVoice","slug":"unexpected-audio-shape-audio-shape","errorCode":null,"errorMessage":"Unexpected audio shape: {audio.shape}","messagePattern":"Unexpected audio shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vibevoice/processor/vibevoice_tokenizer_processor.py","lineNumber":89,"sourceCode":"            \n        Returns:\n            np.ndarray: Mono audio array\n        \"\"\"\n        if len(audio.shape) == 1:\n            return audio\n        elif len(audio.shape) == 2:\n            if audio.shape[0] == 2:  # (2, time)\n                return np.mean(audio, axis=0)\n            elif audio.shape[1] == 2:  # (time, 2)\n                return np.mean(audio, axis=1)\n            else:\n                # If one dimension is 1, squeeze it\n                if audio.shape[0] == 1:\n                    return audio.squeeze(0)\n                elif audio.shape[1] == 1:\n                    return audio.squeeze(1)\n                else:\n                    raise ValueError(f\"Unexpected audio shape: {audio.shape}\")\n        else:\n            raise ValueError(f\"Audio should be 1D or 2D, got shape: {audio.shape}\")\n    \n    def _process_single_audio(self, audio: Union[np.ndarray, List[float]]) -> np.ndarray:\n        \"\"\"\n        Process a single audio array.\n        \n        Args:\n            audio: Single audio input\n            \n        Returns:\n            np.ndarray: Processed audio\n        \"\"\"\n        # Convert to numpy array\n        if not isinstance(audio, np.ndarray):\n            audio = np.array(audio, dtype=np.float32)\n        else:\n            audio = audio.astype(np.float32)","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/microsoft/VibeVoice/blob/94da20d98b2fa7688e9cbfaf7692ddb4954f7600/vibevoice/processor/vibevoice_tokenizer_processor.py#L71-L107","documentation":"_to_mono (the 2D branch of audio normalization) accepts exactly three 2D layouts: (2, time) and (time, 2) stereo (averaged to mono) and squeezable (1, time)/(time, 1). A 2D array that is neither stereo nor single-channel along either axis — e.g. (3, 5000) or (256, 100) — is ambiguous (is time on rows or columns? is it 3-channel?) and is rejected rather than guessed at.","triggerScenarios":"Passing a 2D audio array whose second dimension is neither 2 nor 1 and first dimension neither 2 nor 1 — commonly mel-spectrogram-shaped (n_mels, frames) input, or multi-channel (3+) audio arrays.","commonSituations":"Feeding precomputed features (log-mel frames) where raw waveforms were expected; microphones arrays with >2 channels; accidentally stacking a batch into one array, producing (batch, time) with batch > 2.","solutions":["Pass raw 1D mono waveforms: reduce stereo yourself with np.mean(audio, axis=0/1) or slice one channel.","If you meant a batch, pass a Python list of 1D arrays instead of a stacked 2D array.","Keep the batch dim out of the array handed to _to_mono; batching is handled one level up in __call__."],"exampleFix":"# before\naudio = np.stack([wav_a, wav_b, wav_c])  # (3, time) -> ValueError\nenc = processor(audio=audio)\n\n# after\nenc = processor(audio=[wav_a, wav_b, wav_c])  # list -> batched input","handlingStrategy":"validation","validationCode":"import numpy as np\ndef to_mono_1d(a: np.ndarray) -> np.ndarray:\n    a = np.asarray(a)\n    if a.ndim == 1:\n        return a\n    if a.ndim == 2 and 1 in a.shape:\n        return a.reshape(-1)\n    if a.ndim == 2 and 2 in a.shape:\n        return a.mean(axis=0 if a.shape[0] == 2 else 1)\n    raise ValueError(f'cannot interpret shape {a.shape} as mono audio')","typeGuard":"def is_interpretable_audio(a) -> bool:\n    import numpy as np\n    a = np.asarray(a)\n    return a.ndim == 1 or (a.ndim == 2 and (1 in a.shape or 2 in a.shape))","tryCatchPattern":"try:\n    enc = processor(audio=audio)\nexcept ValueError as e:\n    if 'Unexpected audio shape' in str(e):\n        enc = processor(audio=np.asarray(audio).mean(axis=-1))  # explicit mono mixdown\n    else:\n        raise","preventionTips":["Reduce audio to 1D mono before passing it in; do stereo mixdown yourself.","Pass batches as lists of 1D arrays, never stacked 2D/3D ndarrays.","Don't feed spectrograms or feature matrices where waveforms are expected."],"tags":["audio","shape","mono","input-validation"],"backgroundTag":null,"analyzedSha":"94da20d98b2fa7688e9cbfaf7692ddb4954f7600","analyzedAt":"2026-08-15T04:12:07.418Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}