personalitylinmult.inference.audio_features¶
Extract the audio features the A / AT / AVT models consume, from a media file.
The trained models take pre-extracted per-modality features, not raw audio. To
predict on a new clip a caller must first run the same extractors used to build
fi.h5. This module wraps the two acoustic ones — WavLM and emotion2vec — so a
demo (notebook or Space) can go from an uploaded file to a features dict the
predictor accepts, without importing the batch preprocessing scripts.
exordium (the extractor stack) is imported lazily inside the functions so this module stays importable where those heavy deps are absent (e.g. a unit-test environment that only exercises the predictor).
Attributes¶
Module-level logger. |
|
WavLM transformer layer used everywhere in this project (matches fi.h5). |
|
Extensions treated as audio; anything else is decoded through ffmpeg first. |
|
Sample rate the training audio was extracted at. |
Exceptions¶
Raised when audio cannot be decoded from an input file. |
Functions¶
|
Return a WAV path for the input, extracting audio from video if needed. |
|
Extract the WavLM layer-9 feature sequence for one clip. |
|
Extract the emotion2vec+ feature sequence for one clip. |
|
Extract both acoustic features for the audio (A) model. |
Module Contents¶
- personalitylinmult.inference.audio_features.logger¶
Module-level logger.
- personalitylinmult.inference.audio_features.WAVLM_LAYER = 9¶
WavLM transformer layer used everywhere in this project (matches fi.h5).
- personalitylinmult.inference.audio_features.AUDIO_SUFFIXES¶
Extensions treated as audio; anything else is decoded through ffmpeg first.
- personalitylinmult.inference.audio_features.AUDIO_SAMPLE_RATE = 44100¶
Sample rate the training audio was extracted at.
- exception personalitylinmult.inference.audio_features.AudioExtractionError[source]¶
Bases:
ExceptionRaised when audio cannot be decoded from an input file.
Initialize self. See help(type(self)) for accurate signature.
- personalitylinmult.inference.audio_features.ensure_audio(input_path: str | pathlib.Path) tuple[pathlib.Path, bool][source]¶
Return a WAV path for the input, extracting audio from video if needed.
Audio files are passed through unchanged; any other container (video) is decoded to a temporary mono 44.1 kHz WAV with the same ffmpeg settings the training pipeline used.
- Parameters:
input_path (str | Path) – An audio or video file.
- Returns:
(wav_path, is_temporary)– the caller deletes the WAV whenis_temporaryis True.- Return type:
tuple[Path, bool]
- Raises:
AudioExtractionError – If ffmpeg fails or the input has no audio stream.
- personalitylinmult.inference.audio_features.extract_wavlm(audio_path: str | pathlib.Path, device_id: int = -1) numpy.ndarray[source]¶
Extract the WavLM layer-9 feature sequence for one clip.
- Parameters:
audio_path (str | Path) – Path to an audio/video file exordium can read.
device_id (int) – Device index;
-1for CPU (portable default).
- Returns:
(T, 768)float32 features.- Return type:
np.ndarray
- personalitylinmult.inference.audio_features.extract_emotion2vec(audio_path: str | pathlib.Path, device_id: int = -1) numpy.ndarray[source]¶
Extract the emotion2vec+ feature sequence for one clip.
- Parameters:
audio_path (str | Path) – Path to an audio/video file exordium can read.
device_id (int) – Device index;
-1for CPU.
- Returns:
(T, 768)float32 features.- Return type:
np.ndarray
- personalitylinmult.inference.audio_features.extract_audio_features(audio_path: str | pathlib.Path, device_id: int = -1) dict[str, numpy.ndarray][source]¶
Extract both acoustic features for the audio (A) model.
Accepts audio or video: a video’s audio track is extracted to a temporary mono 44.1 kHz WAV (matching the training pipeline) before feature extraction, then cleaned up.
- Parameters:
audio_path (str | Path) – Path to an audio or video file.
device_id (int) – Device index;
-1for CPU.
- Returns:
{"wavlm": (T, 768), "emotion2vec": (T, 768)}, the exact input theAmodel’s predictor expects.- Return type:
dict[str, np.ndarray]
- Raises:
AudioExtractionError – If the input is a video with no decodable audio.