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
ecfed4d9
"git@developer.sourcefind.cn:OpenDAS/ktransformers.git" did not exist on "5aee6c0446b786e2ef3a7e6077a8456417e168ec"
Unverified
Commit
ecfed4d9
authored
Mar 02, 2021
by
Caroline Chen
Committed by
GitHub
Mar 02, 2021
Browse files
Make sox selective (#1338)
parent
98d0d593
Changes
28
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
80 additions
and
58 deletions
+80
-58
test/torchaudio_unittest/backend/sox_io/info_test.py
test/torchaudio_unittest/backend/sox_io/info_test.py
+6
-6
test/torchaudio_unittest/backend/sox_io/load_test.py
test/torchaudio_unittest/backend/sox_io/load_test.py
+6
-6
test/torchaudio_unittest/backend/sox_io/roundtrip_test.py
test/torchaudio_unittest/backend/sox_io/roundtrip_test.py
+2
-2
test/torchaudio_unittest/backend/sox_io/save_test.py
test/torchaudio_unittest/backend/sox_io/save_test.py
+3
-3
test/torchaudio_unittest/backend/sox_io/smoke_test.py
test/torchaudio_unittest/backend/sox_io/smoke_test.py
+5
-5
test/torchaudio_unittest/backend/sox_io/torchscript_test.py
test/torchaudio_unittest/backend/sox_io/torchscript_test.py
+2
-2
test/torchaudio_unittest/backend/utils_test.py
test/torchaudio_unittest/backend/utils_test.py
+1
-1
test/torchaudio_unittest/common_utils/__init__.py
test/torchaudio_unittest/common_utils/__init__.py
+3
-2
test/torchaudio_unittest/common_utils/case_utils.py
test/torchaudio_unittest/common_utils/case_utils.py
+5
-1
test/torchaudio_unittest/datasets/tedlium_test.py
test/torchaudio_unittest/datasets/tedlium_test.py
+2
-0
test/torchaudio_unittest/functional/functional_cpu_test.py
test/torchaudio_unittest/functional/functional_cpu_test.py
+2
-2
test/torchaudio_unittest/sox_effect/dataset_test.py
test/torchaudio_unittest/sox_effect/dataset_test.py
+3
-3
test/torchaudio_unittest/sox_effect/smoke_test.py
test/torchaudio_unittest/sox_effect/smoke_test.py
+2
-2
test/torchaudio_unittest/sox_effect/sox_effect_test.py
test/torchaudio_unittest/sox_effect/sox_effect_test.py
+8
-8
test/torchaudio_unittest/sox_effect/torchscript_test.py
test/torchaudio_unittest/sox_effect/torchscript_test.py
+2
-2
test/torchaudio_unittest/utils/sox_utils_test.py
test/torchaudio_unittest/utils/sox_utils_test.py
+2
-2
third_party/CMakeLists.txt
third_party/CMakeLists.txt
+1
-5
torchaudio/_internal/module_utils.py
torchaudio/_internal/module_utils.py
+19
-0
torchaudio/backend/sox_io_backend.py
torchaudio/backend/sox_io_backend.py
+3
-3
torchaudio/backend/utils.py
torchaudio/backend/utils.py
+3
-3
No files found.
test/torchaudio_unittest/backend/sox_io/info_test.py
View file @
ecfed4d9
...
@@ -16,8 +16,8 @@ from torchaudio_unittest.common_utils import (
...
@@ -16,8 +16,8 @@ from torchaudio_unittest.common_utils import (
HttpServerMixin
,
HttpServerMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNoExec
,
skipIfNoExec
,
skipIfNoExtension
,
skipIfNoModule
,
skipIfNoModule
,
skipIfNoSox
,
get_asset_path
,
get_asset_path
,
get_wav_data
,
get_wav_data
,
save_wav
,
save_wav
,
...
@@ -33,7 +33,7 @@ if _mod_utils.is_module_available("requests"):
...
@@ -33,7 +33,7 @@ if _mod_utils.is_module_available("requests"):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestInfo
(
TempDirMixin
,
PytorchTestCase
):
class
TestInfo
(
TempDirMixin
,
PytorchTestCase
):
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
'float32'
,
'int32'
,
'int16'
,
'uint8'
],
[
'float32'
,
'int32'
,
'int16'
,
'uint8'
],
...
@@ -253,7 +253,7 @@ class TestInfo(TempDirMixin, PytorchTestCase):
...
@@ -253,7 +253,7 @@ class TestInfo(TempDirMixin, PytorchTestCase):
assert
info
.
encoding
==
"PCM_S"
assert
info
.
encoding
==
"PCM_S"
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestInfoOpus
(
PytorchTestCase
):
class
TestInfoOpus
(
PytorchTestCase
):
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
[
'96k'
],
[
'96k'
],
...
@@ -271,7 +271,7 @@ class TestInfoOpus(PytorchTestCase):
...
@@ -271,7 +271,7 @@ class TestInfoOpus(PytorchTestCase):
assert
info
.
encoding
==
"OPUS"
assert
info
.
encoding
==
"OPUS"
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestLoadWithoutExtension
(
PytorchTestCase
):
class
TestLoadWithoutExtension
(
PytorchTestCase
):
def
test_mp3
(
self
):
def
test_mp3
(
self
):
"""Providing `format` allows to read mp3 without extension
"""Providing `format` allows to read mp3 without extension
...
@@ -306,7 +306,7 @@ class FileObjTestBase(TempDirMixin):
...
@@ -306,7 +306,7 @@ class FileObjTestBase(TempDirMixin):
return
path
return
path
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
class
TestFileObject
(
FileObjTestBase
,
PytorchTestCase
):
class
TestFileObject
(
FileObjTestBase
,
PytorchTestCase
):
def
_query_fileobj
(
self
,
ext
,
dtype
,
sample_rate
,
num_channels
,
num_frames
):
def
_query_fileobj
(
self
,
ext
,
dtype
,
sample_rate
,
num_channels
,
num_frames
):
...
@@ -438,7 +438,7 @@ class TestFileObject(FileObjTestBase, PytorchTestCase):
...
@@ -438,7 +438,7 @@ class TestFileObject(FileObjTestBase, PytorchTestCase):
assert
sinfo
.
encoding
==
get_encoding
(
ext
,
dtype
)
assert
sinfo
.
encoding
==
get_encoding
(
ext
,
dtype
)
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNoModule
(
"requests"
)
@
skipIfNoModule
(
"requests"
)
class
TestFileObjectHttp
(
HttpServerMixin
,
FileObjTestBase
,
PytorchTestCase
):
class
TestFileObjectHttp
(
HttpServerMixin
,
FileObjTestBase
,
PytorchTestCase
):
...
...
test/torchaudio_unittest/backend/sox_io/load_test.py
View file @
ecfed4d9
...
@@ -11,8 +11,8 @@ from torchaudio_unittest.common_utils import (
...
@@ -11,8 +11,8 @@ from torchaudio_unittest.common_utils import (
HttpServerMixin
,
HttpServerMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNoExec
,
skipIfNoExec
,
skipIfNoExtension
,
skipIfNoModule
,
skipIfNoModule
,
skipIfNoSox
,
get_asset_path
,
get_asset_path
,
get_wav_data
,
get_wav_data
,
load_wav
,
load_wav
,
...
@@ -200,7 +200,7 @@ class LoadTestBase(TempDirMixin, PytorchTestCase):
...
@@ -200,7 +200,7 @@ class LoadTestBase(TempDirMixin, PytorchTestCase):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestLoad
(
LoadTestBase
):
class
TestLoad
(
LoadTestBase
):
"""Test the correctness of `sox_io_backend.load` for various formats"""
"""Test the correctness of `sox_io_backend.load` for various formats"""
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
...
@@ -332,7 +332,7 @@ class TestLoad(LoadTestBase):
...
@@ -332,7 +332,7 @@ class TestLoad(LoadTestBase):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestLoadParams
(
TempDirMixin
,
PytorchTestCase
):
class
TestLoadParams
(
TempDirMixin
,
PytorchTestCase
):
"""Test the correctness of frame parameters of `sox_io_backend.load`"""
"""Test the correctness of frame parameters of `sox_io_backend.load`"""
original
=
None
original
=
None
...
@@ -363,7 +363,7 @@ class TestLoadParams(TempDirMixin, PytorchTestCase):
...
@@ -363,7 +363,7 @@ class TestLoadParams(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
found
,
expected
)
self
.
assertEqual
(
found
,
expected
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestLoadWithoutExtension
(
PytorchTestCase
):
class
TestLoadWithoutExtension
(
PytorchTestCase
):
def
test_mp3
(
self
):
def
test_mp3
(
self
):
"""Providing format allows to read mp3 without extension
"""Providing format allows to read mp3 without extension
...
@@ -393,7 +393,7 @@ class CloggedFileObj:
...
@@ -393,7 +393,7 @@ class CloggedFileObj:
return
ret
return
ret
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
class
TestFileObject
(
TempDirMixin
,
PytorchTestCase
):
class
TestFileObject
(
TempDirMixin
,
PytorchTestCase
):
"""
"""
...
@@ -553,7 +553,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
...
@@ -553,7 +553,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
expected
,
found
)
self
.
assertEqual
(
expected
,
found
)
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNoModule
(
"requests"
)
@
skipIfNoModule
(
"requests"
)
class
TestFileObjectHttp
(
HttpServerMixin
,
PytorchTestCase
):
class
TestFileObjectHttp
(
HttpServerMixin
,
PytorchTestCase
):
...
...
test/torchaudio_unittest/backend/sox_io/roundtrip_test.py
View file @
ecfed4d9
...
@@ -7,7 +7,7 @@ from torchaudio_unittest.common_utils import (
...
@@ -7,7 +7,7 @@ from torchaudio_unittest.common_utils import (
TempDirMixin
,
TempDirMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNoExec
,
skipIfNoExec
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_wav_data
,
get_wav_data
,
)
)
from
.common
import
(
from
.common
import
(
...
@@ -17,7 +17,7 @@ from .common import (
...
@@ -17,7 +17,7 @@ from .common import (
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestRoundTripIO
(
TempDirMixin
,
PytorchTestCase
):
class
TestRoundTripIO
(
TempDirMixin
,
PytorchTestCase
):
"""save/load round trip should not degrade data for lossless formats"""
"""save/load round trip should not degrade data for lossless formats"""
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
...
...
test/torchaudio_unittest/backend/sox_io/save_test.py
View file @
ecfed4d9
...
@@ -10,7 +10,7 @@ from torchaudio_unittest.common_utils import (
...
@@ -10,7 +10,7 @@ from torchaudio_unittest.common_utils import (
TorchaudioTestCase
,
TorchaudioTestCase
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNoExec
,
skipIfNoExec
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_wav_data
,
get_wav_data
,
load_wav
,
load_wav
,
save_wav
,
save_wav
,
...
@@ -157,7 +157,7 @@ def nested_params(*params):
...
@@ -157,7 +157,7 @@ def nested_params(*params):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
SaveTest
(
SaveTestBase
):
class
SaveTest
(
SaveTestBase
):
@
nested_params
(
@
nested_params
(
[
"path"
,
"fileobj"
,
"bytesio"
],
[
"path"
,
"fileobj"
,
"bytesio"
],
...
@@ -354,7 +354,7 @@ class SaveTest(SaveTestBase):
...
@@ -354,7 +354,7 @@ class SaveTest(SaveTestBase):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestSaveParams
(
TempDirMixin
,
PytorchTestCase
):
class
TestSaveParams
(
TempDirMixin
,
PytorchTestCase
):
"""Test the correctness of optional parameters of `sox_io_backend.save`"""
"""Test the correctness of optional parameters of `sox_io_backend.save`"""
@
parameterized
.
expand
([(
True
,
),
(
False
,
)],
name_func
=
name_func
)
@
parameterized
.
expand
([(
True
,
),
(
False
,
)],
name_func
=
name_func
)
...
...
test/torchaudio_unittest/backend/sox_io/smoke_test.py
View file @
ecfed4d9
...
@@ -4,26 +4,26 @@ import unittest
...
@@ -4,26 +4,26 @@ import unittest
from
torchaudio.utils
import
sox_utils
from
torchaudio.utils
import
sox_utils
from
torchaudio.backend
import
sox_io_backend
from
torchaudio.backend
import
sox_io_backend
from
torchaudio._internal.module_utils
import
is_
module
_available
from
torchaudio._internal.module_utils
import
is_
sox
_available
from
parameterized
import
parameterized
from
parameterized
import
parameterized
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
TempDirMixin
,
TempDirMixin
,
TorchaudioTestCase
,
TorchaudioTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_wav_data
,
get_wav_data
,
)
)
from
.common
import
name_func
from
.common
import
name_func
skipIfNoMP3
=
unittest
.
skipIf
(
skipIfNoMP3
=
unittest
.
skipIf
(
not
is_
module
_available
(
'torchaudio._torchaudio'
)
or
not
is_
sox
_available
()
or
'mp3'
not
in
sox_utils
.
list_read_formats
()
or
'mp3'
not
in
sox_utils
.
list_read_formats
()
or
'mp3'
not
in
sox_utils
.
list_write_formats
(),
'mp3'
not
in
sox_utils
.
list_write_formats
(),
'"sox_io" backend does not support MP3'
)
'"sox_io" backend does not support MP3'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
SmokeTest
(
TempDirMixin
,
TorchaudioTestCase
):
class
SmokeTest
(
TempDirMixin
,
TorchaudioTestCase
):
"""Run smoke test on various audio format
"""Run smoke test on various audio format
...
@@ -88,7 +88,7 @@ class SmokeTest(TempDirMixin, TorchaudioTestCase):
...
@@ -88,7 +88,7 @@ class SmokeTest(TempDirMixin, TorchaudioTestCase):
self
.
run_smoke_test
(
'flac'
,
sample_rate
,
num_channels
,
compression
=
compression_level
)
self
.
run_smoke_test
(
'flac'
,
sample_rate
,
num_channels
,
compression
=
compression_level
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
SmokeTestFileObj
(
TorchaudioTestCase
):
class
SmokeTestFileObj
(
TorchaudioTestCase
):
"""Run smoke test on various audio format
"""Run smoke test on various audio format
...
...
test/torchaudio_unittest/backend/sox_io/torchscript_test.py
View file @
ecfed4d9
...
@@ -9,7 +9,7 @@ from torchaudio_unittest.common_utils import (
...
@@ -9,7 +9,7 @@ from torchaudio_unittest.common_utils import (
TempDirMixin
,
TempDirMixin
,
TorchaudioTestCase
,
TorchaudioTestCase
,
skipIfNoExec
,
skipIfNoExec
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_wav_data
,
get_wav_data
,
save_wav
,
save_wav
,
load_wav
,
load_wav
,
...
@@ -45,7 +45,7 @@ def py_save_func(
...
@@ -45,7 +45,7 @@ def py_save_func(
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
SoxIO
(
TempDirMixin
,
TorchaudioTestCase
):
class
SoxIO
(
TempDirMixin
,
TorchaudioTestCase
):
"""TorchScript-ability Test suite for `sox_io_backend`"""
"""TorchScript-ability Test suite for `sox_io_backend`"""
backend
=
'sox_io'
backend
=
'sox_io'
...
...
test/torchaudio_unittest/backend/utils_test.py
View file @
ecfed4d9
...
@@ -25,7 +25,7 @@ class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTes
...
@@ -25,7 +25,7 @@ class TestBackendSwitch_NoBackend(BackendSwitchMixin, common_utils.TorchaudioTes
backend_module
=
torchaudio
.
backend
.
no_backend
backend_module
=
torchaudio
.
backend
.
no_backend
@
common_utils
.
skipIfNo
Extension
@
common_utils
.
skipIfNo
Sox
class
TestBackendSwitch_SoXIO
(
BackendSwitchMixin
,
common_utils
.
TorchaudioTestCase
):
class
TestBackendSwitch_SoXIO
(
BackendSwitchMixin
,
common_utils
.
TorchaudioTestCase
):
backend
=
'sox_io'
backend
=
'sox_io'
backend_module
=
torchaudio
.
backend
.
sox_io_backend
backend_module
=
torchaudio
.
backend
.
sox_io_backend
...
...
test/torchaudio_unittest/common_utils/__init__.py
View file @
ecfed4d9
...
@@ -16,6 +16,7 @@ from .case_utils import (
...
@@ -16,6 +16,7 @@ from .case_utils import (
skipIfNoExec
,
skipIfNoExec
,
skipIfNoModule
,
skipIfNoModule
,
skipIfNoExtension
,
skipIfNoExtension
,
skipIfNoSox
,
skipIfNoSoxBackend
,
skipIfNoSoxBackend
,
)
)
from
.wav_utils
import
(
from
.wav_utils
import
(
...
@@ -30,5 +31,5 @@ from .parameterized_utils import (
...
@@ -30,5 +31,5 @@ from .parameterized_utils import (
__all__
=
[
'get_asset_path'
,
'get_whitenoise'
,
'get_sinusoid'
,
'set_audio_backend'
,
__all__
=
[
'get_asset_path'
,
'get_whitenoise'
,
'get_sinusoid'
,
'set_audio_backend'
,
'TempDirMixin'
,
'HttpServerMixin'
,
'TestBaseMixin'
,
'PytorchTestCase'
,
'TorchaudioTestCase'
,
'TempDirMixin'
,
'HttpServerMixin'
,
'TestBaseMixin'
,
'PytorchTestCase'
,
'TorchaudioTestCase'
,
'skipIfNoCuda'
,
'skipIfNoExec'
,
'skipIfNoModule'
,
'skipIfNoExtension'
,
'skipIfNoSox
Backend
'
,
'skipIfNoCuda'
,
'skipIfNoExec'
,
'skipIfNoModule'
,
'skipIfNoExtension'
,
'skipIfNoSox'
,
'get_wav_data'
,
'normalize_wav'
,
'load_wav'
,
'save_wav'
,
'load_params'
]
'skipIfNoSoxBackend'
,
'get_wav_data'
,
'normalize_wav'
,
'load_wav'
,
'save_wav'
,
'load_params'
]
test/torchaudio_unittest/common_utils/case_utils.py
View file @
ecfed4d9
...
@@ -8,7 +8,10 @@ import unittest
...
@@ -8,7 +8,10 @@ import unittest
import
torch
import
torch
from
torch.testing._internal.common_utils
import
TestCase
as
PytorchTestCase
from
torch.testing._internal.common_utils
import
TestCase
as
PytorchTestCase
import
torchaudio
import
torchaudio
from
torchaudio._internal.module_utils
import
is_module_available
from
torchaudio._internal.module_utils
import
(
is_module_available
,
is_sox_available
)
from
.backend_utils
import
set_audio_backend
from
.backend_utils
import
set_audio_backend
...
@@ -95,6 +98,7 @@ def skipIfNoModule(module, display_name=None):
...
@@ -95,6 +98,7 @@ def skipIfNoModule(module, display_name=None):
skipIfNoSoxBackend
=
unittest
.
skipIf
(
skipIfNoSoxBackend
=
unittest
.
skipIf
(
'sox'
not
in
torchaudio
.
list_audio_backends
(),
'Sox backend not available'
)
'sox'
not
in
torchaudio
.
list_audio_backends
(),
'Sox backend not available'
)
skipIfNoCuda
=
unittest
.
skipIf
(
not
torch
.
cuda
.
is_available
(),
reason
=
'CUDA not available'
)
skipIfNoCuda
=
unittest
.
skipIf
(
not
torch
.
cuda
.
is_available
(),
reason
=
'CUDA not available'
)
skipIfNoSox
=
unittest
.
skipIf
(
not
is_sox_available
(),
reason
=
'Sox not available'
)
def
skipIfNoExtension
(
test_item
):
def
skipIfNoExtension
(
test_item
):
...
...
test/torchaudio_unittest/datasets/tedlium_test.py
View file @
ecfed4d9
...
@@ -7,6 +7,7 @@ from torchaudio_unittest.common_utils import (
...
@@ -7,6 +7,7 @@ from torchaudio_unittest.common_utils import (
TorchaudioTestCase
,
TorchaudioTestCase
,
get_whitenoise
,
get_whitenoise
,
save_wav
,
save_wav
,
skipIfNoSox
)
)
from
torchaudio.datasets
import
tedlium
from
torchaudio.datasets
import
tedlium
...
@@ -144,5 +145,6 @@ class TestTedliumSoundfile(Tedlium, TorchaudioTestCase):
...
@@ -144,5 +145,6 @@ class TestTedliumSoundfile(Tedlium, TorchaudioTestCase):
if
platform
.
system
()
!=
"Windows"
:
if
platform
.
system
()
!=
"Windows"
:
@
skipIfNoSox
class
TestTedliumSoxIO
(
Tedlium
,
TorchaudioTestCase
):
class
TestTedliumSoxIO
(
Tedlium
,
TorchaudioTestCase
):
backend
=
"sox_io"
backend
=
"sox_io"
test/torchaudio_unittest/functional/functional_cpu_test.py
View file @
ecfed4d9
...
@@ -10,7 +10,7 @@ import itertools
...
@@ -10,7 +10,7 @@ import itertools
from
torchaudio_unittest
import
common_utils
from
torchaudio_unittest
import
common_utils
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
TorchaudioTestCase
,
TorchaudioTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
)
)
from
torchaudio_unittest.backend.sox_io.common
import
name_func
from
torchaudio_unittest.backend.sox_io.common
import
name_func
...
@@ -220,7 +220,7 @@ class TestMaskAlongAxisIID(common_utils.TorchaudioTestCase):
...
@@ -220,7 +220,7 @@ class TestMaskAlongAxisIID(common_utils.TorchaudioTestCase):
assert
(
num_masked_columns
<
mask_param
).
sum
()
==
num_masked_columns
.
numel
()
assert
(
num_masked_columns
<
mask_param
).
sum
()
==
num_masked_columns
.
numel
()
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestApplyCodec
(
TorchaudioTestCase
):
class
TestApplyCodec
(
TorchaudioTestCase
):
backend
=
"sox_io"
backend
=
"sox_io"
...
...
test/torchaudio_unittest/sox_effect/dataset_test.py
View file @
ecfed4d9
...
@@ -11,7 +11,7 @@ import torchaudio
...
@@ -11,7 +11,7 @@ import torchaudio
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
TempDirMixin
,
TempDirMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_whitenoise
,
get_whitenoise
,
save_wav
,
save_wav
,
)
)
...
@@ -71,7 +71,7 @@ def init_random_seed(worker_id):
...
@@ -71,7 +71,7 @@ def init_random_seed(worker_id):
dataset
.
rng
=
np
.
random
.
RandomState
(
worker_id
)
dataset
.
rng
=
np
.
random
.
RandomState
(
worker_id
)
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIf
(
@
skipIf
(
platform
.
system
()
==
'Darwin'
and
platform
.
system
()
==
'Darwin'
and
sys
.
version_info
.
major
==
3
and
sys
.
version_info
.
major
==
3
and
...
@@ -134,7 +134,7 @@ def speed(path):
...
@@ -134,7 +134,7 @@ def speed(path):
return
torchaudio
.
sox_effects
.
apply_effects_tensor
(
wav
,
sample_rate
,
effects
)[
0
]
return
torchaudio
.
sox_effects
.
apply_effects_tensor
(
wav
,
sample_rate
,
effects
)[
0
]
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestProcessPoolExecutor
(
TempDirMixin
,
PytorchTestCase
):
class
TestProcessPoolExecutor
(
TempDirMixin
,
PytorchTestCase
):
backend
=
"sox_io"
backend
=
"sox_io"
...
...
test/torchaudio_unittest/sox_effect/smoke_test.py
View file @
ecfed4d9
...
@@ -4,7 +4,7 @@ from parameterized import parameterized
...
@@ -4,7 +4,7 @@ from parameterized import parameterized
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
TempDirMixin
,
TempDirMixin
,
TorchaudioTestCase
,
TorchaudioTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_wav_data
,
get_wav_data
,
get_sinusoid
,
get_sinusoid
,
save_wav
,
save_wav
,
...
@@ -14,7 +14,7 @@ from .common import (
...
@@ -14,7 +14,7 @@ from .common import (
)
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
SmokeTest
(
TempDirMixin
,
TorchaudioTestCase
):
class
SmokeTest
(
TempDirMixin
,
TorchaudioTestCase
):
"""Run smoke test on various effects
"""Run smoke test on various effects
...
...
test/torchaudio_unittest/sox_effect/sox_effect_test.py
View file @
ecfed4d9
...
@@ -11,7 +11,7 @@ from torchaudio_unittest.common_utils import (
...
@@ -11,7 +11,7 @@ from torchaudio_unittest.common_utils import (
TempDirMixin
,
TempDirMixin
,
HttpServerMixin
,
HttpServerMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
skipIfNoModule
,
skipIfNoModule
,
skipIfNoExec
,
skipIfNoExec
,
get_asset_path
,
get_asset_path
,
...
@@ -31,7 +31,7 @@ if _mod_utils.is_module_available("requests"):
...
@@ -31,7 +31,7 @@ if _mod_utils.is_module_available("requests"):
import
requests
import
requests
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestSoxEffects
(
PytorchTestCase
):
class
TestSoxEffects
(
PytorchTestCase
):
def
test_init
(
self
):
def
test_init
(
self
):
"""Calling init_sox_effects multiple times does not crush"""
"""Calling init_sox_effects multiple times does not crush"""
...
@@ -39,7 +39,7 @@ class TestSoxEffects(PytorchTestCase):
...
@@ -39,7 +39,7 @@ class TestSoxEffects(PytorchTestCase):
sox_effects
.
init_sox_effects
()
sox_effects
.
init_sox_effects
()
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestSoxEffectsTensor
(
TempDirMixin
,
PytorchTestCase
):
class
TestSoxEffectsTensor
(
TempDirMixin
,
PytorchTestCase
):
"""Test suite for `apply_effects_tensor` function"""
"""Test suite for `apply_effects_tensor` function"""
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
...
@@ -91,7 +91,7 @@ class TestSoxEffectsTensor(TempDirMixin, PytorchTestCase):
...
@@ -91,7 +91,7 @@ class TestSoxEffectsTensor(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
expected
,
found
)
self
.
assertEqual
(
expected
,
found
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestSoxEffectsFile
(
TempDirMixin
,
PytorchTestCase
):
class
TestSoxEffectsFile
(
TempDirMixin
,
PytorchTestCase
):
"""Test suite for `apply_effects_file` function"""
"""Test suite for `apply_effects_file` function"""
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
...
@@ -163,7 +163,7 @@ class TestSoxEffectsFile(TempDirMixin, PytorchTestCase):
...
@@ -163,7 +163,7 @@ class TestSoxEffectsFile(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
found
,
expected
)
self
.
assertEqual
(
found
,
expected
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestFileFormats
(
TempDirMixin
,
PytorchTestCase
):
class
TestFileFormats
(
TempDirMixin
,
PytorchTestCase
):
"""`apply_effects_file` gives the same result as sox on various file formats"""
"""`apply_effects_file` gives the same result as sox on various file formats"""
@
parameterized
.
expand
(
list
(
itertools
.
product
(
@
parameterized
.
expand
(
list
(
itertools
.
product
(
...
@@ -256,7 +256,7 @@ class TestFileFormats(TempDirMixin, PytorchTestCase):
...
@@ -256,7 +256,7 @@ class TestFileFormats(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
found
,
expected
)
self
.
assertEqual
(
found
,
expected
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestApplyEffectFileWithoutExtension
(
PytorchTestCase
):
class
TestApplyEffectFileWithoutExtension
(
PytorchTestCase
):
def
test_mp3
(
self
):
def
test_mp3
(
self
):
"""Providing format allows to read mp3 without extension
"""Providing format allows to read mp3 without extension
...
@@ -275,7 +275,7 @@ class TestApplyEffectFileWithoutExtension(PytorchTestCase):
...
@@ -275,7 +275,7 @@ class TestApplyEffectFileWithoutExtension(PytorchTestCase):
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestFileObject
(
TempDirMixin
,
PytorchTestCase
):
class
TestFileObject
(
TempDirMixin
,
PytorchTestCase
):
@
parameterized
.
expand
([
@
parameterized
.
expand
([
(
'wav'
,
None
),
(
'wav'
,
None
),
...
@@ -384,7 +384,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
...
@@ -384,7 +384,7 @@ class TestFileObject(TempDirMixin, PytorchTestCase):
self
.
assertEqual
(
found
,
expected
)
self
.
assertEqual
(
found
,
expected
)
@
skipIfNo
Extension
@
skipIfNo
Sox
@
skipIfNoExec
(
'sox'
)
@
skipIfNoExec
(
'sox'
)
@
skipIfNoModule
(
"requests"
)
@
skipIfNoModule
(
"requests"
)
class
TestFileObjectHttp
(
HttpServerMixin
,
PytorchTestCase
):
class
TestFileObjectHttp
(
HttpServerMixin
,
PytorchTestCase
):
...
...
test/torchaudio_unittest/sox_effect/torchscript_test.py
View file @
ecfed4d9
...
@@ -7,7 +7,7 @@ from parameterized import parameterized
...
@@ -7,7 +7,7 @@ from parameterized import parameterized
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
TempDirMixin
,
TempDirMixin
,
PytorchTestCase
,
PytorchTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
get_sinusoid
,
get_sinusoid
,
save_wav
,
save_wav
,
)
)
...
@@ -43,7 +43,7 @@ class SoxEffectFileTransform(torch.nn.Module):
...
@@ -43,7 +43,7 @@ class SoxEffectFileTransform(torch.nn.Module):
return
sox_effects
.
apply_effects_file
(
path
,
self
.
effects
,
self
.
channels_first
)
return
sox_effects
.
apply_effects_file
(
path
,
self
.
effects
,
self
.
channels_first
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestTorchScript
(
TempDirMixin
,
PytorchTestCase
):
class
TestTorchScript
(
TempDirMixin
,
PytorchTestCase
):
@
parameterized
.
expand
(
@
parameterized
.
expand
(
load_params
(
"sox_effect_test_args.json"
),
load_params
(
"sox_effect_test_args.json"
),
...
...
test/torchaudio_unittest/utils/sox_utils_test.py
View file @
ecfed4d9
...
@@ -2,11 +2,11 @@ from torchaudio.utils import sox_utils
...
@@ -2,11 +2,11 @@ from torchaudio.utils import sox_utils
from
torchaudio_unittest.common_utils
import
(
from
torchaudio_unittest.common_utils
import
(
PytorchTestCase
,
PytorchTestCase
,
skipIfNo
Extension
,
skipIfNo
Sox
,
)
)
@
skipIfNo
Extension
@
skipIfNo
Sox
class
TestSoxUtils
(
PytorchTestCase
):
class
TestSoxUtils
(
PytorchTestCase
):
"""Smoke tests for sox_util module"""
"""Smoke tests for sox_util module"""
def
test_set_seed
(
self
):
def
test_set_seed
(
self
):
...
...
third_party/CMakeLists.txt
View file @
ecfed4d9
...
@@ -10,12 +10,8 @@ if (BUILD_SOX)
...
@@ -10,12 +10,8 @@ if (BUILD_SOX)
add_subdirectory
(
sox
)
add_subdirectory
(
sox
)
target_include_directories
(
libsox INTERFACE
${
SOX_INCLUDE_DIR
}
)
target_include_directories
(
libsox INTERFACE
${
SOX_INCLUDE_DIR
}
)
target_link_libraries
(
libsox INTERFACE
${
SOX_LIBRARIES
}
)
target_link_libraries
(
libsox INTERFACE
${
SOX_LIBRARIES
}
)
else
()
list
(
APPEND TORCHAUDIO_THIRD_PARTIES libsox
)
# If not building and linking libsox statically, then we expect that
# sox library and header are found in search path
target_link_libraries
(
libsox INTERFACE -lsox
)
endif
()
endif
()
list
(
APPEND TORCHAUDIO_THIRD_PARTIES libsox
)
################################################################################
################################################################################
# kaldi
# kaldi
...
...
torchaudio/_internal/module_utils.py
View file @
ecfed4d9
...
@@ -3,6 +3,8 @@ import importlib.util
...
@@ -3,6 +3,8 @@ import importlib.util
from
typing
import
Optional
from
typing
import
Optional
from
functools
import
wraps
from
functools
import
wraps
import
torch
def
is_module_available
(
*
modules
:
str
)
->
bool
:
def
is_module_available
(
*
modules
:
str
)
->
bool
:
r
"""Returns if a top-level module with :attr:`name` exists *without**
r
"""Returns if a top-level module with :attr:`name` exists *without**
...
@@ -56,3 +58,20 @@ def deprecated(direction: str, version: Optional[str] = None):
...
@@ -56,3 +58,20 @@ def deprecated(direction: str, version: Optional[str] = None):
return
func
(
*
args
,
**
kwargs
)
return
func
(
*
args
,
**
kwargs
)
return
wrapped
return
wrapped
return
decorator
return
decorator
def
is_sox_available
():
return
is_module_available
(
'torchaudio._torchaudio'
)
and
torch
.
ops
.
torchaudio
.
is_sox_available
()
def
requires_sox
():
if
is_sox_available
():
def
decorator
(
func
):
return
func
else
:
def
decorator
(
func
):
@
wraps
(
func
)
def
wrapped
(
*
args
,
**
kwargs
):
raise
RuntimeError
(
f
'
{
func
.
__module__
}
.
{
func
.
__name__
}
requires sox'
)
return
wrapped
return
decorator
torchaudio/backend/sox_io_backend.py
View file @
ecfed4d9
...
@@ -10,7 +10,7 @@ import torchaudio
...
@@ -10,7 +10,7 @@ import torchaudio
from
.common
import
AudioMetaData
from
.common
import
AudioMetaData
@
_mod_utils
.
requires_
module
(
'torchaudio._torchaudio'
)
@
_mod_utils
.
requires_
sox
(
)
def
info
(
def
info
(
filepath
:
str
,
filepath
:
str
,
format
:
Optional
[
str
]
=
None
,
format
:
Optional
[
str
]
=
None
,
...
@@ -54,7 +54,7 @@ def info(
...
@@ -54,7 +54,7 @@ def info(
return
AudioMetaData
(
*
sinfo
)
return
AudioMetaData
(
*
sinfo
)
@
_mod_utils
.
requires_
module
(
'torchaudio._torchaudio'
)
@
_mod_utils
.
requires_
sox
(
)
def
load
(
def
load
(
filepath
:
str
,
filepath
:
str
,
frame_offset
:
int
=
0
,
frame_offset
:
int
=
0
,
...
@@ -151,7 +151,7 @@ def load(
...
@@ -151,7 +151,7 @@ def load(
filepath
,
frame_offset
,
num_frames
,
normalize
,
channels_first
,
format
)
filepath
,
frame_offset
,
num_frames
,
normalize
,
channels_first
,
format
)
@
_mod_utils
.
requires_
module
(
'torchaudio._torchaudio'
)
@
_mod_utils
.
requires_
sox
(
)
def
save
(
def
save
(
filepath
:
str
,
filepath
:
str
,
src
:
torch
.
Tensor
,
src
:
torch
.
Tensor
,
...
...
torchaudio/backend/utils.py
View file @
ecfed4d9
...
@@ -3,7 +3,7 @@ import warnings
...
@@ -3,7 +3,7 @@ import warnings
from
typing
import
Optional
,
List
from
typing
import
Optional
,
List
import
torchaudio
import
torchaudio
from
torchaudio._internal
.
module_utils
import
is_module_available
from
torchaudio._internal
import
module_utils
as
_mod_utils
from
.
import
(
from
.
import
(
no_backend
,
no_backend
,
sox_io_backend
,
sox_io_backend
,
...
@@ -24,9 +24,9 @@ def list_audio_backends() -> List[str]:
...
@@ -24,9 +24,9 @@ def list_audio_backends() -> List[str]:
List[str]: The list of available backends.
List[str]: The list of available backends.
"""
"""
backends
=
[]
backends
=
[]
if
is_module_available
(
'soundfile'
):
if
_mod_utils
.
is_module_available
(
'soundfile'
):
backends
.
append
(
'soundfile'
)
backends
.
append
(
'soundfile'
)
if
is
_mod
ule_available
(
'torchaudio._torchaudio'
):
if
_mod
_utils
.
is_sox_available
(
):
backends
.
append
(
'sox_io'
)
backends
.
append
(
'sox_io'
)
return
backends
return
backends
...
...
Prev
1
2
Next
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