soxr package#
- class soxr.ResampleStream(in_rate: float, out_rate: float, num_channels: int, dtype='float32', quality='HQ')#
Streaming resampler
Use ResampleStream for real-time processing or very long signal.
- Parameters:
in_rate (float) – Input sample-rate.
out_rate (float) – Output sample-rate.
num_channels (int) – Number of channels.
dtype (type or str, optional) – Internal data type processed with. Should be one of float32, float64, int16, int32.
quality (int or str, optional) – Quality setting. One of QQ, LQ, MQ, HQ, VHQ.
- clear() None#
Reset resampler. Ready for fresh signal, same config.
This can be used to save initialization time.
- delay() float#
Get current delay.
SoXR output has an algorithmic delay. This function returns the length of current pending output.
- Returns:
Current delay in output samples.
- Return type:
float
- num_clips() int#
Clip counter. (for int I/O)
- Returns:
Count of clipped samples.
- Return type:
int
- resample_chunk(x: numpy.ndarray, last=False) numpy.ndarray#
Resample chunk with streaming resampler
- Parameters:
x (np.ndarray) – Input array. Input can be mono(1D) or multi-channel(2D of [frame, channel]). dtype should match with constructor.
last (bool, optional) – Set True at final chunk to flush last outputs. It should be True only once at the end of a continuous sequence.
- Returns:
Resampled data. Output is np.ndarray with same ndim with input.
- Return type:
np.ndarray
- soxr.resample(x: numpy.typing.ArrayLike, in_rate: float, out_rate: float, quality='HQ') numpy.ndarray#
Resample signal
- Parameters:
x (array_like) – Input array. Input can be mono(1D) or multi-channel(2D of [frame, channel]). If input is not np.ndarray, it will be converted to np.ndarray(dtype=’float32’). Its dtype should be one of float32, float64, int16, int32.
in_rate (float) – Input sample-rate.
out_rate (float) – Output sample-rate.
quality (int or str, optional) – Quality setting. One of QQ, LQ, MQ, HQ, VHQ.
- Returns:
Resampled data. Output is np.ndarray with same ndim and dtype with input.
- Return type:
np.ndarray