[Python] Flattening signal frames withou overlap after applying VAD Filter using Librosa

Discussão em 'Python' iniciado por Stack, Maio 15, 2025.

  1. Stack

    Stack Membro Participativo

    Hello I've built a very basic VAD filter using Librosa.

    # Size of our frame is 552 samples
    frame_len = 552
    # Size of the overlap is 221 samples
    frame_hop = 221

    # Slices data array into overlapping frames without previously defined variables
    frames = librosa.util.frame(y,
    frame_length=frame_len,
    hop_length=frame_hop)

    # Computing average loudness in frame.
    # summing the square of our frame and dividing by frame length
    # Squaring the Signal positive and negative don't cancel each other out.
    energy = np.sum(frames**2, axis=0) / frame_len

    # Convert to decibels and add a tiny (1e-10) constant to avoid log(0) errors
    # Since the above calculates power we multiply by 10 (not 20 as would be the case for Amplitude) [1]
    # To obtain the average decibel power of our frame
    energy_db = 10 * np.log10(energy + 1e-10)

    # Comparing the loudest frame energy_db.max() to other frames
    # anything not louder than energy_db.max() - 40db, is cut off
    # We return a Boolean Array
    vad_mask = energy_db > (energy_db.max() - 40)



    The issue I'm running into is that when I'm just naively filtering and flattening the signal, I keep the overlap. (Effectively this sounds like I'm lowering the frequency)

    # We select only the vad_mask frames
    speech_frames = frames[:, vad_mask]
    # Transpose and flatten the frames to yield one continious signal
    y_vad = speech_frames.T.reshape(-1)


    I could simply remove the preceding and trailing 221 samples from each frame, but I'm wondering if there is a librosa function which will help me do that.

    Continue reading...

Compartilhe esta Página