pytorch / pytorch/audio

Resampling from 8KHz to 16KHz generate nonexisting spectral components

Open
#3,603 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
798
Avg merge
58m
Merged PRs (30d)
3

Description

🐛 Describe the bug

Hi, I have found a abnormal situation when I try to use torchaudio to resample 8KHz speech data to 16KHz.
The code I am using is as follow.

import torchaudio
import torchaudio.backend.sox_io_backend as sox
wav = "float32_wav_file" # given a float32, 8KHz wav file
audio, samplerate = sox.load(wav, normalize=False)
audio = torchaudio.transforms.Resample(8000, 16000)(audio)
torchaudio.save(filepath="new_wav_path", src=audio, sample_rate=16000)
  • This is the spectrum of the original 8KHz data where the cutoff frequency is 4KHz:
CleanShot 2023-09-12 at 20 34 09@2x
  • This is 16KHz resampled version by sox, where the cutoff frequency is still 4KHz:
sox $original_wav -r 16000 $new_wav
CleanShot 2023-09-12 at 20 35 41@2x
  • This is 16Khz resampled version by torchaudio, where the cutoff frequency reaches 5KHz:
CleanShot 2023-09-12 at 20 37 16@2x

Here is another more obvious example:
CleanShot 2023-09-12 at 20 40 12

When using torchaudio to upsample an 8KHz audio to 16KHz, it will somehow generate some spectral components that should not exist.

Versions

PyTorch version: 2.0.1+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Rocky Linux 8.4 (Green Obsidian) (x86_64)
GCC version: (GCC) 9.3.0
Clang version: 14.0.6 (Red Hat 14.0.6-1.module+el8.7.0+1080+d88dc670)
CMake version: version 3.19.4
Libc version: glibc-2.28

Python version: 3.8.17 (default, Jul 5 2023, 21:04:15) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.18.0-305.25.1.el8_4.x86_64-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: 11.6.55
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 48
On-line CPU(s) list: 0-47
Thread(s) per core: 2
Core(s) per socket: 12
Socket(s): 2
NUMA node(s): 2
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Silver 4214R CPU @ 2.40GHz
Stepping: 7
CPU MHz: 2999.754
CPU max MHz: 3500.0000
CPU min MHz: 1000.0000
BogoMIPS: 4800.00
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 1024K
L3 cache: 16896K
NUMA node0 CPU(s): 0-11,24-35
NUMA node1 CPU(s): 12-23,36-47
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req pku ospke avx512_vnni md_clear flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8-bugbear==23.1.20
[pip3] flake8-comprehensions==3.10.1
[pip3] flake8-executable==2.1.3
[pip3] flake8-pyi==20.5.0
[pip3] numpy==1.22.0
[pip3] pytorch-ranger==0.1.1
[pip3] pytorch-wpe==0.0.1
[pip3] torch==2.0.1+cu118
[pip3] torch-complex==0.4.3
[pip3] torch-optimizer==0.3.0
[pip3] torchaudio==2.0.2+cu118
[pip3] triton==2.0.0
[conda] numpy 1.22.0 pypi_0 pypi
[conda] torch 2.0.1+cu118 pypi_0 pypi
[conda] torchaudio 2.0.2+cu118 pypi_0 pypi
[conda] triton 2.0.0 pypi_0 pypi

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

Start with the provided torchaudio.transforms.Resample(8000, 16000) reproduction and compare its spectrum with the original and SoX output. Trace the resampling implementation and its existing tests to determine why components appear above 4 kHz; done means the behavior matches the expected anti-aliasing cutoff and is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
audio-video-rtc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.