Anomaly-Driven Outlier Extractor — Acoustic Anomaly Extraction

This script extracts the most acoustically unusual moments from a sound. Praat builds a frame-by-frame feature table; a Python backend scores each frame for "outlier-ness" and returns a new Sound containing only the anomalous material.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 0.3 (2026) License: MIT License Repo: https://github.com/ShaiCohen-ops/Praat-plugin_AudioTools
Contents:

What this does

This script implements anomaly-driven outlier extraction. Praat measures a frame-level feature table on one common time grid, hands it to the Python backend together with the audio, and receives back a Sound containing only the acoustical outliers — the frames the detector could not explain from the rest of the file.

What is an acoustic outlier? An outlier is a frame that is "unusual" relative to the rest of the file. This could be a transient attack in an otherwise sustained sound, a pitch instability, a spectral oddity, or any frame that the detection algorithm finds hard to explain. The script extracts these frames and re-assembles them into a new Sound — a "highlight reel" of the most unusual moments.

Key Features:

Threshold semantics: Outlier_threshold is a fraction of frames, not a score cut. 0.05 keeps the top 5% most anomalous frames. Raw anomaly scores are not comparable across algorithms or files, so an absolute score cut would behave differently for every input. The threshold is applied as a quantile: score_cut = quantile(scores, 1 - threshold).

Quick start

  1. In Praat, select exactly one Sound object.
  2. Run script…Anomaly_Outlier_Extractor.praat.
  3. Choose a preset from the dropdown (6 options, plus Custom).
  4. If Custom, set Features (space-separated keywords: pitch intensity centroid flux formants deltas all), Window_step_s (e.g., "0.025 0.010"), Pitch_range_Hz (e.g., "75 600").
  5. Select Algorithm (IsolationForest, Mahalanobis, Autoencoder).
  6. Set Outlier_threshold (top fraction of frames to extract).
  7. Choose Concat_mode (chronological, sorted, granular, texture, memory).
  8. For texture/memory modes, set Texture_length_s (output duration).
  9. Click OK — Praat extracts features, Python runs detection, assembles output.
Quick tip: Start with Transient hunt for percussive outliers. Pitch instability for vocal pitch deviations. Broadband oddity for full-spectrum anomalies. Anomaly texture uses the outliers as a corpus to generate a textured canvas of a requested length. Anomaly memory spreads each outlier as a motif across the canvas. Enable More_options to adjust segmentation, detection, and assembly parameters.
Important: Python dependencies required: pip install numpy scipy pandas soundfile scikit-learn. Autoencoder uses PyTorch if installed, otherwise a numpy MLP fallback. The analysis is always mono (To Spectrum and other commands require mono), but the exported audio preserves the original channel count. The texture/memory modes decouple output length from anomaly duration — a 70 ms anomaly can populate a 30-second canvas.

6 Presets

PresetFeaturesWindow/Step (ms)AlgorithmThresholdModeCharacter
Transient huntintensity, centroid, flux, deltas20 / 5IsolationForest0.03chronologicalShort frames, delta-heavy — catches attacks
Pitch instabilitypitch, intensity, formants, deltas40 / 10Mahalanobis0.08chronologicalVoice-source features, Mahalanobis
Broadband oddityintensity, centroid, flux, formants, deltas30 / 10Autoencoder0.05sortedFull spectral feature set, autoencoder
Granular cloudpitch, intensity, centroid, flux, deltas25 / 10IsolationForest0.15granularPermissive threshold, short grains, OLA
Anomaly texturepitch, intensity, centroid, flux, deltas25 / 10IsolationForest0.12textureWeighted stochastic cloud, fixed canvas length
Anomaly memorypitch, intensity, centroid, flux, deltas25 / 10IsolationForest0.08memoryEach outlier returns as a motif across the canvas

3 Detection Algorithms

IsolationForest

Scikit-learn ensemble — isolates outliers by random partitioning. Frames that are easy to isolate (short path length) are anomalous. Score = negated average path length, mapped to [0,1].

Use: General-purpose, robust to many feature types. Fast on medium-sized datasets.

Mahalanobis

Shrinkage covariance — squared Mahalanobis distance under a regularised covariance matrix, mapped to [0,1] by log-compression. The chi² tail probability is reported as a diagnostic.

Use: When features are approximately Gaussian. Good for pitch/formant analysis.

Autoencoder

Neural reconstruction error — a small MLP autoencoder learns to reconstruct normal frames. Frames with high reconstruction error are outliers.

