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 waveformn_features: Number of output feature channelshop_ms: Hop length in milliseconds (determines frame rate)
The base class provides utility methods for time-frame conversion.
- Parameters:
- sample_rate
int Expected sample rate in Hz. Waveforms should be resampled to this rate before extraction.
- sample_rate
Attributes
Frame rate in Hz (frames per second).
Hop length in milliseconds.
Hop length in seconds.
Number of output feature channels.
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 ... ...
- abstractmethod extract(waveform)[source]🔗
Extract features from a waveform.
- Parameters:
- waveform
Tensor Audio waveform of shape
(1, samples)or(samples,). Should be mono and sampled atsample_rate.
- waveform
- Returns:
- frames_to_seconds(frames)[source]🔗
Convert number of frames to 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:
- seconds
float Duration in seconds.
- seconds
- Returns:
- frames
int Number of frames (rounded to nearest integer).
- frames
Examples
>>> extractor = SNRExtractor(sample_rate=32000, hop_ms=8.0) >>> extractor.seconds_to_frames(2.0) 250
- abstract property hop_ms🔗
Hop length in milliseconds.
Determines the time resolution of extracted features.
- Type:
- abstract property n_features🔗
Number of output feature channels.
For SNR features, this is the number of frequency bands.
- Type: