Title: Load audio dataset error
Author: lemoner20 (NONE)
State: closed
Created: 2022-03-08T02:16:04Z
Labels: bug

## Load audio dataset error

Hi, when I load audio dataset following https://huggingface.co/docs/datasets/audio_process and https://github.com/huggingface/datasets/tree/master/datasets/superb,
```
from datasets import load_dataset, load_metric, Audio
raw_datasets = load_dataset("superb", "ks", split="train")
print(raw_datasets[0]["audio"])
```
following errors occur 
```
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-169-3f8253239fa0> in <module>
----> 1 raw_datasets[0]["audio"]

/usr/lib/python3.6/site-packages/datasets/arrow_dataset.py in __getitem__(self, key)
   1924         """Can be used to index columns (by string names) or rows (by integer index or iterable of indices or bools)."""
   1925         return self._getitem(
-> 1926             key,
   1927         )
   1928 

/usr/lib/python3.6/site-packages/datasets/arrow_dataset.py in _getitem(self, key, decoded, **kwargs)
   1909         pa_subtable = query_table(self._data, key, indices=self._indices if self._indices is not None else None)
   1910         formatted_output = format_table(
-> 1911             pa_subtable, key, formatter=formatter, format_columns=format_columns, output_all_columns=output_all_columns
   1912         )
   1913         return formatted_output

/usr/lib/python3.6/site-packages/datasets/formatting/formatting.py in format_table(table, key, formatter, format_columns, output_all_columns)
    530     python_formatter = PythonFormatter(features=None)
    531     if format_columns is None:
--> 532         return formatter(pa_table, query_type=query_type)
    533     elif query_type == "column":
    534         if key in format_columns:

/usr/lib/python3.6/site-packages/datasets/formatting/formatting.py in __call__(self, pa_table, query_type)
    279     def __call__(self, pa_table: pa.Table, query_type: str) -> Union[RowFormat, ColumnFormat, BatchFormat]:
    280         if query_type == "row":
--> 281             return self.format_row(pa_table)
    282         elif query_type == "column":
    283             return self.format_column(pa_table)

/usr/lib/python3.6/site-packages/datasets/formatting/formatting.py in format_row(self, pa_table)
    310         row = self.python_arrow_extractor().extract_row(pa_table)
    311         if self.decoded:
--> 312             row = self.python_features_decoder.decode_row(row)
    313         return row
    314 

/usr/lib/python3.6/site-packages/datasets/formatting/formatting.py in decode_row(self, row)
    219 
    220     def decode_row(self, row: dict) -> dict:
--> 221         return self.features.decode_example(row) if self.features else row
    222 
    223     def decode_column(self, column: list, column_name: str) -> list:

/usr/lib/python3.6/site-packages/datasets/features/features.py in decode_example(self, example)
   1320             else value
   1321             for column_name, (feature, value) in utils.zip_dict(
-> 1322                 {key: value for key, value in self.items() if key in example}, example
   1323             )
   1324         }

/usr/lib/python3.6/site-packages/datasets/features/features.py in <dictcomp>(.0)
   1319             if self._column_requires_decoding[column_name]
   1320             else value
-> 1321             for column_name, (feature, value) in utils.zip_dict(
   1322                 {key: value for key, value in self.items() if key in example}, example
   1323             )

/usr/lib/python3.6/site-packages/datasets/features/features.py in decode_nested_example(schema, obj)
   1053     # Object with special decoding:
   1054     elif isinstance(schema, (Audio, Image)):
-> 1055         return schema.decode_example(obj) if obj is not None else None
   1056     return obj
   1057 

/usr/lib/python3.6/site-packages/datasets/features/audio.py in decode_example(self, value)
    100                 array, sampling_rate = self._decode_non_mp3_file_like(file)
    101             else:
--> 102                 array, sampling_rate = self._decode_non_mp3_path_like(path)
    103         return {"path": path, "array": array, "sampling_rate": sampling_rate}
    104 

/usr/lib/python3.6/site-packages/datasets/features/audio.py in _decode_non_mp3_path_like(self, path)
    143 
    144         with xopen(path, "rb") as f:
--> 145             array, sampling_rate = librosa.load(f, sr=self.sampling_rate, mono=self.mono)
    146         return array, sampling_rate
    147 

/usr/lib/python3.6/site-packages/librosa/core/audio.py in load(path, sr, mono, offset, duration, dtype, res_type)
    110 
    111     y = []
--> 112     with audioread.audio_open(os.path.realpath(path)) as input_file:
    113         sr_native = input_file.samplerate
    114         n_channels = input_file.channels

/usr/lib/python3.6/posixpath.py in realpath(filename)
    392     """Return the canonical path of the specified filename, eliminating any
    393 symbolic links encountered in the path."""
--> 394     filename = os.fspath(filename)
    395     path, ok = _joinrealpath(filename[:0], filename, {})
    396     return abspath(path)

TypeError: expected str, bytes or os.PathLike object, not _io.BufferedReader
```

