feat_util
Author: Heli Qi Affiliation: NAIST Date: 2022.12
compute_stft(wav, n_fft, hop_length, win_length, window='hann', center=True)
A drop-in replacement for librosa.stft() implemented with numpy and scipy, so that speechain doesn't have to depend on librosa. It assumes zero-padded centering (center=True) and produces bit-identical results to librosa.stft() for the same arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wav
|
ndarray
|
(n_sample,) The single-channel waveform to be processed. |
required |
n_fft
|
int
|
int The number of Fourier points. |
required |
hop_length
|
int
|
int The number of time steps between two adjacent frames. |
required |
win_length
|
int
|
int The window length used to extract each frame. |
required |
window
|
str
|
str The window function used to extract each frame. Has to be a name recognized by scipy.signal.get_window(). |
'hann'
|
center
|
bool
|
bool Whether to pad the waveform so that the t-th frame is centered at wav[t * hop_length]. |
True
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The complex-valued STFT results in the shape (1 + n_fft // 2, n_frame). |
Source code in speechain/utilbox/feat_util.py
convert_wav_to_logmel(wav, n_mels, hop_length, win_length, sr=16000, n_fft=None, preemphasis=None, pre_stft_norm=None, window='hann', center=True, mag_spec=False, fmin=0.0, fmax=None, clamp=1e-10, logging=True, log_base=10.0, htk=False, norm='slaney', delta_order=0, delta_N=2)
For the details about the arguments and returns, please refer to ${SPEECHAIN_ROOT}/speechain/module/frontend/speech2mel.py.
Source code in speechain/utilbox/feat_util.py
convert_wav_to_mfcc(wav, hop_length, win_length, num_ceps=None, n_mfcc=20, sr=16000, n_fft=None, n_mels=80, preemphasis=None, pre_stft_norm=None, window='hann', center=True, fmin=0.0, fmax=None, clamp=1e-10, logging=True, log_base=10.0, htk=False, norm='slaney', delta_order=0, delta_N=2)
For the details about the arguments and returns, please refer to ${SPEECHAIN_ROOT}/speechain/utilbox/feat_util.convert_wav_to_logmel() and scipy.fftpack.dct.
Source code in speechain/utilbox/feat_util.py
convert_wav_to_pitch(wav, hop_length=256, sr=22050, f0min=80, f0max=400, continuous_f0=True, return_tensor=False)
The function that converts a waveform to a pitch contour by dio & stonemask of pyworld.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wav
|
ndarray or Tensor
|
(n_sample, 1) or (n_sample,) The waveform to be processed. |
required |
hop_length
|
int or float
|
int = 256 The value of the argument 'hop_length' given to pyworld.dio() |
256
|
sr
|
int
|
int = 22050 The value of the argument 'fs' given to pyworld.dio() |
22050
|
f0min
|
int
|
int = 80 The value of the argument 'f0min' given to pyworld.dio() |
80
|
f0max
|
int
|
int = 400 The value of the argument 'f0max' given to pyworld.dio() |
400
|
continuous_f0
|
bool
|
bool = True Whether to make the calculated pitch values continuous over time. |
True
|
return_tensor
|
bool
|
bool Whether to return the pitch in torch.Tensor. If False, np.ndarray will be returned. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
f0 |
ndarray or Tensor
|
(n_frame,) |
Source code in speechain/utilbox/feat_util.py
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | |
convert_wav_to_stft(wav, hop_length, win_length, sr=16000, n_fft=None, preemphasis=None, pre_stft_norm=None, window='hann', center=True, mag_spec=False, clamp=1e-10, logging=False, log_base=None)
For the details about the arguments and returns, please refer to ${SPEECHAIN_ROOT}/speechain/module/frontend/speech2linear.py.
Source code in speechain/utilbox/feat_util.py
mel_filterbank(sr, n_fft, n_mels, fmin=0.0, fmax=None, htk=False, norm='slaney')
A drop-in replacement for librosa.filters.mel() based on torchaudio.functional.melscale_fbanks(), which speechain already depends on for its main mel-spectrogram frontend (speechain/module/frontend/linear2mel.py).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sr
|
int
|
int The sampling rate of the incoming signal. |
required |
n_fft
|
int
|
int The number of Fourier points used to obtain the linear spectrogram. |
required |
n_mels
|
int
|
int The number of filters in the mel-fbank. |
required |
fmin
|
float
|
float The minimal frequency for the mel-fbank. |
0.0
|
fmax
|
float
|
float The maximal frequency for the mel-fbank. sr / 2 is used if not given. |
None
|
htk
|
bool
|
bool Whether to use the HTK formula instead of the Slaney one for the mel scale. |
False
|
norm
|
str or None
|
str or None Whether to perform Slaney-style area normalization on the mel-fbank filters. |
'slaney'
|
Returns:
| Type | Description |
|---|---|
ndarray
|
The mel-fbank matrix in the shape (n_mels, 1 + n_fft // 2). |