The Python API exposes the Rust core: the P.56 meter, the protection pre-filters, and the resampler. All numerical work happens in the compiled extension; the Python layer only marshals NumPy arrays.
p56_asl
¶
Extended ITU-T Rec. P.56 active speech level measurement.
Rust-core implementation of the P.56 speech voltmeter with blockwise streaming, P.56 protection pre-filters (NB/SWB/FB), resampling, and an extended mode that auto-calibrates the amplitude reference for signals whose peaks exceed full scale.
Modules:
-
cli–CLI module for Extended ITU-T Rec. P.56 - Active Speech Level (ASL).
Classes:
-
ActiveSpeechLevelMeter–Extended ITU-T Rec. P.56 active speech level meter (Rust core).
-
Measurement–Result of a completed measurement.
-
PreFilter–P.56 protection pre-filter (clause 10.2/Table 3, Annex B/C).
-
Resampler–Stateful FFT resampler from any input rate to any target rate, mono.
ActiveSpeechLevelMeter
¶
ActiveSpeechLevelMeter(sample_rate: float = 8000.0, block_size: int = 256, max_amplitude: float = 1.0, auto_calibrate: bool = False)
Extended ITU-T Rec. P.56 active speech level meter (Rust core).
Methods:
-
__new__–Create and return a new object. See help(type) for accurate signature.
-
finish–Finalizes the measurement: flushes the resampler (zero-padding the
-
process_block–Processes one block of samples given as a 1-D numpy array with
-
reset–Resets all accumulated state; configuration is kept.
Attributes:
-
__doc__–str(object='') -> str
-
__module__–str(object='') -> str
__doc__
class-attribute
¶
__doc__ = 'Extended ITU-T Rec. P.56 active speech level meter (Rust core).'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
__module__ = 'p56_asl._native'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__new__
builtin
¶
__new__(*args, **kwargs)
Create and return a new object. See help(type) for accurate signature.
finish
method descriptor
¶
finish() -> Measurement
Finalizes the measurement: flushes the resampler (zero-padding the final partial chunk) and processes any remaining 16 kHz samples.
process_block
method descriptor
¶
process_block(samples: NDArray[float32 | float64]) -> None
Processes one block of samples given as a 1-D numpy array with
dtype float32, float64, int8, int16 or int32 (int32 also covers
24-bit data stored in the low 24 bits — pass bit_depth=24).
Integer samples are normalized by their maximum representable
value. Input rates below 16 kHz are resampled to 16 kHz
automatically.
Measurement
¶
Result of a completed measurement.
Methods:
-
__repr__–Return repr(self).
Attributes:
-
__doc__–str(object='') -> str
-
__module__–str(object='') -> str
-
active_speech_level_db(float) –Active speech level, in dB re.
max_amplitude(dBov by default). -
activity_factor(float) –Activity factor, in
0..1. -
dc_level(float) –Average (DC) level of the input samples.
-
peak_abs(float) –Maximum absolute sample.
-
peak_negative(float) –Maximum negative sample (<= 0).
-
peak_positive(float) –Maximum positive sample.
-
rms_db(float) –Long-term RMS level, in dB re.
max_amplitude. -
sample_count(int) –Number of processed samples.
__doc__
class-attribute
¶
__doc__ = 'Result of a completed measurement.'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
__module__ = 'p56_asl._native'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
active_speech_level_db
property
¶
active_speech_level_db: float
Active speech level, in dB re. max_amplitude (dBov by default).
PreFilter
¶
PreFilter(band: str, fs: float)
P.56 protection pre-filter (clause 10.2/Table 3, Annex B/C).
Streaming-safe biquad cascade matching the tolerance corridor of the selected band (NB, SWB or FB) at the configured sampling rate.
Methods:
-
__new__–Create and return a new object. See help(type) for accurate signature.
-
process–Filters samples in place. Accepts a 1-D numpy array (float32 or
-
reset–Resets the filter state.
-
response_db–Magnitude response
|H(f)|at frequencyf(Hz), relative to 1 kHz.
Attributes:
-
__doc__–str(object='') -> str
-
__module__–str(object='') -> str
-
band(str) –Band name ("nb", "swb" or "fb").
-
num_sections(int) –Number of biquad sections.
-
sample_rate(float) –Sampling rate in Hz.
__doc__
class-attribute
¶
__doc__ = 'P.56 protection pre-filter (clause 10.2/Table 3, Annex B/C).\n\nStreaming-safe biquad cascade matching the tolerance corridor of the\nselected band (NB, SWB or FB) at the configured sampling rate.'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
__module__ = 'p56_asl._native'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__new__
builtin
¶
__new__(*args, **kwargs)
Create and return a new object. See help(type) for accurate signature.
process
method descriptor
¶
process(samples: NDArray[float32 | float64]) -> NDArray[float32]
Filters samples in place. Accepts a 1-D numpy array (float32 or float64) and returns a new float32 array.
response_db
method descriptor
¶
response_db(f: float) -> float
Magnitude response |H(f)| at frequency f (Hz), relative to 1 kHz.
Resampler
¶
Resampler(sample_rate: int, target_rate: int)
Stateful FFT resampler from any input rate to any target rate, mono.
Used by the CLI for --fs: streaming-safe — the rubato instance
carries its overlap across process calls. flush zero-pads the
final partial chunk and trims the ramp-up delay so the total output
length equals round(total_input * target / source).
Methods:
-
__new__–Create and return a new object. See help(type) for accurate signature.
-
flush–Zero-pads and drains; returns the final output samples.
-
process–Feeds samples (float32/float64 numpy array); returns all output
Attributes:
-
__doc__–str(object='') -> str
-
__module__–str(object='') -> str
-
sample_rate(int) –Source rate in Hz.
-
target_rate(int) –Target rate in Hz.
__doc__
class-attribute
¶
__doc__ = 'Stateful FFT resampler from any input rate to any target rate, mono.\n\nUsed by the CLI for `--fs`: streaming-safe — the rubato instance\ncarries its overlap across `process` calls. `flush` zero-pads the\nfinal partial chunk and trims the ramp-up delay so the total output\nlength equals `round(total_input * target / source)`.'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__module__
class-attribute
¶
__module__ = 'p56_asl._native'
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__new__
builtin
¶
__new__(*args, **kwargs)
Create and return a new object. See help(type) for accurate signature.
flush
method descriptor
¶
flush() -> list[float]
Zero-pads and drains; returns the final output samples.
process
method descriptor
¶
process(samples: NDArray[float32 | float64]) -> list[float]
Feeds samples (float32/float64 numpy array); returns all output available so far.
ActiveSpeechLevelMeter¶
Stateful P.56 speech voltmeter. Feed blocks of samples with
process_block, then call finish for the result. Results are in dB re.
full scale (1.0); see Measuring Above Full Scale for
the extended mode.
meter = ActiveSpeechLevelMeter(sample_rate=16000.0, block_size=256)
for block in stream:
meter.process_block(block) # NDArray[np.float32 | np.float64]
result = meter.finish() # Measurement
Constructor¶
ActiveSpeechLevelMeter(
sample_rate: float = 8000.0,
block_size: int = 256,
max_amplitude: float = 1.0,
auto_calibrate: bool = False,
)
| Parameter | Default | Description |
|---|---|---|
sample_rate |
8000 |
Analysis sample rate in Hz. |
block_size |
256 |
Upper bound on the chunk length accepted by process_block. |
max_amplitude |
1.0 |
Amplitude reference; the histogram grid spans max_amplitude / 2 downward in −6.02 dB steps. |
auto_calibrate |
False |
Extended mode: double max_amplitude (and shift the grid +6.02 dB) whenever a block peak exceeds it. |
block_size is a guard, not a window
Feeding one large block or many small ones is bit-identical: all
algorithmic state (envelope filters, histogram, accumulators) carries
across calls. block_size only bounds per-call buffer length.
Methods¶
| Method | Description |
|---|---|
process_block(samples) |
Feed one block (NDArray[np.float32 \| np.float64]); must not exceed block_size. |
finish() -> Measurement |
Finalize and return the measurement. Errors if no samples were fed. |
reset() |
Clear all accumulated state, keep the configuration. |
Properties¶
| Property | Type | Description |
|---|---|---|
sample_rate |
float |
Analysis rate. |
block_size |
int |
Configured chunk bound. |
max_amplitude |
float |
Current reference (adapted by auto-calibration). |
auto_calibrate |
bool |
Whether extended mode is active. |
Measurement¶
Result of a completed measurement. Values are dB re. full scale (1.0),
i.e. dBov.
| Property | Type | Description |
|---|---|---|
active_speech_level_db |
float |
Active speech level, dBov. |
activity_factor |
float |
Fraction of time the signal is active, 0..1. |
rms_db |
float |
Long-term RMS level, dBov. |
dc_level |
float |
Average (DC) level of the input samples. |
peak_positive |
float |
Maximum positive sample. |
peak_negative |
float |
Maximum negative sample (≤ 0). |
peak_abs |
float |
Maximum absolute sample. |
sample_count |
int |
Number of processed samples. |
PreFilter¶
P.56 protection pre-filter (band-limited speech weighting). Three bands are available, covering the frequency ranges defined in ITU-T Rec. P.56 Tables 3 / B.1 / C.1 — see P.56 Pre-Filter Bands.
pf = PreFilter(band="NB", fs=48000.0)
filtered = pf.process(block) # NDArray[np.float32]
| Parameter | Values | Description |
|---|---|---|
band |
"NB", "SWB", "FB" |
Narrowband / super-wideband / fullband. |
fs |
float |
Sample rate in Hz (coefficients are prewarped for it). |
Methods¶
| Method | Description |
|---|---|
process(samples) -> NDArray[np.float32] |
Apply the filter; the input array is processed in place and returned. |
reset() |
Clear the filter state (the sections keep their coefficients). |
response_db(f) -> float |
Magnitude response at frequency f in dB (verification aid). |
In-place filtering
PreFilter.process modifies the caller's buffer and returns it. Pass
samples.copy() if you need the original signal afterwards.
Properties¶
| Property | Type | Description |
|---|---|---|
band |
str |
The configured band. |
sample_rate |
float |
The configured rate. |
num_sections |
int |
Biquad section count (14/20/24 for NB/SWB/FB). |
Resampler¶
Sample-rate conversion for analysis and calibration. Stateful — call
process with input blocks, then flush to drain the tail.
rs = Resampler(sample_rate=44100, target_rate=48000)
out = rs.process(block) # list[float]
out += rs.flush() # residual tail samples
| Parameter | Type | Description |
|---|---|---|
sample_rate |
int |
Input rate in Hz. |
target_rate |
int |
Output rate in Hz. |
Methods¶
| Method | Description |
|---|---|
process(samples) -> list[float] |
Resample one block of input. |
flush() -> list[float] |
Drain the resampler tail after the last block. |
Properties¶
| Property | Type | Description |
|---|---|---|
sample_rate |
int |
Input rate. |
target_rate |
int |
Output rate. |
Command line interface¶
p56-asl measure and p56-asl calibrate — see the
CLI Reference. The CLI applies the same Rust core; it does not
currently expose auto_calibrate or the raw resampler/pre-filter objects.