{"record":{"id":"dcc534ce74bc9f1d","repo":"microsoft/VibeVoice","slug":"audio-should-be-1d-or-2d-got-shape-audio-shape","errorCode":null,"errorMessage":"Audio should be 1D or 2D, got shape: {audio.shape}","messagePattern":"Audio should be 1D or 2D, got shape: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"vibevoice/processor/vibevoice_tokenizer_processor.py","lineNumber":91,"sourceCode":"            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)\n        \n        # Ensure mono","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/microsoft/VibeVoice/blob/94da20d98b2fa7688e9cbfaf7692ddb4954f7600/vibevoice/processor/vibevoice_tokenizer_processor.py#L73-L109","documentation":"The mono-conversion helper only handles 1D (time,) and 2D arrays. Any array with 3 or more dimensions — (batch, channels, time), (batch, time, 1), etc. — hits the outer else and is rejected. Batch/channel handling is the caller's job (__call__ accepts a list of arrays for batching), so a 3D array means the batching convention was violated.","triggerScenarios":"Passing a batched tensor-style array of shape (B, T) squeezed from (B, 1, T), or (B, C, T) multi-channel batches, directly as a single audio input.","commonSituations":"Converting a torch tensor of shape (B, 1, T) with .numpy() and feeding it unchanged; datasets that yield (clip, channel, time) containers; voice-cloning code that stacks prompt + target audio into one ndarray.","solutions":["Unbatch before calling: pass [a[0] for a in arr] or arr[:, 0, :] reduced per-sample as a list of 1D arrays.","Squeeze channel dims per sample: audio = audio.reshape(audio.shape[0], -1) only if channels are genuinely 1.","Keep individual samples 1D (time,) and let the processor's list handling do batching."],"exampleFix":"# before\nenc = processor(audio=batched_np)  # shape (4, 1, 24000) -> ValueError\n\n# after\nenc = processor(audio=[s.squeeze() for s in batched_np])","handlingStrategy":"validation","validationCode":"import numpy as np\ndef as_audio_list(a):\n    a = np.asarray(a)\n    if a.ndim == 1:\n        return [a]\n    if a.ndim in (2, 3) and a.shape[0] > 1:  # treat leading dim as batch\n        return [np.asarray(s).reshape(-1) for s in a]\n    return [a.reshape(-1)]\nenc = processor(audio=as_audio_list(raw))","typeGuard":"def is_1d_or_2d_audio(a) -> bool:\n    import numpy as np\n    return np.asarray(a).ndim <= 2","tryCatchPattern":"try:\n    enc = processor(audio=raw)\nexcept ValueError as e:\n    if '1D or 2D' in str(e):\n        enc = processor(audio=[np.asarray(s).squeeze() for s in raw])  # unbatch\n    else:\n        raise","preventionTips":["Squeeze channel dims and unbatch per sample before calling the processor.","Pass a list of 1D waveforms for batched input instead of an (B,C,T) ndarray.","Assert ndim <= 2 on tensors converted from torch before handoff."],"tags":["audio","shape","ndim","input-validation"],"backgroundTag":null,"analyzedSha":"94da20d98b2fa7688e9cbfaf7692ddb4954f7600","analyzedAt":"2026-08-15T04:12:07.418Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}