TGraphX › Insights › Audio Event Detection in Video with PANNs: Window Tags and Event Times
← Back to Insights

Audio Event Detection in Video with PANNs: Window Tags and Event Times

Topic: Vision, multimodal and domain applications

Run the PANNs CNN14 audio tagger on a video's soundtrack and you get, for each stretch of audio you give it, 527 independent scores saying which sound classes appear somewhere in that stretch. You do not get the moment a sound started or stopped. This article shows how the model works, what its scores mean, how to run it on a soundtrack, and how far a window label is from an event time.

One thing first. AI-Powered Video Analyzer, a video analyzer that runs locally, has an audio event stage built on PANNs, but in version 1.1.0 with panns-inference 0.1.1 that stage returns no sounds at all, as checked on 27 November 2026 with the real checkpoint. Every score below comes from calling panns-inference directly. None of it is analyzer output.

Transcription, tagging and detection

Task Question it answers Output Example model family
Speech transcription What words were said? Text, possibly with segment times Whisper
Audio tagging Which sounds are present in this clip? Scores per class for the whole clip PANNs CNN14
Sound event detection Which sounds happen, from when to when? Scores per class over time Frame-wise models, such as PANNs decision-level variants

CNN14 used through AudioTagging does the middle task. It can say that a recording contains speech and music; it cannot say that the music began at 12.4 seconds.

What the analyzer's stage does today

The intended procedure is simple: load the extracted audio at 32 kHz mono, peak-normalise it, cut it into 5 second windows that do not overlap, keep only the single highest-scoring label of each window if it reaches 0.1, and record the window's start time.

The failure is in handling the library's return value. AudioTagging.inference() returns a pair of arrays, the class scores with shape (1, 527) and an embedding with shape (1, 2048). The analyzer converts the pair as a whole into one array, which raises an error. The run still exits successfully, and the report contains:

text
"audio_events": {"error": []}

The Markdown report prints this as an entry named error, the report's limitations list does not mention it, and the summary stage receives the word as if it were a sound. Without a checkpoint file the entry is model_not_found instead. Until this is fixed, pass --no-audio-events and tag the audio yourself as shown below. Even after a repair, the procedure above would give at most one label per 5 second window.

What CNN14 receives

The model takes a mono waveform at 32 kHz. The number of samples is sampling rate times duration, so a 5 second window is 32000 * 5 = 160,000 samples.

Level of the 9 second speech clip and its two analysis windows

RMS level00.20.4window 1window 2threshold 0.01012345678time (s)

level, values at or above the threshold: 22 of 36 (0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25)

Windows
windowcoversat or above threshold at
window 10 to 4.750, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75
window 25 to 8.755, 5.25
RMS level by time (s)
time (s)levelat or above threshold
00.056level
0.250.275level
0.50.241level
0.750.334level
10.262level
1.250.302level
1.50.237level
1.750.237level
20.217level
2.250.101level
2.50.203level
2.750.145level
30.231level
3.250.202level
3.50.138level
3.750.259level
40.303level
4.250.299level
4.50.148level
4.750.186level
50.201level
5.250.155level
5.50none
5.750none
60none
6.250none
6.50none
6.750none
70none
7.250none
7.50none
7.750none
80none
8.250none
8.50none
8.750none

Threshold 0.01. level is at or above it at 22 of 36 (0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25).

Root mean square level in quarter second steps. Speech stops near 5.4 s, so the second window is mostly silent. Measured values, as recorded by the author: RMS of the peak-normalised 32 kHz mono soundtrack of the test clip (synthetic speech), computed in NumPy, 0.25 s steps. The figure only displays and compares them. Which values cross the threshold is computed from them.

From waveform to log-Mel spectrogram

The front end cuts the signal into overlapping frames, takes a Fourier transform of each, pools the power into Mel-spaced bands and converts to decibels:

text
X(m, k) = sum over n of  x[n + m*H] * w[n] * exp(-2*pi*i*k*n / N)
L(m, b) = 10 * log10( max( sum over k of  M_b(k) * |X(m, k)|^2 , 1e-10 ) )

x is the waveform, m the frame, H = 320 samples the step (10 ms), N = 1024 the window length (32 ms), w a Hann window, k the frequency bin and M_b the b-th of 64 Mel filters spanning 50 to 14,000 Hz. With the centred framing used by the implementation, a 5 second window becomes 501 frames by 64 bands. These settings are those of panns-inference 0.1.1; the paper describes the same sizes and frequency range with a Hamming window.

Log-Mel spectrogram of the speech test clip, CNN14 settings

A coarse spectrogram with 32 rows of Mel band pairs over nine seconds. Most bands carry energy while the synthetic voice speaks, up to about five and a half seconds, with only a faint constant level in the highest rows. From 5.75 seconds on, every cell sits at the floor value.

log-Mel, dB (cells below the threshold are dimmed)

-100 (dark)15 (light)

Left to right: time (s) 0 to 8.75. Bottom to top: lowest Mel band in row 0 to 62.

selected cell
lowest Mel band in row 0, time (s) 0
log-Mel, dB there
-28
log-Mel, dB: cells counted
1152 of 1152
log-Mel, dB: lowest Mel band in row (rows) by time (s) (columns)
row00.250.50.7511.251.51.7522.252.52.7533.253.53.7544.254.54.7555.255.55.7566.256.56.7577.257.57.7588.258.58.75
62-85-85-85-85-85-85-86-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-94-100-100-100-100-100-100-100-100-100-100-100-100-100
60-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-94-100-100-100-100-100-100-100-100-100-100-100-100-100
58-85-85-84-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-85-94-100-100-100-100-100-100-100-100-100-100-100-100-100
56-84-60-60-79-83-84-69-82-77-72-82-79-83-81-81-83-79-84-81-77-77-85-94-100-100-100-100-100-100-100-100-100-100-100-100-100
54-82-62-63-78-82-83-70-82-76-73-81-77-82-81-81-81-79-82-81-78-77-84-93-100-100-100-100-100-100-100-100-100-100-100-100-100
52-65-29-30-51-59-61-40-61-51-46-57-53-59-57-56-63-53-60-56-49-49-68-88-100-100-100-100-100-100-100-100-100-100-100-100-100
50-56-16-15-34-44-44-26-48-39-33-47-40-43-41-39-46-36-45-43-35-33-53-84-100-100-100-100-100-100-100-100-100-100-100-100-100
48-57-19-19-33-40-38-26-47-39-35-47-41-39-38-36-42-33-33-39-32-28-45-84-100-100-100-100-100-100-100-100-100-100-100-100-100
46-55-24-22-34-38-25-21-46-28-32-34-34-40-34-35-42-30-29-34-26-27-48-84-100-100-100-100-100-100-100-100-100-100-100-100-100
44-56-29-28-34-34-28-20-44-32-37-34-36-39-35-37-39-32-33-39-33-32-49-84-100-100-100-100-100-100-100-100-100-100-100-100-100
42-54-29-27-31-32-21-14-43-29-35-32-32-35-31-31-37-26-23-35-30-26-41-84-100-100-100-100-100-100-100-100-100-100-100-100-100
40-57-36-34-35-36-17-15-46-28-38-27-31-38-33-33-39-23-25-36-30-27-45-83-100-100-100-100-100-100-100-100-100-100-100-100-100
38-55-29-27-28-33-24-17-40-32-38-30-30-33-29-29-34-20-23-34-30-23-37-84-100-100-100-100-100-100-100-100-100-100-100-100-100
36-54-28-26-24-27-19-11-38-31-39-30-30-31-27-26-32-19-21-31-27-18-32-84-100-100-100-100-100-100-100-100-100-100-100-100-100
34-55-33-33-26-27-15-14-41-31-41-26-30-33-27-28-35-21-27-33-27-21-35-85-100-100-100-100-100-100-100-100-100-100-100-100-100
32-57-37-36-31-31-6-21-45-28-45-22-30-35-31-33-38-23-29-35-32-25-40-85-100-100-100-100-100-100-100-100-100-100-100-100-100
30-55-31-30-26-28-2-22-42-20-46-21-28-31-30-30-35-22-30-35-30-27-48-85-100-100-100-100-100-100-100-100-100-100-100-100-100
28-58-33-31-29-31-2-28-42-17-47-20-29-31-31-31-38-23-33-32-27-29-54-87-100-100-100-100-100-100-100-100-100-100-100-100-100
26-61-38-34-33-34-7-35-44-20-49-18-32-35-34-32-43-23-32-31-24-29-56-88-100-100-100-100-100-100-100-100-100-100-100-100-100
24-63-42-37-37-38-11-39-48-21-50-16-37-39-38-35-46-24-31-31-23-29-57-89-100-100-100-100-100-100-100-100-100-100-100-100-100
22-62-42-39-37-39-14-39-50-24-50-13-39-40-40-36-46-23-30-33-22-28-61-87-100-100-100-100-100-100-100-100-100-100-100-100-100
20-64-42-38-34-35-12-36-48-26-51-10-41-37-40-35-43-21-28-34-25-29-58-87-100-100-100-100-100-100-100-100-100-100-100-100-100
18-62-38-35-28-33-11-34-45-22-49-6-39-33-34-32-40-20-27-34-23-27-49-87-100-100-100-100-100-100-100-100-100-100-100-100-100
16-63-37-35-31-33-8-32-43-25-48-13-36-33-34-30-39-20-23-33-24-24-46-86-100-100-100-100-100-100-100-100-100-100-100-100-100
14-64-38-36-28-31-2-32-48-24-51-12-38-32-34-30-38-16-24-30-24-28-47-87-100-100-100-100-100-100-100-100-100-100-100-100-100
12-61-31-29-25-27-1-29-45-19-49-5-36-25-29-25-37-15-21-29-24-22-44-87-100-100-100-100-100-100-100-100-100-100-100-100-100
10-59-28-26-19-1811-20-37-11-42-1-26-22-22-25-29-9-7-25-19-17-42-87-100-100-100-100-100-100-100-100-100-100-100-100-100
8-54-16-17-16-114-14-38-10-38-1-22-21-19-23-31-11-3-24-20-16-39-86-100-100-100-100-100-100-100-100-100-100-100-100-100
6-51-15-18-16-105-11-33-4-324-17-18-13-22-26-112-22-17-9-34-84-100-100-100-100-100-100-100-100-100-100-100-100-100
4-46-7-15-6-110-9-22-5-302-13-14-8-15-15-28-18-13-7-21-82-100-100-100-100-100-100-100-100-100-100-100-100-100
2-341-9039-6-13-3-234-10-9-4-9-719-11-7-2-12-75-100-100-100-100-100-100-100-100-100-100-100-100-100
0-282-74815-1-84-189-5-33-7-1515-9-14-10-70-100-100-100-100-100-100-100-100-100-100-100-100-100

