"docs/git@developer.sourcefind.cn:OpenDAS/pytorch3d.git" did not exist on "25d2e2c8b72a85c36f761eccbecdb8fc10b9264a"
Commit af932cc7 authored by moto's avatar moto Committed by Facebook GitHub Bot
Browse files

Fix AudioEffector for mulaw (#3372)

Summary:
When encoding audio with mulaw, the resulting data does not have header, and the StreamReader defaults to 16k Hz, which can strech/shrink the resulting waveform.

Pull Request resolved: https://github.com/pytorch/audio/pull/3372

Reviewed By: hwangjeff

Differential Revision: D46234772

Pulled By: mthrok

fbshipit-source-id: 942c89a8cfe29b0b6f57b3e5b6c9dfd3524ca552
parent 1b05ca7e
...@@ -30,14 +30,17 @@ class EffectorTest(TorchaudioTestCase): ...@@ -30,14 +30,17 @@ class EffectorTest(TorchaudioTestCase):
("ogg", "flac"), # flac only supports s16 and s32 ("ogg", "flac"), # flac only supports s16 and s32
("ogg", "opus"), # opus only supports 48k Hz ("ogg", "opus"), # opus only supports 48k Hz
("ogg", "vorbis"), # vorbis only supports stereo ("ogg", "vorbis"), # vorbis only supports stereo
# ("ogg", "vorbis", 44100),
# this fails with small descrepancy; 441024 vs 441000
# TODO: investigate
("wav", None), ("wav", None),
("wav", "pcm_u8"), ("wav", "pcm_u8"),
("mp3", None), ("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""" """Formats (some with restrictions) just work without an issue in effector"""
sample_rate = 8000
effector = AudioEffector(format=format, encoder=encoder) effector = AudioEffector(format=format, encoder=encoder)
original = get_sinusoid(n_channels=3, sample_rate=sample_rate, channels_first=False) original = get_sinusoid(n_channels=3, sample_rate=sample_rate, channels_first=False)
......
...@@ -267,6 +267,10 @@ class AudioEffector: ...@@ -267,6 +267,10 @@ class AudioEffector:
muxer = self.format muxer = self.format
encoder = self.encoder encoder = self.encoder
option = {} 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 else: # PCM
muxer = _get_muxer(waveform.dtype) muxer = _get_muxer(waveform.dtype)
encoder = None encoder = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment