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
78a4a027
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "e4ffadc429913f86789f795f8cdc9e23d27bc2cd"
Unverified
Commit
78a4a027
authored
Apr 03, 2020
by
moto
Committed by
GitHub
Apr 03, 2020
Browse files
Move SoX filter test to test_functional_filtering (#502)
parent
5cf3e56f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
60 deletions
+66
-60
test/test_functional.py
test/test_functional.py
+0
-57
test/test_functional_filtering.py
test/test_functional_filtering.py
+66
-3
No files found.
test/test_functional.py
View file @
78a4a027
...
@@ -5,11 +5,9 @@ import unittest
...
@@ -5,11 +5,9 @@ import unittest
import
torch
import
torch
import
torchaudio
import
torchaudio
import
torchaudio.functional
as
F
import
torchaudio.functional
as
F
import
torchaudio.transforms
as
T
import
pytest
import
pytest
import
common_utils
import
common_utils
from
common_utils
import
AudioBackendScope
,
BACKENDS
class
TestFunctional
(
unittest
.
TestCase
):
class
TestFunctional
(
unittest
.
TestCase
):
...
@@ -275,61 +273,6 @@ class TestFunctional(unittest.TestCase):
...
@@ -275,61 +273,6 @@ class TestFunctional(unittest.TestCase):
data_size
=
(
2
,
7
,
3
,
2
)
data_size
=
(
2
,
7
,
3
,
2
)
self
.
_test_linearity_of_istft
(
data_size
,
kwargs4
,
atol
=
1e-5
,
rtol
=
1e-8
)
self
.
_test_linearity_of_istft
(
data_size
,
kwargs4
,
atol
=
1e-5
,
rtol
=
1e-8
)
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_gain
(
self
):
waveform_gain
=
F
.
gain
(
self
.
waveform_train
,
3
)
self
.
assertTrue
(
waveform_gain
.
abs
().
max
().
item
(),
1.
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
self
.
test_filepath
)
E
.
append_effect_to_chain
(
"gain"
,
[
3
])
sox_gain_waveform
=
E
.
sox_build_flow_effects
()[
0
]
self
.
assertTrue
(
torch
.
allclose
(
waveform_gain
,
sox_gain_waveform
,
atol
=
1e-04
))
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_dither
(
self
):
waveform_dithered
=
F
.
dither
(
self
.
waveform_train
)
waveform_dithered_noiseshaped
=
F
.
dither
(
self
.
waveform_train
,
noise_shaping
=
True
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
self
.
test_filepath
)
E
.
append_effect_to_chain
(
"dither"
,
[])
sox_dither_waveform
=
E
.
sox_build_flow_effects
()[
0
]
self
.
assertTrue
(
torch
.
allclose
(
waveform_dithered
,
sox_dither_waveform
,
atol
=
1e-04
))
E
.
clear_chain
()
E
.
append_effect_to_chain
(
"dither"
,
[
"-s"
])
sox_dither_waveform_ns
=
E
.
sox_build_flow_effects
()[
0
]
self
.
assertTrue
(
torch
.
allclose
(
waveform_dithered_noiseshaped
,
sox_dither_waveform_ns
,
atol
=
1e-02
))
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_vctk_transform_pipeline
(
self
):
test_filepath_vctk
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets/VCTK-Corpus/wav48/p224/"
,
"p224_002.wav"
)
wf_vctk
,
sr_vctk
=
torchaudio
.
load
(
test_filepath_vctk
)
# rate
sample
=
T
.
Resample
(
sr_vctk
,
16000
,
resampling_method
=
'sinc_interpolation'
)
wf_vctk
=
sample
(
wf_vctk
)
# dither
wf_vctk
=
F
.
dither
(
wf_vctk
,
noise_shaping
=
True
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
test_filepath_vctk
)
E
.
append_effect_to_chain
(
"gain"
,
[
"-h"
])
E
.
append_effect_to_chain
(
"channels"
,
[
1
])
E
.
append_effect_to_chain
(
"rate"
,
[
16000
])
E
.
append_effect_to_chain
(
"gain"
,
[
"-rh"
])
E
.
append_effect_to_chain
(
"dither"
,
[
"-s"
])
wf_vctk_sox
=
E
.
sox_build_flow_effects
()[
0
]
self
.
assertTrue
(
torch
.
allclose
(
wf_vctk
,
wf_vctk_sox
,
rtol
=
1e-03
,
atol
=
1e-03
))
def
test_pitch
(
self
):
def
test_pitch
(
self
):
test_dirpath
,
test_dir
=
common_utils
.
create_temp_assets_dir
()
test_dirpath
,
test_dir
=
common_utils
.
create_temp_assets_dir
()
test_filepath_100
=
os
.
path
.
join
(
test_dirpath
,
'assets'
,
"100Hz_44100Hz_16bit_05sec.wav"
)
test_filepath_100
=
os
.
path
.
join
(
test_dirpath
,
'assets'
,
"100Hz_44100Hz_16bit_05sec.wav"
)
...
...
test/test_functional_filtering.py
View file @
78a4a027
import
math
import
os
import
os
import
time
import
unittest
import
torch
import
torch
import
torchaudio
import
torchaudio
import
torchaudio.functional
as
F
import
torchaudio.functional
as
F
import
unittest
import
torchaudio.transforms
as
T
import
time
from
common_utils
import
AudioBackendScope
,
BACKENDS
,
create_temp_assets_dir
from
common_utils
import
AudioBackendScope
,
BACKENDS
,
create_temp_assets_dir
...
@@ -107,6 +109,67 @@ class TestFunctionalFiltering(unittest.TestCase):
...
@@ -107,6 +109,67 @@ class TestFunctionalFiltering(unittest.TestCase):
print
(
"skipping GPU test for lfilter because device not available"
)
print
(
"skipping GPU test for lfilter because device not available"
)
pass
pass
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_gain
(
self
):
test_filepath
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.wav"
)
waveform
,
_
=
torchaudio
.
load
(
test_filepath
)
waveform_gain
=
F
.
gain
(
waveform
,
3
)
self
.
assertTrue
(
waveform_gain
.
abs
().
max
().
item
(),
1.
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
test_filepath
)
E
.
append_effect_to_chain
(
"gain"
,
[
3
])
sox_gain_waveform
=
E
.
sox_build_flow_effects
()[
0
]
assert
torch
.
allclose
(
waveform_gain
,
sox_gain_waveform
,
atol
=
1e-04
)
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_dither
(
self
):
test_filepath
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets"
,
"steam-train-whistle-daniel_simon.wav"
)
waveform
,
_
=
torchaudio
.
load
(
test_filepath
)
waveform_dithered
=
F
.
dither
(
waveform
)
waveform_dithered_noiseshaped
=
F
.
dither
(
waveform
,
noise_shaping
=
True
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
test_filepath
)
E
.
append_effect_to_chain
(
"dither"
,
[])
sox_dither_waveform
=
E
.
sox_build_flow_effects
()[
0
]
assert
torch
.
allclose
(
waveform_dithered
,
sox_dither_waveform
,
atol
=
1e-04
)
E
.
clear_chain
()
E
.
append_effect_to_chain
(
"dither"
,
[
"-s"
])
sox_dither_waveform_ns
=
E
.
sox_build_flow_effects
()[
0
]
assert
torch
.
allclose
(
waveform_dithered_noiseshaped
,
sox_dither_waveform_ns
,
atol
=
1e-02
)
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
def
test_vctk_transform_pipeline
(
self
):
test_filepath_vctk
=
os
.
path
.
join
(
self
.
test_dirpath
,
"assets/VCTK-Corpus/wav48/p224/"
,
"p224_002.wav"
)
wf_vctk
,
sr_vctk
=
torchaudio
.
load
(
test_filepath_vctk
)
# rate
sample
=
T
.
Resample
(
sr_vctk
,
16000
,
resampling_method
=
'sinc_interpolation'
)
wf_vctk
=
sample
(
wf_vctk
)
# dither
wf_vctk
=
F
.
dither
(
wf_vctk
,
noise_shaping
=
True
)
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
test_filepath_vctk
)
E
.
append_effect_to_chain
(
"gain"
,
[
"-h"
])
E
.
append_effect_to_chain
(
"channels"
,
[
1
])
E
.
append_effect_to_chain
(
"rate"
,
[
16000
])
E
.
append_effect_to_chain
(
"gain"
,
[
"-rh"
])
E
.
append_effect_to_chain
(
"dither"
,
[
"-s"
])
wf_vctk_sox
=
E
.
sox_build_flow_effects
()[
0
]
assert
torch
.
allclose
(
wf_vctk
,
wf_vctk_sox
,
rtol
=
1e-03
,
atol
=
1e-03
)
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
unittest
.
skipIf
(
"sox"
not
in
BACKENDS
,
"sox not available"
)
@
AudioBackendScope
(
"sox"
)
@
AudioBackendScope
(
"sox"
)
def
test_lowpass
(
self
):
def
test_lowpass
(
self
):
...
...
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