Cell lowest Mel band in row 0, time (s) 0: log-Mel, dB -28 (at or above the threshold). Cells at or above -100: log-Mel, dB 1152 of 1152.

Raise the threshold to dim quiet cells. Time runs left to right, low Mel bands are at the bottom. Measured grid values, as recorded by the author: torchlibrosa with CNN14 front-end settings on the 9 s synthetic-speech WAV; cell = mean of 2 Mel bands x 25 frames, whole dB. The figure only displays and compares them. A cell counts when its value is at or above the threshold.

CNN14 in brief

CNN14 treats the spectrogram as an image. Six blocks of two 3 x 3 convolutions each raise the channel count from 64 to 2048, and the first five halve both time and frequency.

CNN14 from one 5 second window to 527 scores

1. Log-Mel front end2. Convolution blocks 1 to 33. Convolution blocks 4 to 64. Global pooling5. Classifier
Inputs and outputs of every stage
stageinputoutputwhat happens
1. Log-Mel front endwaveform, 160000 samples1 x 501 x 64STFT with a 1024 sample window and 320 sample step, 64 Mel bands, decibels.
2. Convolution blocks 1 to 31 x 501 x 64256 x 62 x 8Each block has two convolutions and average pooling by 2 in time and frequency.
3. Convolution blocks 4 to 6256 x 62 x 82048 x 15 x 2Blocks 4 and 5 halve both axes; block 6 does not pool.
4. Global pooling2048 x 15 x 22048 numbersMean over frequency, then maximum plus mean over time. The position within the window is gone.
5. Classifier2048 numbers527 scores in 0..1A 2048 unit layer, then one output per class through a sigmoid.

