Audio: `encode_example` fails with IndexError
Author: sanchit-gandhi
State: closed
Labels: name: bug

## Describe the bug
Loading the dataset [earnings-22](https://huggingface.co/datasets/sanchit-gandhi/earnings22_split) from the Hub yields an Index Error. I created this dataset locally and then pushed to hub at the specified URL. Thus, I expect the dataset should work out-of-the-box! Indeed, the dataset viewer functions correctly, and there were no issues when I had the dataset locally.

Don't think it's a sound file bug as the version matches what worked previously.

Update: the bug appeared for me on a GPU, mysteriously on a TPU I can't repro and it downloads correctly...

## Steps to reproduce the bug
```python
from datasets import load_dataset

earnings22 = load_dataset("sanchit-gandhi/earnings22_split")
```

## Expected results
```
>>>  earnings22
DatasetDict({
    validation: Dataset({
        features: ['source_id', 'audio', 'segment_id', 'sentence', 'start_ts', 'end_ts', 'id'],
        num_rows: 2650
    })
    train: Dataset({
        features: ['source_id', 'audio', 'segment_id', 'sentence', 'start_ts', 'end_ts', 'id'],
        num_rows: 52006
    })
    test: Dataset({
        features: ['source_id', 'audio', 'segment_id', 'sentence', 'start_ts', 'end_ts', 'id'],
        num_rows: 2735
    })
})
```

## Actual results
```
Traceback (most recent call last):
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/arrow_dataset.py", line 2764, in _map_single
    writer.write(example)
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/arrow_writer.py", line 451, in write
    self.write_examples_on_file()
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/arrow_writer.py", line 409, in write_examples_on_file
    self.write_batch(batch_examples=batch_examples)
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/arrow_writer.py", line 508, in write_batch
    arrays.append(pa.array(typed_sequence))
  File "pyarrow/array.pxi", line 231, in pyarrow.lib.array
  File "pyarrow/array.pxi", line 110, in pyarrow.lib._handle_arrow_array_protocol
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/arrow_writer.py", line 197, in __arrow_array__
    out = cast_array_to_feature(out, type, allow_number_to_str=not self.trying_type)
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/table.py", line 1683, in wrapper
    return func(array, *args, **kwargs)
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/table.py", line 1795, in cast_array_to_feature
    return feature.cast_storage(array)
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/features/audio.py", line 190, in cast_storage
    storage = pa.array([Audio().encode_example(x) if x is not None else None for x in storage.to_pylist()])
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/features/audio.py", line 190, in <listcomp>
    storage = pa.array([Audio().encode_example(x) if x is not None else None for x in storage.to_pylist()])
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/datasets/features/audio.py", line 92, in encode_example
    sf.write(buffer, value["array"], value["sampling_rate"], format="wav")
  File "/opt/conda/envs/hf/lib/python3.8/site-packages/soundfile.py", line 313, in write
    channels = data.shape[1]
IndexError: tuple index out of range
```

## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version: 2.4.0
- Platform: Linux-4.19.0-21-cloud-amd64-x86_64-with-glibc2.10
- Python version: 3.8.13
- PyArrow version: 9.0.0
- Pandas version: 1.4.3

Plus:
- SoundFile version: 0.10.3.post1

cc @lhoestq @polinaeterna 

Comments: Sorry bug on my part 😅 Closing