Title: To support decoding audio data, please install 'torchcodec'.
State: closed


In the latest version of datasets==4.0.0, i cannot print the audio data on the Colab notebook. But it works on the 3.6.0 version.

!pip install -q -U datasets huggingface_hub fsspec

from datasets import load_dataset

downloaded_dataset = load_dataset("ymoslem/MediaSpeech", "tr", split="train")
print(downloaded_dataset["audio"][0])

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[/tmp/ipython-input-4-90623240.py](https://localhost:8080/#) in <cell line: 0>()
----> 1 downloaded_dataset["audio"][0]

10 frames
[/usr/local/lib/python3.11/dist-packages/datasets/features/audio.py](https://localhost:8080/#) in decode_example(self, value, token_per_repo_id)
    170             from ._torchcodec import AudioDecoder
    171         else:
--> 172             raise ImportError("To support decoding audio data, please install 'torchcodec'.")
    173 
    174         if not self.decode:

ImportError: To support decoding audio data, please install 'torchcodec'. 

### Environment info

- `datasets` version: 4.0.0
- Platform: Linux-6.1.123+-x86_64-with-glibc2.35
- Python version: 3.11.13
- `huggingface_hub` version: 0.33.2
- PyArrow version: 18.1.0
- Pandas version: 2.2.2
- `fsspec` version: 2025.3.0

Comments:
Hi ! yes you should `!pip install -U datasets[audio]` to have the required dependencies.

`datasets` 4.0 now relies on `torchcodec` for audio decoding. The `torchcodec` AudioDecoder enables streaming from HF and also allows to decode ranges of audio

Same issues on Colab.

> !pip install -U datasets[audio] 

This works for me. Thanks.

### Still getting error after installed datasets

RuntimeError                              Traceback (most recent call last)
Cell In[2], [line 53](vscode-notebook-cell:?execution_count=2&line=53)
     50             f.write(json.dumps(entry, ensure_ascii=False) + "\n")
     52 # Run this for your training set
---> [53](vscode-notebook-cell:?execution_count=2&line=53) process_to_orpheus_jsonl(ds['train'], "mongolian_train.jsonl")

Cell In[2], [line 18](vscode-notebook-cell:?execution_count=2&line=18)
     15 OFFSET = 128266
     17 with open(output_file, "w", encoding="utf-8") as f:
---> [18](vscode-notebook-cell:?execution_count=2&line=18)     for item in tqdm(dataset):
     19         # A. Process Audio
     20         audio_tensor = torch.tensor(item["audio"]["array"]).unsqueeze(0).to("cuda")
     21         sr = item["audio"]["sampling_rate"]

File ~/.pyenv/versions/comet/lib/python3.12/site-packages/tqdm/std.py:1181, in tqdm.__iter__(self)
   1178 time = self._time
   1180 try:
-> [1181](https://vscode-remote+ssh-002dremote-002b202-002e70-002e34-002e9.vscode-resource.vscode-cdn.net/home/ml-team/aThe_Sainaa/ASR/TTS/orpheus/~/.pyenv/versions/comet/lib/python3.12/site-packages/tqdm/std.py:1181)     for obj in iterable:
   1182         yield obj
   1183         # Update and possibly print the progressbar.
   1184         # Note: does not call self.update(1) for speed optimisation.

File ~/.pyenv/versions/comet/lib/python3.12/site-packages/datasets/arrow_dataset.py:2474, in Dataset.__iter__(self)
   2472         for i in range(pa_subtable.num_rows):
...
    torch.ops.load_library(core_library_path)
  File "/home/ml-team/.pyenv/versions/comet/lib/python3.12/site-packages/torch/_ops.py", line 1444, in load_library
    raise OSError(f"Could not load this library: {path}") from e
OSError: Could not load this library: /home/ml-team/.pyenv/versions/3.12.11/envs/comet/lib/python3.12/site-packages/torchcodec/libtorchcodec_core4.so
[end of libtorchcodec loading traceback].