Stage 1 of 5, Log-Mel front end. Input: waveform, 160000 samples. Output: 1 x 501 x 64.

Shapes are channels x time x Mel bands for one window, as measured on the library model. A schematic of the stages as described by the author; nothing is executed.

The global pooling step is the reason a tag carries no time: after the maximum and mean over time, nothing records where in the window the evidence was.

The authors trained on AudioSet, about two million 10 second clips from YouTube whose labels state which classes are present in a clip, not when. They report a mean average precision (mAP) of 0.431 for CNN14 on AudioSet tagging; their larger Wavegram-Logmel-CNN reaches 0.439. Average precision is computed per class from the precision-recall curve and then averaged over classes. The CNN14 instantiated here has about 80.8 million parameters.

Reading multi-label scores

For class k the network produces a number z_k and squashes it on its own:

text
p_k = 1 / (1 + exp(-z_k))

Each class is a separate yes-or-no question. The 527 values do not sum to 1, several can be high together (speech over music), and all can be low. Training uses binary cross-entropy per class. A score is not a calibrated probability for your audio unless you have checked that.

The class list follows AudioSet. A few representative entries, with their exact names:

Group Class names
Voice Speech, Speech synthesizer, Narration, monologue, Laughter, Crying, sobbing, Cough
Animals Dog, Bark, Meow
Music and applause Music, Applause
Weather and water Rain, Thunder, Wind, Water
Vehicles and alarms Car, Vehicle horn, car horn, honking, Siren, Fire alarm, Smoke detector, smoke alarm
Impacts Glass, Shatter, Gunshot, gunfire, Explosion
Signals and background Telephone bell ringing, Dial tone, Busy signal, Sine wave, Silence, Inside, small room

Run PANNs directly on a soundtrack

Extract the soundtrack:

bash
ffmpeg -i video.mp4 -vn -ac 1 -ar 32000 -c:a pcm_s16le speech.wav

Install panns-inference, librosa and PyTorch:

bash
python -m pip install panns-inference librosa torch

Download Cnn14_mAP=0.431.pth (327,428,481 bytes) from the authors' Zenodo record, which is licensed CC BY 4.0. The record gives its MD5 as 541141fa2ee191a88f24a3219fff024e; check it.

Two behaviours of the library affect where your machine connects. Importing panns_inference downloads the class label CSV with wget, over plain HTTP, into a panns_data folder in your home directory if the file is missing. And AudioTagging downloads the checkpoint again if the file you point to is smaller than 300 million bytes. Both need wget.

python
import librosa
import numpy as np
from panns_inference import AudioTagging, labels

SR = 32000
WINDOW = 5 * SR
wave, _ = librosa.load("speech.wav", sr=SR, mono=True)
peak = np.abs(wave).max()
if peak > 0:
    wave = wave / peak                                  # the analyzer's normalisation

model = AudioTagging(checkpoint_path="Cnn14_mAP=0.431.pth")   # GPU if present, else CPU
for start in range(0, len(wave), WINDOW):
    chunk = wave[start:start + WINDOW]
    if len(chunk) < SR:                                 # pad a very short tail
        chunk = np.pad(chunk, (0, SR - len(chunk)))
    clipwise, embedding = model.inference(chunk[None, :])     # a tuple of two arrays
    scores = clipwise[0]                                # 527 independent scores
    top = np.argsort(scores)[::-1][:3]
    print(f"{start / SR:4.1f} s", [(labels[k], round(float(scores[k]), 3)) for k in top])

Pad short tails: in this version, an input of 0.3 seconds or less raised an error because the pooling layers run out of time steps.