## Expected results
```
>>> raw_datasets[0]["audio"]
{'array': array([-0.0005188 , -0.00109863,  0.00030518, ...,  0.01730347,
        0.01623535,  0.01724243]),
'path': '/root/.cache/huggingface/datasets/downloads/extracted/bb3a06b491a64aff422f307cd8116820b4f61d6f32fcadcfc554617e84383cb7/bed/026290a7_nohash_0.wav',
'sampling_rate': 16000}
```

Comments:
Hi @lemoner20, thanks for reporting.

I'm sorry but I cannot reproduce your problem:
```python
In [1]: from datasets import load_dataset, load_metric, Audio
   ...: raw_datasets = load_dataset("superb", "ks", split="train")
   ...: print(raw_datasets[0]["audio"])
Downloading builder script: 30.2kB [00:00, 13.0MB/s]                                                                                                                                                       
Downloading metadata: 38.0kB [00:00, 16.6MB/s]                                                                                                                                                             
Downloading and preparing dataset superb/ks (download: 1.45 GiB, generated: 9.64 MiB, post-processed: Unknown size, total: 1.46 GiB) to .../.cache/huggingface/datasets/superb/ks/1.9.0/fc1f59e1fa54262dfb42de99c326a806ef7de1263ece177b59359a1a3354a9c9...
Downloading data: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 1.49G/1.49G [00:37<00:00, 39.3MB/s]
Downloading data: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 71.3M/71.3M [00:01<00:00, 36.1MB/s]
Downloading data files: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:41<00:00, 20.67s/it]
Extracting data files: 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:28<00:00, 14.24s/it]
Dataset superb downloaded and prepared to .../.cache/huggingface/datasets/superb/ks/1.9.0/fc1f59e1fa54262dfb42de99c326a806ef7de1263ece177b59359a1a3354a9c9. Subsequent calls will reuse this data.
{'path': '.../.cache/huggingface/datasets/downloads/extracted/8571921d3088b48f58f75b2e514815033e1ffbd06aa63fd4603691ac9f1c119f/_background_noise_/doing_the_dishes.wav', 'array': array([ 0.        ,  0.        ,  0.        , ..., -0.00592041,
       -0.00405884, -0.00253296], dtype=float32), 'sampling_rate': 16000}
``` 

Which version of `datasets` are you using? Could you please fill in the environment info requested in the bug report template? You can run the command `datasets-cli env` and copy-and-paste its output below
## Environment info
<!-- You can run the command `datasets-cli env` and copy-and-paste its output below. -->
- `datasets` version:
- Platform:
- Python version:
- PyArrow version:

@albertvillanova Thanks for your reply. The environment info below

## Environment info
- `datasets` version: 1.18.3
- Platform: Linux-4.19.91-007.ali4000.alios7.x86_64-x86_64-with-debian-buster-sid
- Python version: 3.6.12
- PyArrow version: 6.0.1

Thanks @lemoner20,

I cannot reproduce your issue in datasets version 1.18.3 either.

Maybe redownloading the data file may work if you had already cached this dataset previously. Could you please try passing "force_redownload"?
```python
raw_datasets = load_dataset("superb", "ks", split="train", download_mode="force_redownload")

Thanks, @albertvillanova,

I install the python package of **librosa=0.9.1** again, it works now!




Cool!

@albertvillanova, you can actually reproduce the error if you reach the cell `common_voice_train[0]["path"]` of this [notebook](https://colab.research.google.com/github/patrickvonplaten/notebooks/blob/master/Fine_Tune_XLSR_Wav2Vec2_on_Turkish_ASR_with_%F0%9F%A4%97_Transformers.ipynb#scrollTo=_0kRndSvqaKk). Error gets solved after updating the versions of the libraries used in there.

@jvel07, thanks for reporting and finding a solution.

Maybe we could tell @patrickvonplaten about the version pinning issue in his notebook.

Should I update the version of datasets @albertvillanova ?