diff --git a/soundfile.py b/soundfile.py index 9758a9f..843d0ab 100644 --- a/soundfile.py +++ b/soundfile.py @@ -1379,10 +1379,11 @@ def _check_dtype(self, dtype): def _array_io(self, action, array, frames): """Check array and call low-level IO function.""" - if (array.ndim not in (1, 2) or - array.ndim == 1 and self.channels != 1 or - array.ndim == 2 and array.shape[1] != self.channels): - raise ValueError("Invalid shape: {0!r}".format(array.shape)) + if array.ndim not in (1,2): + raise ValueError("Invalid shape: {0!r} ({1})".format(array.shape, "0 dimensions not supported" if array.ndim < 1 else "too many dimensions")) + array_channels = 1 if array.ndim == 1 else array.shape[1] + if array_channels != self.channels: + raise ValueError("Invalid shape: {0!r} (Expected {1} channels, got {2})".format(array.shape, self.channels, array_channels)) if not array.flags.c_contiguous: raise ValueError("Data must be C-contiguous") ctype = self._check_dtype(array.dtype.name)