Use: Non-linear feature relationships. PyTorch if installed, otherwise numpy MLP fallback.

Score transformation

All algorithms produce raw scores that are min-max mapped to [0,1]:

A(t) = (raw - min(raw)) / (max(raw) - min(raw))

Higher values = more anomalous. The threshold is applied as a quantile: score_cut = quantile(A, 1 - threshold).

Log-compression: For Mahalanobis and Autoencoder, raw distances are log-compressed before scaling so that one extreme frame doesn't compress all others toward 0.

5 Concatenation Modes

chronological sequential

Outlier slices are placed in the order they appear in the original file. The output is a "highlight reel" of anomalies in time order.

sorted by score

Outlier slices are placed in order of anomaly score (quietest anomaly to loudest). A crescendo of weirdness.

granular cloud

Outlier slices are overlap-added with random jitter, creating a continuous, cloud-like texture.

texture corpus

Outliers become a corpus. Slices are drawn with replacement, weighted by anomaly score, until the canvas is full. Output length is a parameter.

memory motif

Each outlier gets a recurrence budget from its score, and its occurrences are spread evenly across the canvas. A sharp anomaly comes back as a motif.

Texture / memory modes: The first three modes use each slice exactly once, so output length is a consequence of how much anomalous material was found. Texture and memory treat the slices as a corpus and take the canvas length as a parameter — a 70 ms anomaly can populate 30 seconds. Anomaly_bias controls how strongly the strongest anomalies dominate (0 = every anomaly equally present, higher = the strongest recur most).

Applications

Outlier highlight reel (chronological)

Use case: Extract all the "interesting" moments from a long recording — anomalies in order.

Settings: Transient hunt preset, chronological mode. The output is a concatenation of the most unusual frames.

Anomaly crescendo (sorted)

Use case: Hear anomalies from least to most unusual — a compositional arc.

Settings: Broadband oddity preset, sorted mode. The output builds from subtle to extreme outliers.

Anomaly cloud / texture (texture, memory)

Use case: Generate a long texture from a few short anomalies — create a "memory" of the outliers.

Settings: Anomaly texture preset, texture_length_s = 30.0. The output is a 30-second weighted stochastic cloud of the anomalies. Anomaly memory spreads each outlier as a recurring motif.

Workflow: Speech recording → Pitch instability outliers

Source: Spoken word recording.
Settings: Pitch instability preset, chronological mode, threshold=0.08.
Result: The output contains only the frames with pitch instability — the "unusual" vocal moments, extracted in order.

Workflow: Field recording → Anomaly texture

Source: Long field recording (birds, water, wind).
Settings: Anomaly texture preset, texture_length_s = 60.0, bias=1.5.
Result: A 60-second texture made from the unusual moments in the recording — the anomalies become a continuous soundscape.

Workflow: Instrumental solo → Granular cloud

Source: Instrumental solo (guitar, voice, etc.).
Settings: Granular cloud preset, threshold=0.15, granular_overlap=0.70.
Result: The anomalous frames are overlap-added into a granular cloud — a continuous, shimmering texture.

Troubleshooting:
No outliers extracted: Lower the threshold (e.g., 0.05 → 0.15). If the sound is very uniform, there may be few anomalies. Try a different algorithm or feature set.
Output is very short: In chronological/sorted/granular modes, output length depends on anomaly duration. Use texture/memory modes to specify a fixed output length.
Texture output is repetitive: Reduce Anomaly_bias (lower = more uniform) or increase Anti_repeat (cooldown for recently used slices).
Memory output loops too regularly: Increase Granular_jitter (drift) to spread occurrences more randomly.
Autoencoder is slow: The numpy MLP fallback is used if PyTorch is not installed. Install PyTorch for faster training: pip install torch.
Features not recognised: Use keywords: pitch, intensity, centroid, flux, formants, deltas, all. The script ignores unknown words.

Visualisation

When Draw_visualization is enabled, the script generates:
  • Input waveform — with outlier regions marked (red bars at the bottom, vertical lines at boundaries).
  • Input spectrogram — full frequency content.
  • Anomaly score curve A(t) — the score over time, with the cut threshold shown (red line).
  • Segment map — colour-coded bars showing where each outlier came from in the original file (blue = weaker, red = stronger).
  • Output waveform — the assembled outlier sound.
  • Output spectrogram — spectral content of the outliers.
  • Summary panel — frames, features, algorithm, threshold, flagged frames, segments, duration change, RMS.
The segment map is the key diagnostic: it shows which parts of the input were extracted and how they are re-assembled.