Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
720323c6
Unverified
Commit
720323c6
authored
Mar 03, 2021
by
Prakashkumar Thiagarajan
Committed by
GitHub
Mar 03, 2021
Browse files
Refactor sox compatibility test (#1344)
parent
3c448374
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
30 deletions
+53
-30
test/torchaudio_unittest/functional/sox_compatibility_test.py
.../torchaudio_unittest/functional/sox_compatibility_test.py
+0
-30
test/torchaudio_unittest/transforms/__init__.py
test/torchaudio_unittest/transforms/__init__.py
+0
-0
test/torchaudio_unittest/transforms/sox_compatibility_test.py
.../torchaudio_unittest/transforms/sox_compatibility_test.py
+53
-0
No files found.
test/torchaudio_unittest/sox_compatibility_test.py
→
test/torchaudio_unittest/
functional/
sox_compatibility_test.py
View file @
720323c6
import
torch
import
torch
import
torchaudio.functional
as
F
import
torchaudio.functional
as
F
import
torchaudio.transforms
as
T
from
parameterized
import
parameterized
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
skipIfNoSoxBackend
,
skipIfNoSoxBackend
,
...
@@ -299,31 +297,3 @@ class TestFunctionalFiltering(TempDirMixin, TorchaudioTestCase):
...
@@ -299,31 +297,3 @@ class TestFunctionalFiltering(TempDirMixin, TorchaudioTestCase):
data
,
path
=
self
.
get_whitenoise
()
data
,
path
=
self
.
get_whitenoise
()
result
=
F
.
lfilter
(
data
,
torch
.
tensor
([
a0
,
a1
,
a2
]),
torch
.
tensor
([
b0
,
b1
,
b2
]))
result
=
F
.
lfilter
(
data
,
torch
.
tensor
([
a0
,
a1
,
a2
]),
torch
.
tensor
([
b0
,
b1
,
b2
]))
self
.
assert_sox_effect
(
result
,
path
,
[
'biquad'
,
b0
,
b1
,
b2
,
a0
,
a1
,
a2
])
self
.
assert_sox_effect
(
result
,
path
,
[
'biquad'
,
b0
,
b1
,
b2
,
a0
,
a1
,
a2
])
@
parameterized
.
expand
([
(
'q'
,
'quarter_sine'
),
(
'h'
,
'half_sine'
),
(
't'
,
'linear'
),
])
def
test_fade
(
self
,
fade_shape_sox
,
fade_shape
):
fade_in_len
,
fade_out_len
=
44100
,
44100
data
,
path
=
self
.
get_whitenoise
(
sample_rate
=
44100
)
result
=
T
.
Fade
(
fade_in_len
,
fade_out_len
,
fade_shape
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'fade'
,
fade_shape_sox
,
'1'
,
'0'
,
'1'
])
@
parameterized
.
expand
([
(
'amplitude'
,
1.1
),
(
'db'
,
2
),
(
'power'
,
2
),
])
def
test_vol
(
self
,
gain_type
,
gain
):
data
,
path
=
self
.
get_whitenoise
()
result
=
T
.
Vol
(
gain
,
gain_type
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'vol'
,
f
'
{
gain
}
'
,
gain_type
])
@
parameterized
.
expand
([
'vad-go-stereo-44100.wav'
,
'vad-go-mono-32000.wav'
])
def
test_vad
(
self
,
filename
):
path
=
get_asset_path
(
filename
)
data
,
sample_rate
=
load_wav
(
path
)
result
=
T
.
Vad
(
sample_rate
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'vad'
])
test/torchaudio_unittest/transforms/__init__.py
0 → 100644
View file @
720323c6
test/torchaudio_unittest/transforms/sox_compatibility_test.py
0 → 100644
View file @
720323c6
import
torchaudio.transforms
as
T
from
parameterized
import
parameterized
from
torchaudio_unittest.common_utils
import
(
skipIfNoSoxBackend
,
skipIfNoExec
,
TempDirMixin
,
TorchaudioTestCase
,
get_asset_path
,
sox_utils
,
load_wav
,
)
@
skipIfNoSoxBackend
@
skipIfNoExec
(
'sox'
)
class
TestFunctionalFiltering
(
TempDirMixin
,
TorchaudioTestCase
):
def
run_sox_effect
(
self
,
input_file
,
effect
):
output_file
=
self
.
get_temp_path
(
'expected.wav'
)
sox_utils
.
run_sox_effect
(
input_file
,
output_file
,
[
str
(
e
)
for
e
in
effect
])
return
load_wav
(
output_file
)
def
assert_sox_effect
(
self
,
result
,
input_path
,
effects
,
atol
=
1e-04
,
rtol
=
1e-5
):
expected
,
_
=
self
.
run_sox_effect
(
input_path
,
effects
)
self
.
assertEqual
(
result
,
expected
,
atol
=
atol
,
rtol
=
rtol
)
@
parameterized
.
expand
([
(
'q'
,
'quarter_sine'
),
(
'h'
,
'half_sine'
),
(
't'
,
'linear'
),
])
def
test_fade
(
self
,
fade_shape_sox
,
fade_shape
):
fade_in_len
,
fade_out_len
=
44100
,
44100
data
,
path
=
self
.
get_whitenoise
(
sample_rate
=
44100
)
result
=
T
.
Fade
(
fade_in_len
,
fade_out_len
,
fade_shape
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'fade'
,
fade_shape_sox
,
'1'
,
'0'
,
'1'
])
@
parameterized
.
expand
([
(
'amplitude'
,
1.1
),
(
'db'
,
2
),
(
'power'
,
2
),
])
def
test_vol
(
self
,
gain_type
,
gain
):
data
,
path
=
self
.
get_whitenoise
()
result
=
T
.
Vol
(
gain
,
gain_type
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'vol'
,
f
'
{
gain
}
'
,
gain_type
])
@
parameterized
.
expand
([
'vad-go-stereo-44100.wav'
,
'vad-go-mono-32000.wav'
])
def
test_vad
(
self
,
filename
):
path
=
get_asset_path
(
filename
)
data
,
sample_rate
=
load_wav
(
path
)
result
=
T
.
Vad
(
sample_rate
)(
data
)
self
.
assert_sox_effect
(
result
,
path
,
[
'vad'
])
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment