pytorch / pytorch/audio

read mp3 file fail

Open
#2,867 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue help wanted triaged
Dominant language
Python
Stars
2.9k
Forks
799
Avg merge
58m
Merged PRs (30d)
3

Description

🐛 Describe the bug

I am trying to load commonvoice mp3 files using torchaudio with below code:

import torchaudio
array, sampling_rate = torchaudio.load(path_or_file, format="mp3")

I get an empty output:

Out[4]: tensor([], size=(1, 0))

I find the root cause in file soundfile_backend.py

    with soundfile.SoundFile(filepath, "r") as file_:
        if file_.format != "WAV" or normalize:
            dtype = "float32"

by changing float32 to float64, the array can be generated

tensor([[ 0.0000e+00,  0.0000e+00,  0.0000e+00,  ..., -2.9407e-05,
         -3.2597e-05, -2.5751e-05]], dtype=torch.float64)

Attached a mp3 file for your reference
common_voice_zh-HK_20096730.zip

The ffmpeg version I am using is 5.1.2.

Thanks.

Versions

Collecting environment information...
PyTorch version: 1.12.0
Is debug build: False
CUDA used to build PyTorch: 11.6
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 10 Pro
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 3.24.0-rc3
Libc version: N/A

Python version: 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.19045-SP0
Is CUDA available: True
CUDA runtime version: 11.6.124
CUDA_MODULE_LOADING set to:
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3090 Ti
Nvidia driver version: 516.94
cuDNN version: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\cudnn_ops_train64_8.dll
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.23.3
[pip3] numpydoc==1.2
[pip3] pytorchvideo==0.1.5
[pip3] torch==1.12.0
[pip3] torch-geometric==2.0.4
[pip3] torch-geometric-temporal==0.53.0
[pip3] torch-scatter==2.0.9
[pip3] torch-sparse==0.6.13
[pip3] torchaudio==0.12.0
[pip3] torchfile==0.1.0
[pip3] torchvision==0.13.0
[conda] Could not collect

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the empty waveform with the provided commonvoice MP3 and the torchaudio.load call, then inspect soundfile_backend.py around the SoundFile dtype selection. Confirm the behavior with the reported ffmpeg and Windows environment; done means loading the attachment returns a non-empty waveform with an appropriate dtype.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
audio-video-rtc
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.