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
df2a6bcd
Unverified
Commit
df2a6bcd
authored
Nov 09, 2023
by
Yangze Luo
Committed by
GitHub
Nov 09, 2023
Browse files
Fix vad to return zero output for zero input (#3685)
When the input is zero Tensor, the result should be empty.
parent
d4cf8d54
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
src/torchaudio/functional/filtering.py
src/torchaudio/functional/filtering.py
+3
-0
test/torchaudio_unittest/transforms/transforms_test_impl.py
test/torchaudio_unittest/transforms/transforms_test_impl.py
+15
-0
No files found.
src/torchaudio/functional/filtering.py
View file @
df2a6bcd
...
@@ -1660,6 +1660,9 @@ def vad(
...
@@ -1660,6 +1660,9 @@ def vad(
flushedLen_ns
=
(
measures_len
-
num_measures_to_flush
)
*
measure_period_ns
flushedLen_ns
=
(
measures_len
-
num_measures_to_flush
)
*
measure_period_ns
break
break
# end for window
# end for window
if
not
has_triggered
:
return
waveform
[...,
:
0
].
view
(
shape
[:
-
1
]
+
torch
.
Size
([
0
]))
res
=
waveform
[:,
pos
-
samplesLen_ns
+
flushedLen_ns
:]
res
=
waveform
[:,
pos
-
samplesLen_ns
+
flushedLen_ns
:]
# unpack batch
# unpack batch
return
res
.
view
(
shape
[:
-
1
]
+
res
.
shape
[
-
1
:])
return
res
.
view
(
shape
[:
-
1
]
+
res
.
shape
[
-
1
:])
test/torchaudio_unittest/transforms/transforms_test_impl.py
View file @
df2a6bcd
...
@@ -478,3 +478,18 @@ class TransformsTestBase(TestBaseMixin):
...
@@ -478,3 +478,18 @@ class TransformsTestBase(TestBaseMixin):
self
.
assertTrue
(
diff
>
0
)
self
.
assertTrue
(
diff
>
0
)
else
:
else
:
self
.
assertTrue
(
diff
==
0
)
self
.
assertTrue
(
diff
==
0
)
@
parameterized
.
expand
(
[
((
32000
,),
(
0
,),
16000
),
((
1
,
32000
),
(
1
,
0
),
32000
),
((
2
,
44100
),
(
2
,
0
),
32000
),
((
2
,
2
,
44100
),
(
2
,
2
,
0
),
32000
),
]
)
def
test_vad_on_zero_audio
(
self
,
input_shape
,
output_shape
,
sample_rate
:
int
):
"""VAD should return zero when input is zero Tensor"""
inpt
=
torch
.
zeros
(
input_shape
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
expected_output
=
torch
.
zeros
(
output_shape
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
result
=
T
.
Vad
(
sample_rate
)(
inpt
)
self
.
assertEqual
(
result
,
expected_output
)
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