Skip to content

Commit db8f2bf

Browse files
authored
Do not use SoxEffectsChain in sox compatibility test (#781)
This PR replaces `torchaudio.sox_effects.SoxEffectsChain` in `test_sox_compatibility` with bare `sox` command. The parity of `torchaudio.sox_effects.SoxEffectsChain` against `sox` command is not tested and it has known issues #771, therefore it is not appropriate to use this class for testing other functions.
1 parent 131e48b commit db8f2bf

File tree

2 files changed

+168
-353
lines changed

2 files changed

+168
-353
lines changed

test/common_utils/sox_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,24 @@ def convert_audio_file(
7777
command += [dst_path]
7878
print(' '.join(command))
7979
subprocess.run(command, check=True)
80+
81+
82+
def _flattern(effects):
83+
if not effects:
84+
return effects
85+
if isinstance(effects[0], str):
86+
return effects
87+
return [item for sublist in effects for item in sublist]
88+
89+
90+
def run_sox_effect(input_file, output_file, effect, *, output_sample_rate=None, output_bitdepth=None):
91+
"""Run sox effects"""
92+
effect = _flattern(effect)
93+
command = ['sox', '-V', '--no-dither', input_file]
94+
if output_bitdepth:
95+
command += ['--bits', str(output_bitdepth)]
96+
command += [output_file] + effect
97+
if output_sample_rate:
98+
command += ['rate', str(output_sample_rate)]
99+
print(' '.join(command))
100+
subprocess.run(command, check=True)

0 commit comments

Comments
 (0)