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
4f0acc58
Unverified
Commit
4f0acc58
authored
Oct 09, 2020
by
Vincent QB
Committed by
GitHub
Oct 09, 2020
Browse files
fix tedlium load_audio (#934)
and add test on other backend.
parent
725f8b06
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
7 deletions
+34
-7
test/torchaudio_unittest/common_utils/backend_utils.py
test/torchaudio_unittest/common_utils/backend_utils.py
+5
-1
test/torchaudio_unittest/datasets/tedlium_test.py
test/torchaudio_unittest/datasets/tedlium_test.py
+21
-3
torchaudio/datasets/tedlium.py
torchaudio/datasets/tedlium.py
+8
-3
No files found.
test/torchaudio_unittest/common_utils/backend_utils.py
View file @
4f0acc58
...
...
@@ -6,11 +6,15 @@ import torchaudio
def
set_audio_backend
(
backend
):
"""Allow additional backend value, 'default'"""
backends
=
torchaudio
.
list_audio_backends
()
if
backend
==
'default'
:
if
backend
==
'soundfile-new'
:
be
=
'soundfile'
torchaudio
.
USE_SOUNDFILE_LEGACY_INTERFACE
=
False
elif
backend
==
'default'
:
if
'sox_io'
in
backends
:
be
=
'sox_io'
elif
'soundfile'
in
backends
:
be
=
'soundfile'
torchaudio
.
USE_SOUNDFILE_LEGACY_INTERFACE
=
True
else
:
raise
unittest
.
SkipTest
(
'No default backend available'
)
else
:
...
...
test/torchaudio_unittest/datasets/tedlium_test.py
View file @
4f0acc58
import
os
import
platform
import
unittest
from
torchaudio.datasets
import
tedlium
from
torchaudio_unittest.common_utils
import
(
TestBaseMixin
,
TempDirMixin
,
TorchaudioTestCase
,
get_whitenoise
,
...
...
@@ -30,9 +33,7 @@ PHONEME = [
]
class
TestTedlium
(
TempDirMixin
,
TorchaudioTestCase
):
backend
=
"default"
class
Tedlium
(
TempDirMixin
):
root_dir
=
None
samples
=
{}
...
...
@@ -151,3 +152,20 @@ class TestTedlium(TempDirMixin, TorchaudioTestCase):
phoneme_dict
=
dataset
.
phoneme_dict
phoenemes
=
[
f
"
{
key
}
{
' '
.
join
(
value
)
}
"
for
key
,
value
in
phoneme_dict
.
items
()]
assert
phoenemes
==
PHONEME
class
TestTedliumSoundfile
(
Tedlium
,
TorchaudioTestCase
):
backend
=
"soundfile"
class
TestTedliumSoundfileNew
(
Tedlium
,
TorchaudioTestCase
):
backend
=
"soundfile-new"
if
platform
.
system
()
!=
"Windows"
:
class
TestTedliumSox
(
Tedlium
,
TorchaudioTestCase
):
backend
=
"sox"
class
TestTedliumSoxIO
(
Tedlium
,
TorchaudioTestCase
):
backend
=
"sox_io"
torchaudio/datasets/tedlium.py
View file @
4f0acc58
...
...
@@ -143,9 +143,14 @@ class TEDLIUM(Dataset):
"""
start_time
=
int
(
float
(
start_time
)
*
sample_rate
)
end_time
=
int
(
float
(
end_time
)
*
sample_rate
)
if
torchaudio
.
get_audio_backend
()
==
"sox_io"
:
return
torchaudio
.
load
(
path
,
frame_offset
=
start_time
,
num_frames
=
end_time
-
start_time
)
return
torchaudio
.
load
(
path
)[:,
start_time
:
end_time
]
backend
=
torchaudio
.
get_audio_backend
()
if
backend
==
"sox"
or
(
backend
==
"soundfile"
and
torchaudio
.
USE_SOUNDFILE_LEGACY_INTERFACE
):
kwargs
=
{
"offset"
:
start_time
,
"num_frames"
:
end_time
-
start_time
}
else
:
kwargs
=
{
"frame_offset"
:
start_time
,
"num_frames"
:
end_time
-
start_time
}
return
torchaudio
.
load
(
path
,
**
kwargs
)
def
__getitem__
(
self
,
n
:
int
)
->
Tuple
[
Tensor
,
int
,
str
,
int
,
int
,
int
]:
"""Load the n-th sample from the dataset.
...
...
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