callcut.extractors.BaseExtractor🔗

class callcut.extractors.BaseExtractor(sample_rate)[source]🔗

Abstract base class for feature extractors.

All feature extractors must implement:

  • extract(): Extract features from a waveform

  • n_features: Number of output feature channels

  • hop_ms: Hop length in milliseconds (determines frame rate)

The base class provides utility methods for time-frame conversion.

Parameters:
sample_rateint

Expected sample rate in Hz. Waveforms should be resampled to this rate before extraction.

Attributes

frame_rate

Frame rate in Hz (frames per second).

hop_ms

Hop length in milliseconds.

hop_s

Hop length in seconds.

n_features

Number of output feature channels.

sample_rate

Expected sample rate in Hz.

Methods

__call__(waveform)

Extract features (alias for extract()).

extract(waveform)

Extract features from a waveform.

frames_to_seconds(frames)

Convert number of frames to duration in seconds.

seconds_to_frames(seconds)

Convert duration in seconds to number of frames.

Examples

Create a custom extractor by subclassing BaseExtractor:

>>> class MyExtractor(BaseExtractor):
...     def __init__(self, sample_rate: int, hop_ms: float = 10.0):
...         super().__init__(sample_rate)
...         self._hop_ms = hop_ms
...
...     @property
...     def n_features(self) -> int:
...         return 64
...
...     @property
...     def hop_ms(self) -> float:
...         return self._hop_ms
...
...     def extract(self, waveform: Tensor) -> tuple[Tensor, Tensor]:
...         # Implementation here
...         ...
__call__(waveform)[source]🔗

Extract features (alias for extract()).

Parameters:
waveformTensor

Audio waveform of shape (1, samples) or (samples,).

Returns:
featuresTensor

Extracted features of shape (n_features, n_frames).

timesTensor

Time axis of shape (n_frames,) in seconds.

abstractmethod extract(waveform)[source]🔗

Extract features from a waveform.

Parameters:
waveformTensor

Audio waveform of shape (1, samples) or (samples,). Should be mono and sampled at sample_rate.

Returns:
featuresTensor

Extracted features of shape (n_features, n_frames).

timesTensor

Time axis of shape (n_frames,) in seconds.

frames_to_seconds(frames)[source]🔗

Convert number of frames to duration in seconds.

Parameters:
framesint

Number of frames.

Returns:
secondsfloat

Duration in seconds.

Examples

>>> extractor = SNRExtractor(sample_rate=32000, hop_ms=8.0)
>>> extractor.frames_to_seconds(250)
2.0
seconds_to_frames(seconds)[source]🔗

Convert duration in seconds to number of frames.

Parameters:
secondsfloat

Duration in seconds.

Returns:
framesint

Number of frames (rounded to nearest integer).

Examples

>>> extractor = SNRExtractor(sample_rate=32000, hop_ms=8.0)
>>> extractor.seconds_to_frames(2.0)
250
property frame_rate🔗

Frame rate in Hz (frames per second).

Type:

float

abstract property hop_ms🔗

Hop length in milliseconds.

Determines the time resolution of extracted features.

Type:

float

property hop_s🔗

Hop length in seconds.

Type:

float

abstract property n_features🔗

Number of output feature channels.

For SNR features, this is the number of frequency bands.

Type:

int

property sample_rate🔗

Expected sample rate in Hz.

Type:

int