Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AudioEffector for mulaw #3372

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/torchaudio_unittest/io/effector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ def test_null(self):
("ogg", "flac"), # flac only supports s16 and s32
("ogg", "opus"), # opus only supports 48k Hz
("ogg", "vorbis"), # vorbis only supports stereo
# ("ogg", "vorbis", 44100),
# this fails with small descrepancy; 441024 vs 441000
# TODO: investigate
("wav", None),
("wav", "pcm_u8"),
("mp3", None),
("mulaw", None, 44100), # mulaw is encoded without header
]
)
def test_formats(self, format, encoder):
def test_formats(self, format, encoder, sample_rate=8000):
"""Formats (some with restrictions) just work without an issue in effector"""
sample_rate = 8000

effector = AudioEffector(format=format, encoder=encoder)
original = get_sinusoid(n_channels=3, sample_rate=sample_rate, channels_first=False)
Expand Down
4 changes: 4 additions & 0 deletions torchaudio/io/_effector.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def _get_reader(self, waveform, sample_rate, frames_per_chunk=None):
muxer = self.format
encoder = self.encoder
option = {}
# Some formats are headerless, so need to provide these infomation.
if self.format == "mulaw":
option = {"sample_rate": f"{sample_rate}", "channels": f"{num_channels}"}

else: # PCM
muxer = _get_muxer(waveform.dtype)
encoder = None
Expand Down