HNRExtractor#

Defined in: voxatlas.features.acoustic.voice_quality.hnr

class voxatlas.features.acoustic.voice_quality.hnr.HNRExtractor[source]#

Bases: BaseExtractor

Extract the acoustic.voice_quality.hnr feature within the VoxAtlas pipeline.

This public extractor defines the reusable API for computing acoustic.voice_quality.hnr from VoxAtlas structured inputs. It consumes None units and produces values aligned to frame units, making the extractor a stable pipeline node that can be cited independently of the surrounding execution machinery.

Algorithm#

The extractor estimates harmonic-to-noise ratio from voiced waveform frames aligned with the \(f_0\) contour.

  1. Frame partitioning The waveform is split into frame-like segments synchronized with the pitch track.

  2. Autocorrelation analysis For each voiced frame, the strongest non-zero-lag autocorrelation peak is treated as harmonic energy \(H\), and residual energy is treated as noise \(N\).

  3. Ratio in decibels The returned value is

    \[\mathrm{HNR}_t = 10\log_{10}\left(\frac{H}{N}\right).\]
  4. Packaging Invalid or unvoiced frames remain undefined to preserve methodological transparency.

Notes

This extractor declares the upstream dependencies [‘acoustic.pitch.f0’] and is executed only after those features are available in the pipeline feature store.

Examples

>>> import numpy as np
>>> from voxatlas.audio.audio import Audio
>>> from voxatlas.features.acoustic.voice_quality.hnr import HNRExtractor
>>> from voxatlas.features.feature_input import FeatureInput
>>> from voxatlas.features.feature_output import VectorFeatureOutput
>>> from voxatlas.pipeline.feature_store import FeatureStore
>>> audio = Audio(waveform=np.zeros(1600, dtype=np.float32), sample_rate=16000)
>>> store = FeatureStore()
>>> f0_out = VectorFeatureOutput(
...     feature="acoustic.pitch.f0",
...     unit="frame",
...     time=np.array([0.0, 0.01, 0.02, 0.03], dtype=np.float32),
...     values=np.array([100.0, 100.0, 100.0, 100.0], dtype=np.float32),
... )
>>> store.add("acoustic.pitch.f0", f0_out)
>>> feature_input = FeatureInput(audio=audio, units=None, context={"feature_store": store})
>>> out = HNRExtractor().compute(feature_input, {})
>>> out.values.tolist()
[0.0, 0.0, 0.0, 0.0]
name: str = 'acoustic.voice_quality.hnr'#
input_units: str | None = None#
output_units: str | None = 'frame'#
dependencies: list[str] = ['acoustic.pitch.f0']#
default_config: dict = {}#
compute(feature_input, params)[source]#

Compute the extractor output for a single pipeline invocation.

This method is the reusable execution entry point for the extractor. It receives the standard FeatureInput bundle, applies the configured algorithm, and returns feature values aligned to the extractor output units for storage in the pipeline feature store.

Parameters:
  • feature_input (object) – Structured extractor input bundling audio, hierarchical units, and execution context for this feature computation.

  • params (object) – Resolved feature configuration for this invocation. Keys are feature-specific and merged from defaults and pipeline settings.

Returns:

Structured output aligned to the frame unit level when applicable.

Return type:

FeatureOutput

Examples

>>> import numpy as np
>>> from voxatlas.audio.audio import Audio
>>> from voxatlas.features.acoustic.voice_quality.hnr import HNRExtractor
>>> from voxatlas.features.feature_input import FeatureInput
>>> from voxatlas.features.feature_output import VectorFeatureOutput
>>> from voxatlas.pipeline.feature_store import FeatureStore
>>> audio = Audio(waveform=np.zeros(1600, dtype=np.float32), sample_rate=16000)
>>> store = FeatureStore()
>>> f0_out = VectorFeatureOutput(
...     feature="acoustic.pitch.f0",
...     unit="frame",
...     time=np.array([0.0, 0.01], dtype=np.float32),
...     values=np.array([100.0, 100.0], dtype=np.float32),
... )
>>> store.add("acoustic.pitch.f0", f0_out)
>>> feature_input = FeatureInput(audio=audio, units=None, context={"feature_store": store})
>>> result = HNRExtractor().compute(feature_input, {})
>>> result.unit
'frame'