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
82965683
Unverified
Commit
82965683
authored
Jun 09, 2020
by
moto
Committed by
GitHub
Jun 09, 2020
Browse files
Initialize backend in backend.__init__ (#707)
parent
b788db3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
torchaudio/backend/__init__.py
torchaudio/backend/__init__.py
+4
-0
torchaudio/backend/utils.py
torchaudio/backend/utils.py
+20
-10
No files found.
torchaudio/backend/__init__.py
View file @
82965683
from
.
import
utils
from
.utils
import
(
_get_audio_backend_module
,
list_audio_backends
,
...
...
@@ -16,3 +17,6 @@ from .common import (
SignalInfo
,
EncodingInfo
,
)
utils
.
_init_audio_backend
()
torchaudio/backend/utils.py
View file @
82965683
import
warnings
from
typing
import
Any
,
Optional
from
torchaudio._internal
import
module_utils
as
_mod_utils
...
...
@@ -6,16 +7,6 @@ from . import soundfile_backend, sox_backend
_BACKEND
=
None
_BACKENDS
=
{}
if
_mod_utils
.
is_module_available
(
'soundfile'
):
_BACKENDS
[
'soundfile'
]
=
soundfile_backend
if
_mod_utils
.
is_module_available
(
'torchaudio._torchaudio'
):
_BACKENDS
[
'sox'
]
=
sox_backend
if
'sox'
in
_BACKENDS
:
_BACKEND
=
'sox'
elif
'soundfile'
in
_BACKENDS
:
_BACKEND
=
'soundfile'
def
list_audio_backends
():
return
list
(
_BACKENDS
.
keys
())
...
...
@@ -50,3 +41,22 @@ def _get_audio_backend_module() -> Any:
if
_BACKEND
is
None
:
raise
RuntimeError
(
'Backend is not initialized.'
)
return
_BACKENDS
[
_BACKEND
]
def
_init_audio_backend
():
global
_BACKEND
global
_BACKENDS
_BACKENDS
=
{}
if
_mod_utils
.
is_module_available
(
'soundfile'
):
_BACKENDS
[
'soundfile'
]
=
soundfile_backend
if
_mod_utils
.
is_module_available
(
'torchaudio._torchaudio'
):
_BACKENDS
[
'sox'
]
=
sox_backend
if
'sox'
in
_BACKENDS
:
_BACKEND
=
'sox'
elif
'soundfile'
in
_BACKENDS
:
_BACKEND
=
'soundfile'
else
:
warnings
.
warn
(
'No audio backend is available.'
)
_BACKEND
=
None
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