apply_hangover (vad/postprocess.py)

ai-ml-portfolio · labs/vad/postprocess.py · python · MIT
voice

Python utilities to smooth and convert VAD flags into speech segments.

# Source: https://github.com/mangeshraut712/ai-ml-portfolio | License: MIT | Copyright 2026 Mangesh Raut
# Provided via justclaw.it.com; keep this notice with the code.
"""Frame-level post-processing for VAD timelines (hangover / smoothing)."""

from __future__ import annotations

import numpy as np


def apply_hangover(
    flags: np.ndarray,
    *,
    pad_speech_frames: int = 1,
    fill_gap_frames: int = 2,
    min_speech_frames: int = 2,
) -> np.ndarray:
    """Stabilize raw binary VAD flags for production-like segmentation.

    Steps:
    1. Drop speech islands shorter than ``min_speech_frames`` (noise blips).
    2. Fill non-speech gaps shorter than ``fill_gap_frames`` inside speech.
    3. Pad each speech region by ``pad_speech_frames`` on both sides (hangover)
       to recover c

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key