Analysis#

pylstraight.extract_f0(x: np.ndarray, fs: int, *, frame_shift: float = 5.0, f0_range: tuple[float, float] = (40.0, 400.0), f0_format: str = 'linear', f0_param: F0Param | None = None, return_aux: bool = False, refine_f0_range: bool = False, gamma: float = 3.0, seed: int | None = None) → np.ndarray | tuple[np.ndarray, SimpleNamespace][source]#

Extract F0 from waveform.

Parameters:
xnp.ndarray [shape=(nsample,) or (nchannel, nsample)]

The input waveform. If multi-channel, it will be averaged.

fsint

The sampling frequency in Hz.

frame_shiftfloat

The frame shift in msec.

f0_rangetuple[float, float]

The lower and upper bounds of F0 search in Hz.

f0_format[‘inverse’, ‘linear’, ‘log’]

The output format.

f0_paramF0Param or None

Control parameters for the F0 extraction. If given, override the other parameters. You have full control and responsibility.

return_auxbool

Whether to return the auxiliary outputs.

refine_f0_rangebool

Whether to refine the F0 search range based on the initial F0 statistics.

gammafloat

The width factor for the F0 range refinement.

seedint or None

The random seed to make the results reproducible.

Returns:
f0np.ndarray [shape=(nframe,)]

The fundamental frequency.

auxoutsSimpleNamespace (optional)

The auxiliary outputs.

Examples

>>> import pylstraight as pyls
>>> import numpy as np
>>> f, fs = 200, 16000
>>> x = np.mod(2 * np.pi * f / fs * np.arange(600), 2 * np.pi) - np.pi
>>> f0 = pyls.extract_f0(x, fs)
>>> f0.round()
array([193., 198., 200., 200., 200., 200.])
pylstraight.extract_ap(x: np.ndarray, fs: int, f0: np.ndarray, aux: SimpleNamespace | None = None, *, frame_shift: float = 5.0, ap_floor: float = 0.001, f0_format: str = 'linear', ap_format: str = 'a', ap_param: ApParam | None = None, seed: int | None = None) → np.ndarray[source]#

Extract aperiodicity from waveform.

Parameters:
xnp.ndarray [shape=(nsample,) or (nchannel, nsample)]

The input waveform. If multi-channel, it will be averaged.

fsint

The sampling frequency in Hz.

f0np.ndarray [shape=(nframe,)]

The fundamental frequency.

auxSimpleNamespace or None

The auxiliary outputs from extract_f0.

frame_shiftfloat

The frame shift in msec.

ap_floorfloat

The minimum value of aperiodicity.

f0_format[‘inverse’, ‘linear’, ‘log’]

The input format of the F0.

ap_format[‘a’, ‘p’, ‘a/p’, ‘p/a’]

The output format.

ap_paramApParam or None

Control parameters for the aperiodicity extraction. If given, override the other parameters. You have full control and responsibility.

seedint or None

The random seed to make the results reproducible.

Returns:
outnp.ndarray [shape=(nframe, nfreq)]

The aperiodicity.

Examples

>>> import pylstraight as pyls
>>> import numpy as np
>>> f, fs = 200, 16000
>>> x = np.sin(2 * np.pi * f / fs * np.arange(640))
>>> f0 = np.ones(8) * f
>>> ap = pyls.extract_ap(x, fs, f0)
>>> ap.shape
(8, 1025)
>>> float(ap.min())
0.001
>>> float(ap.max().round(decimals=1))
1.0
pylstraight.extract_sp(x: ndarray, fs: int, f0: ndarray, *, frame_shift: float = 5.0, f0_format: str = 'linear', sp_format: str = 'linear', sp_param: SpParam | None = None, seed: int | None = None) → ndarray[source]#

Extract spectrum from waveform.

Parameters:
xnp.ndarray [shape=(nsample,) or (nchannel, nsample)]

The input waveform. If multi-channel, it will be averaged.

fsint

The sampling frequency in Hz.

f0np.ndarray [shape=(nframe,)]

The fundamental frequency.

frame_shiftfloat

The frame shift in msec.

f0_format[‘inverse’, ‘linear’, ‘log’]

The input format of the F0.

sp_format[‘db’, ‘log’, ‘linear’, ‘power’]

The output format.

sp_paramSpParam or None

Control parameters for the spectrum extraction. If given, override the other parameters. You have full control and responsibility.

seedint or None

The random seed to make the results reproducible.

Returns:
outnp.ndarray [shape=(nframe, nfreq)]

The spectrum.

Examples

>>> import pylstraight as pyls
>>> import numpy as np
>>> f, fs = 200, 16000
>>> x = np.sin(2 * np.pi * f / fs * np.arange(640))
>>> f0 = np.ones(8) * f
>>> sp = pyls.extract_sp(x, fs, f0, sp_format='db')
>>> sp.shape
(8, 1025)
>>> float(sp.min().round(decimals=2))
-89.85
>>> float(sp.max().round(decimals=2))
14.81
pylstraight.init_f0_param() → F0Param[source]#

Make a default F0 parameter set.

Returns:
outF0Param

Control parameter set for the F0 extraction.

pylstraight.init_ap_param() → ApParam[source]#

Make a default aperiodicity parameter set.

Returns:
outApParam

Control parameter set for the aperiodicity extraction.

pylstraight.init_sp_param() → SpParam[source]#

Make a default spectrum parameter set.

Returns:
outSpParam

Control parameter set for the spectrum extraction.