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
17aa81ea
Unverified
Commit
17aa81ea
authored
Feb 01, 2021
by
Nicolas Hug
Committed by
GitHub
Feb 01, 2021
Browse files
Update SpectralCentroid to accept window_fn and wkwargs (#1216)
parent
114461cc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
torchaudio/transforms.py
torchaudio/transforms.py
+6
-5
No files found.
torchaudio/transforms.py
View file @
17aa81ea
...
...
@@ -1087,8 +1087,9 @@ class SpectralCentroid(torch.nn.Module):
win_length (int or None, optional): Window size. (Default: ``n_fft``)
hop_length (int or None, optional): Length of hop between STFT windows. (Default: ``win_length // 2``)
pad (int, optional): Two sided padding of signal. (Default: ``0``)
window(Tensor, optional): A window tensor that is applied/multiplied to each frame.
(Default: ``torch.hann_window(win_length)``)
window_fn (Callable[..., Tensor], optional): A function to create a window tensor
that is applied/multiplied to each frame/window. (Default: ``torch.hann_window``)
wkwargs (dict or None, optional): Arguments for window function. (Default: ``None``)
Example
>>> waveform, sample_rate = torchaudio.load('test.wav', normalization=True)
...
...
@@ -1102,14 +1103,14 @@ class SpectralCentroid(torch.nn.Module):
win_length
:
Optional
[
int
]
=
None
,
hop_length
:
Optional
[
int
]
=
None
,
pad
:
int
=
0
,
window
:
Optional
[
Tensor
]
=
None
)
->
None
:
window_fn
:
Callable
[...,
Tensor
]
=
torch
.
hann_window
,
wkwargs
:
Optional
[
dict
]
=
None
)
->
None
:
super
(
SpectralCentroid
,
self
).
__init__
()
self
.
sample_rate
=
sample_rate
self
.
n_fft
=
n_fft
self
.
win_length
=
win_length
if
win_length
is
not
None
else
n_fft
self
.
hop_length
=
hop_length
if
hop_length
is
not
None
else
self
.
win_length
//
2
if
window
is
None
:
window
=
torch
.
hann_window
(
self
.
win_length
)
window
=
window_fn
(
self
.
win_length
)
if
wkwargs
is
None
else
window_fn
(
self
.
win_length
,
**
wkwargs
)
self
.
register_buffer
(
'window'
,
window
)
self
.
pad
=
pad
...
...
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