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
6edb3355
Unverified
Commit
6edb3355
authored
Jan 05, 2021
by
Krishna Kalyan
Committed by
GitHub
Jan 05, 2021
Browse files
Refactor CMUARCTIC unittest (#1147)
Co-authored-by:
krishnakalyan3
<
skalyan@cloudera.com
>
parent
02e4f6d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
33 deletions
+42
-33
test/torchaudio_unittest/datasets/cmuarctic_test.py
test/torchaudio_unittest/datasets/cmuarctic_test.py
+42
-33
No files found.
test/torchaudio_unittest/datasets/cmuarctic_test.py
View file @
6edb3355
...
@@ -12,6 +12,47 @@ from torchaudio_unittest.common_utils import (
...
@@ -12,6 +12,47 @@ from torchaudio_unittest.common_utils import (
)
)
def
get_mock_dataset
(
root_dir
):
"""
root_dir: directory to the mocked dataset
"""
mocked_data
=
[]
sample_rate
=
16000
utterance
=
"This is a test utterance."
base_dir
=
os
.
path
.
join
(
root_dir
,
"ARCTIC"
,
"cmu_us_aew_arctic"
)
txt_dir
=
os
.
path
.
join
(
base_dir
,
"etc"
)
os
.
makedirs
(
txt_dir
,
exist_ok
=
True
)
txt_file
=
os
.
path
.
join
(
txt_dir
,
"txt.done.data"
)
audio_dir
=
os
.
path
.
join
(
base_dir
,
"wav"
)
os
.
makedirs
(
audio_dir
,
exist_ok
=
True
)
seed
=
42
with
open
(
txt_file
,
"w"
)
as
txt
:
for
c
in
[
"a"
,
"b"
]:
for
i
in
range
(
5
):
utterance_id
=
f
"arctic_
{
c
}{
i
:
04
d
}
"
path
=
os
.
path
.
join
(
audio_dir
,
f
"
{
utterance_id
}
.wav"
)
data
=
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
3
,
n_channels
=
1
,
dtype
=
"int16"
,
seed
=
seed
,
)
save_wav
(
path
,
data
,
sample_rate
)
sample
=
(
normalize_wav
(
data
),
sample_rate
,
utterance
,
utterance_id
.
split
(
"_"
)[
1
],
)
mocked_data
.
append
(
sample
)
txt
.
write
(
f
'(
{
utterance_id
}
"
{
utterance
}
" )
\n
'
)
seed
+=
1
return
mocked_data
class
TestCMUARCTIC
(
TempDirMixin
,
TorchaudioTestCase
):
class
TestCMUARCTIC
(
TempDirMixin
,
TorchaudioTestCase
):
backend
=
"default"
backend
=
"default"
...
@@ -21,39 +62,7 @@ class TestCMUARCTIC(TempDirMixin, TorchaudioTestCase):
...
@@ -21,39 +62,7 @@ class TestCMUARCTIC(TempDirMixin, TorchaudioTestCase):
@
classmethod
@
classmethod
def
setUpClass
(
cls
):
def
setUpClass
(
cls
):
cls
.
root_dir
=
cls
.
get_base_temp_dir
()
cls
.
root_dir
=
cls
.
get_base_temp_dir
()
sample_rate
=
16000
cls
.
samples
=
get_mock_dataset
(
cls
.
root_dir
)
utterance
=
"This is a test utterance."
base_dir
=
os
.
path
.
join
(
cls
.
root_dir
,
"ARCTIC"
,
"cmu_us_aew_arctic"
)
txt_dir
=
os
.
path
.
join
(
base_dir
,
"etc"
)
os
.
makedirs
(
txt_dir
,
exist_ok
=
True
)
txt_file
=
os
.
path
.
join
(
txt_dir
,
"txt.done.data"
)
audio_dir
=
os
.
path
.
join
(
base_dir
,
"wav"
)
os
.
makedirs
(
audio_dir
,
exist_ok
=
True
)
seed
=
42
with
open
(
txt_file
,
"w"
)
as
txt
:
for
c
in
[
"a"
,
"b"
]:
for
i
in
range
(
5
):
utterance_id
=
f
"arctic_
{
c
}{
i
:
04
d
}
"
path
=
os
.
path
.
join
(
audio_dir
,
f
"
{
utterance_id
}
.wav"
)
data
=
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
3
,
n_channels
=
1
,
dtype
=
"int16"
,
seed
=
seed
,
)
save_wav
(
path
,
data
,
sample_rate
)
sample
=
(
normalize_wav
(
data
),
sample_rate
,
utterance
,
utterance_id
.
split
(
"_"
)[
1
],
)
cls
.
samples
.
append
(
sample
)
txt
.
write
(
f
'(
{
utterance_id
}
"
{
utterance
}
" )
\n
'
)
seed
+=
1
def
_test_cmuarctic
(
self
,
dataset
):
def
_test_cmuarctic
(
self
,
dataset
):
n_ite
=
0
n_ite
=
0
...
...
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