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) np.ndarray[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.

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
>>> pyls.extract_f0(x, fs)
array([193.86025508, 198.46273078, 199.65873847, 199.98109482,
       199.99103883, 199.99119509])
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) 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.

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)
>>> ap.mean(0)
array([0.17473351, 0.1747341 , 0.17473478, ..., 0.66521378, 0.66521439,
       0.66521501])
pylstraight.extract_sp(x: np.ndarray, fs: int, f0: np.ndarray, *, frame_shift: float = 5.0, f0_format: str = 'linear', sp_format: str = 'linear', sp_param: SpParam | None = None) np.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.

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)
>>> sp.mean(0)
array([  9.3790045 ,   9.3959332 ,   9.44756499, ..., -74.57928489,
       -74.57916264, -74.57908274])
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.