Skip to content

Commit 44f158a

Browse files
committed
Port sox_utils from sox-effects-chain branch
1 parent 9f7cfe0 commit 44f158a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
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)