The test clip is 9 seconds of synthetic speech (FFmpeg's flite voice) followed by silence. The script, run on the soundtrack as the analyzer had extracted it (panns-inference 0.1.1, librosa 0.11.0, PyTorch 2.15.0), printed the same result lines on GPU and CPU, after the library's own start-up messages:

text
 0.0 s [('Speech synthesizer', 0.745), ('Speech', 0.685), ('Narration, monologue', 0.108)]
 5.0 s [('Speech', 0.627), ('Silence', 0.241), ('Music', 0.113)]

Top three PANNs scores in each window of the speech clip

Six bars. The first window scores speech synthesizer highest, then speech, then narration far lower. The second window scores speech highest, then silence and music, with music at about 0.11.

0-5 s Speech synthesizer: 0.745 ×1.00 total over the score 0.1

0-5 s Speech: 0.685 ×0.92 total over the score 0.1

0-5 s Narration, monologue: 0.108 ×0.14 total over the score 0.1

5-9 s Speech: 0.627 ×0.84 total over the score 0.1

5-9 s Silence: 0.241 ×0.32 total over the score 0.1

5-9 s Music: 0.113 ×0.15 total over the score 0.1

Vertical mark: score 0.1, 0.1.

Each × compares with 0-5 s Speech synthesizer. Shown: total.

Values
barvaluescore 0.1
0-5 s Speech synthesizer0.745over
0-5 s Speech0.685over
0-5 s Narration, monologue0.108over
5-9 s Speech0.627over
5-9 s Silence0.241over
5-9 s Music0.113over

Showing each value: 0-5 s Speech synthesizer 0.745; 0-5 s Speech 0.685; 0-5 s Narration, monologue 0.108; 5-9 s Speech 0.627; 5-9 s Silence 0.241; 5-9 s Music 0.113. Ratios are to 0-5 s Speech synthesizer.

Direct panns-inference output, not analyzer output. Scores are independent per class. Measured values, as recorded by the author: panns-inference 0.1.1, CNN14, 5 s windows, 9 s synthetic-speech clip; direct library call, not analyzer output. The figure only displays and compares them. Bars start at zero; totals and ratios are computed from the values.

Read these carefully. The voice really is synthetic, and speech really is present. There is no music in the file, so Music at 0.113 is a false positive. And the second window is tagged Speech at 0.627 although speech occupies only its first 0.4 seconds or so.

For comparison, a pure 440 Hz tone was tagged Sine wave (0.60 to 0.71 across three windows) with Dial tone next (0.06 to 0.12).

Choosing a threshold

A threshold turns scores into labels. The code below applies several to the recorded scores above (the two lists hold the top five of each window).

python
# recorded top scores (panns-inference called directly, NOT analyzer output), speech clip
windows = {
    "0-5 s": {"Speech synthesizer": 0.745, "Speech": 0.685, "Narration, monologue": 0.108,
              "Music": 0.051, "Male speech, man speaking": 0.028},
    "5-9 s": {"Speech": 0.627, "Silence": 0.241, "Music": 0.113,
              "Vehicle": 0.068, "Inside, small room": 0.037},
}
for threshold in (0.05, 0.1, 0.2, 0.5):
    for name, scores in windows.items():
        kept = [label for label, score in scores.items() if score >= threshold]
        print(f"threshold {threshold:<4} {name}: {kept}")
text
threshold 0.05 0-5 s: ['Speech synthesizer', 'Speech', 'Narration, monologue', 'Music']
threshold 0.05 5-9 s: ['Speech', 'Silence', 'Music', 'Vehicle']
threshold 0.1  0-5 s: ['Speech synthesizer', 'Speech', 'Narration, monologue']
threshold 0.1  5-9 s: ['Speech', 'Silence', 'Music']
threshold 0.2  0-5 s: ['Speech synthesizer', 'Speech']
threshold 0.2  5-9 s: ['Speech', 'Silence']
threshold 0.5  0-5 s: ['Speech synthesizer', 'Speech']
threshold 0.5  5-9 s: ['Speech']

The analyzer's intended rule, top label only, would have kept Speech synthesizer in the first window and dropped Speech, although both are correct.

There is no universal threshold. To choose one, label some audio of the kind you will process and, for each class you care about, count at several thresholds:

  • precision, the share of reported windows that really contain the sound, TP / (TP + FP);
  • recall, the share of windows containing the sound that were reported, TP / (TP + FN).

The numbers below are invented to show the mechanics.

python
# made-up validation data for one class: (model score, 1 if the sound really is in the window)
labelled = [(0.92, 1), (0.81, 1), (0.64, 1), (0.55, 0), (0.41, 1), (0.33, 0),
            (0.27, 1), (0.18, 0), (0.12, 0), (0.09, 1), (0.05, 0), (0.02, 0)]

for threshold in (0.5, 0.3, 0.1):
    tp = sum(1 for score, truth in labelled if score >= threshold and truth)
    fp = sum(1 for score, truth in labelled if score >= threshold and not truth)
    fn = sum(1 for score, truth in labelled if score < threshold and truth)
    print(f"threshold {threshold}: precision {tp / (tp + fp):.2f}  recall {tp / (tp + fn):.2f}")
text
threshold 0.5: precision 0.75  recall 0.50
threshold 0.3: precision 0.67  recall 0.67
threshold 0.1: precision 0.56  recall 0.83

Lowering the threshold finds more of the sound and raises more false alarms. Which trade is right depends on what happens next: a search tool that a person checks can accept false alarms, while an automatic alert usually cannot. Choose on one labelled set and report performance on another. Classes differ, and a threshold tuned on 5 second windows need not hold for 1 second windows.

A window tag is not an event time

Timing comes only from which windows you feed in. With a duration T, window length W and step D between window starts, there are n = floor((T - W) / D) + 1 full windows, and shorter steps cost proportionally more model calls. Shorter windows localise better but give the model less context than the 10 second clips it was trained on.

To see how window length affects timing, a test signal was built with a known answer: 10 seconds of very faint noise with a 440 Hz tone added from 6.2 to 7.2 seconds. It was tagged with the same model, first in two 5 second windows and then in 1 second windows starting every 0.5 seconds (19 of them).

With 5 second windows, the first scored Silence highest (0.142) and the second Busy signal (0.696). That locates the beep only "between 5 and 10 seconds", and under a name you might not expect for a tone: Sine wave scored 0.026.

Scores of 1 second windows around a 1 second tone

score00.51threshold 0.50123456789window start (s)

Busy signal (circles)White noise (squares, dashed)

Busy signal, values at or above the threshold: 4 of 19 (5.5, 6, 6.5, 7)

White noise, values at or above the threshold: 0 of 19

Windows
windowcoversat or above threshold at
overlap tone5.5 to 75.5, 6, 6.5, 7
score by window start (s)
window start (s)Busy signalWhite noiseat or above threshold
000.111none
0.500.094none
100.073none
1.500.091none
200.114none
2.500.095none
300.099none
3.500.089none
400.073none
4.500.06none
500.08none
5.50.8650.024Busy signal
60.5530.005Busy signal
6.50.7480.001Busy signal
70.6110.012Busy signal
7.500.115none
800.095none
8.500.061none
900.091none

Threshold 0.5. Busy signal is at or above it at 4 of 19 (5.5, 6, 6.5, 7). White noise is at or above it at 0 of 19.

The tone runs from 6.2 to 7.2 s. Move the threshold and see which window starts still report Busy signal. Measured values, as recorded by the author: panns-inference 0.1.1, CNN14, GPU; 1 s windows every 0.5 s on 10 s of faint noise with a 440 Hz tone at 6.2-7.2 s; one run. The figure only displays and compares them. Which values cross the threshold is computed from them.

All four windows that overlap the tone fire, including the one holding only 0.2 seconds of it, and the window holding the most tone has the lowest of the four scores. A score is not the fraction of the window a sound fills. Turning window hits into intervals therefore depends strongly on the threshold:

python
# recorded "Busy signal" scores of 1 s windows starting every 0.5 s; the tone runs from 6.2 to 7.2 s
busy = {5.0: 0.000, 5.5: 0.865, 6.0: 0.553, 6.5: 0.748, 7.0: 0.611, 7.5: 0.000}

def intervals(scores, threshold, length=1.0):
    """Merge the windows at or above the threshold that touch or overlap."""
    merged = []
    for start in sorted(s for s, p in scores.items() if p >= threshold):
        if merged and start <= merged[-1][1]:
            merged[-1][1] = start + length
        else:
            merged.append([start, start + length])
    return merged

for threshold in (0.5, 0.7, 0.8, 0.9):
    print(f"threshold {threshold}: {intervals(busy, threshold)}")
text
threshold 0.5: [[5.5, 8.0]]
threshold 0.7: [[5.5, 7.5]]
threshold 0.8: [[5.5, 6.5]]
threshold 0.9: []

One tone and three different answers about when it happened

True tone5 s window, Busy signalscore 0.701 s windows, 0.5 or more1 s windows, 0.8 or more0246810seconds
What each lane holds at the selected time
laneholds
True tonenothing
5 s window, Busy signalnothing
1 s windows, 0.5 or morenothing
1 s windows, 0.8 or morenothing
All events
eventlanetime
440 HzTrue tone6.2 to 7.2 s
score 0.705 s window, Busy signal5 to 10 s
5.5 to 8.0 s1 s windows, 0.5 or more5.5 to 8 s
5.5 to 6.5 s1 s windows, 0.8 or more5.5 to 6.5 s

At 0 s. True tone: nothing. 5 s window, Busy signal: nothing. 1 s windows, 0.5 or more: nothing. 1 s windows, 0.8 or more: nothing.

Select a time to compare the true tone with what each windowing and threshold reports. Measured times and events, as recorded by the author: panns-inference 0.1.1, CNN14, GPU, synthetic 10 s signal; intervals computed from the window scores. The figure only displays and compares them.

Report such results as "a window overlapping this range scored high", keep the window length and threshold with them, and do not present the interval's ends as onset and offset. To compare with video frames, also check whether the audio stream starts later than the video; ffprobe shows each stream's start_time, and a WAV extracted on its own does not keep that offset.

A trap with synthetic test signals

The first version of this test used exact digital silence and a pure tone. On those inputs GPU and CPU disagreed badly: for the window starting at 6.5 s the GPU's top class was Busy signal (0.703) and the CPU's was Sine wave (0.577). The same silent signal also gave Music as the top class (0.142) for 1 second windows of pure zeros. Adding the faint noise floor brought GPU and CPU to within 0.003 of each other. A likely reason is that logarithms of near-zero energy depend on floating-point rounding, though that was not isolated. Test with realistic audio, and do not assume digital silence is scored as Silence.

Models that output times

panns-inference also provides SoundEventDetection, which uses a decision-level CNN14 checkpoint and returns scores for each frame. It was not run for this article. Its training labels are also clip-level, so check its times against hand-marked events before relying on them.

False positives and false negatives

Situation Risk What to do
A brief sound in a long window Missed or diluted Shorter or overlapping windows, then validate
Digital silence or synthetic tones Odd labels, hardware-dependent scores Gate by signal level; test with real recordings
Several sounds at once Quieter class falls below threshold Keep all classes above a per-class threshold
Acoustically similar sounds Confusion, such as a beep read as a phone signal Group related classes; listen to hits
A class your task needs but the list lacks Mapped to a neighbour Train or adapt a model for that class
Recording conditions unlike YouTube clips Scores shift Re-measure thresholds on your own audio

Store each result with its window start and end, label, score, model file, window length and threshold. A label without those cannot be reviewed later.

For the words in the soundtrack, see offline video transcription with Whisper.

How captions, detections and speech are combined into a summary, and checked, is covered in local video summarization with Ollama.

References

  1. Q. Kong, Y. Cao, T. Iqbal, Y. Wang, W. Wang, M. D. Plumbley. PANNs: Large-Scale Pretrained Audio Neural Networks for Audio Pattern Recognition. arXiv:1912.10211
  2. Q. Kong. panns_inference repository. github.com/qiuqiangkong/panns_inference
  3. PANNs pretrained models, Zenodo record. zenodo.org/records/3987831
  4. J. F. Gemmeke, D. P. W. Ellis, D. Freedman, A. Jansen, W. Lawrence, R. C. Moore, M. Plakal, M. Ritter. Audio Set: An ontology and human-labeled dataset for audio events. ICASSP 2017. Google Research
  5. AudioSet ontology and dataset site. research.google.com/audioset
  6. A. Sajjadi. AI-Powered Video Analyzer, source repository, version 1.1.0. GitHub