Bayesian Drone Weaver — User Guide

Algorithmic drone composition: Bayesian classification of audio clips into gesture types, intelligent timeline construction, and overlapping assembly for continuous ambient textures.

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

What this does

This script implements Bayesian Drone Weaver — an algorithmic composition system that analyzes audio clips, classifies them into musical gesture types using Bayesian inference, constructs intelligent timelines, and weaves them into continuous ambient drone textures. Process: (1) Audio analysis: Extract intensity, spectral, harmonic, and temporal features from each clip. (2) Bayesian classification: Compute posterior probabilities for five gesture hypotheses (Sustain, Swell, Tension, Air, Pulse). (3) Timeline construction: Build narrative arc (intro→development→climax→resolution) by matching clip characteristics to phase-based targets. (4) Overlap assembly: Mix clips with calculated overlaps and crossfades to create seamless drone. Result: Algorithmically composed ambient piece from raw audio materials.

Key Features:

What is Bayesian drone composition? Traditional drone: Static, sustained tones. Algorithmic drone: Dynamic texture created from overlapping sound clips. Bayesian approach: Mathematical classification based on audio features. Advantages: (1) Intelligent selection: Clips chosen based on musical role. (2) Narrative structure: Builds coherent musical arc. (3) Seamless transitions: Calculated overlaps and fades. (4) Adaptive parameters: Composition adjusts to input material. (5) Reproducible: Same inputs → similar (not identical) output. Use cases: Ambient music generation, film scoring (background textures), sound installations, generative art, experimental composition, meditation audio.

Technical Implementation: (1) File processing: Load WAV/AIFF/FLAC files, convert to mono, resample to 44.1kHz, validate duration (0.1–30s). (2) Feature extraction: Intensity (mean, std, motion), spectral brightness, harmonicity, voicing fraction. (3) Bayesian classification: Compute log-likelihoods for each gesture hypothesis, apply uniform prior (0.2), normalize to posterior probabilities. (4) Macro-feature derivation: Compute flow, growth, edge, space, soften from posteriors. (5) Timeline construction: Four-phase narrative arc with phase-specific targets, select clips minimizing Euclidean distance to targets. (6) Overlap calculation: Flow/space dependent overlaps with preset scaling. (7) Assembly: Apply fades (in/out), optional intensity scaling, mix into final drone. (8) Visualization: Draw timeline with color-coded gesture types.

Quick start

  1. Prepare a folder with audio clips (WAV/AIFF/FLAC, 0.1–30s duration).
  2. In Praat, run Bayesian_Drone_Weaver.praat.
  3. Choose Preset: Ambient, Cinematic, Meditative, Textural, or Custom.
  4. Set Max_clips (maximum clips to use, default 30).
  5. Adjust Overlap_factor (1.0 = default, >1 = more overlap, <1 = less).
  6. Enable Draw_visualization for timeline visualization.
  7. Click OK, select your folder of audio clips.
  8. Script analyzes clips, classifies gestures, builds timeline, outputs drone.
Quick tip: Start with Ambient preset for slow-evolving textures. Use 3–10 second clips for best results (avoids monotony, allows overlaps). Folder should contain at least 3 clips (more = better selection). Enable visualization to see classification results and timeline structure. For denser textures: increase Overlap_factor (1.2–1.5). For sparser textures: decrease Overlap_factor (0.6–0.8). Max_clips controls how many clips are used from folder (not all need be used). Output named BayesianDrone_[Preset] appears in Objects window.
Important: CLIP DURATION MATTERS — clips <0.1s skipped, >30s truncated/skipped. File formats: WAV, AIFF, FLAC supported (others may fail). Stereo files converted to mono (averaged). Sampling rate converted to 44.1kHz. Bayesian classification depends on extracted features — noisy/quiet/tonal/atonal clips classify differently. Timeline construction is non-deterministic but reproducible with same inputs. Overlap calculations can produce negative overlaps (gaps) if flow/space very low. Fade durations adapt to clip length (max 50% of clip). Final output normalized to peak 0.95. Original clips remain unchanged.

Bayesian Classification Theory

The Five Gesture Hypotheses

🎵 Gesture Taxonomy

Five mutually exclusive hypotheses:

  1. Sustain: Stable, steady-state, minimal intensity variation
  2. Swell: Crescendo/decrescendo, intensity motion > 0
  3. Tension: Bright, inharmonic, high intensity variance
  4. Air: Quiet, noisy/breathy, low harmonicity
  5. Pulse: Rhythmic, percussive, intensity variations

Each clip assigned posterior probability for each hypothesis

Feature Extraction

Features computed per clip:

INTENSITY FEATURES (via Praat Intensity object): mean_intensity = average energy (dB) std_intensity = standard deviation of energy intensity_motion = (late_mean - early_mean) / duration SPECTRAL FEATURES: brightness = spectral centre of gravity (Hz) HARMONIC FEATURES: harmonicity_mean = average harmonics-to-noise ratio voiced_fraction = proportion of voiced frames DERIVED: bright_khz = brightness / 1000 (normalized)

Bayesian Inference Pipeline

📊 From Features to Probabilities

Step 1: Log-Likelihood Calculation

For each hypothesis h, compute log-likelihood L(h|features):

L(sustain) = -(std_int-2)²/10 - motion²/0.1 - (bright_khz-1.5)²/3 + harm/5 + voiced L(swell) = motion*10 (if motion>0 else motion*3) - (bright_khz-2)²/4 + std_int/5 + harm/10 L(tension) = (bright_khz-1)*2 - harm + intensity/10 + std_int/3 L(air) = -(intensity-50)²/200 + (bright_khz-3)/2 - harm*2 - voiced L(pulse) = std_int - harm/2 + (motion<-2 ? 2 : 0)

Step 2: Prior Application

Uniform prior: P(h) = 0.2 for all h

Log-posterior: log P(h|data) = L(h|data) + log P(h)

Step 3: Normalization

Exponentiate, normalize to sum=1 → posterior probabilities

Macro-Feature Derivation

From posteriors to compositional parameters:

flow = 0.5 + 0.3×P(sustain) + 0.4×P(air) + 0.2×P(swell) growth = 0.3 + 0.6×P(swell) + 0.1×P(tension) edge = 0.2 + 0.6×P(tension) + 0.2×P(swell) space = 0.4 + 0.4×P(air) + 0.3×P(sustain) + 0.1×P(swell) soften = P(pulse) Constraints: flow ∈ [0,1], growth ∈ [0,1], edge ∈ [0,0.85], space ∈ [0,1], soften ∈ [0,1]

Timeline Construction Algorithm

📈 Narrative Arc Generation

Four-phase structure:

PhaseFlowGrowthEdgeSpace
Intro (0–25%)0.850.20.150.8
Development (25–60%)0.750.70.40.5
Climax (60–80%)0.50.40.750.3
Resolution (80–100%)0.950.10.20.9

Clip selection: For each timeline position, find unused clip minimizing:

distance = √[(flow-target_flow)² + (growth-target_growth)² + (edge-target_edge)² + (space-target_space)²]

Continuity bonus: Prefer clips similar to previous in flow/edge

Overlap Calculation

Dynamic overlap based on flow and space:

BASIC FORMULA (resolution phase >80%): overlap = 0.6 + flow_avg×1.2 + space_avg×0.5 OTHER PHASES: overlap = 0.4 + flow_avg×0.8 + space_avg×0.3 APPLY PRESET FACTOR: final_overlap = overlap × overlap_factor WHERE: flow_avg = (flow_prev + flow_curr) / 2 space_avg = (space_prev + space_curr) / 2 overlap_factor = user parameter (default 1.0) CLAMP: final_overlap ≤ 2.0 seconds

Fade Application

Adaptive fade durations:

fade_in = 0.05 + flow×0.4 + soften×0.5 fade_out = 0.1 + flow×0.5 + space×0.4 + soften×0.6 CONSTRAINTS: fade_in ≤ duration/2 fade_out ≤ duration/2 INTENSITY SCALING (if soften > 0.5): scale = 1 - (soften - 0.5) Scale intensity to scale×70 dB

Composition Presets

Preset 1: Ambient

🌌 Slow Evolution

Parameters: max_clips=20, overlap_factor=1.2

Character: Gradual changes, long overlaps, smooth transitions

Timeline: Extended intro/resolution, gentle climax

Best for: Background ambiance, meditation, sleep music

Preset 2: Cinematic

🎬 Dramatic Arc

Parameters: max_clips=30, overlap_factor=0.8

Character: Clear narrative structure, stronger contrasts

Timeline: Pronounced climax, dynamic development

Best for: Film scoring, dramatic contexts, emotional arcs

Preset 3: Meditative

🧘 Sustained Focus

Parameters: max_clips=15, overlap_factor=1.5

Character: Minimal change, maximal overlap, stable

Timeline: Flat structure, subtle variations

Best for: Deep meditation, trance states, sustained attention

Preset 4: Textural

🎨 Varied Palette

Parameters: max_clips=40, overlap_factor=0.6

Character: Many short clips, less overlap, rapid changes

Timeline: Complex structure, many transitions

Best for: Experimental music, sound art, granular textures

Preset 5: Custom

🔧 User-Defined

Parameters: User specifies max_clips, overlap_factor

Character: Tailored to specific needs

Flexibility: Full control over density and structure

Best for: Advanced users, specific project requirements

Parameters & Features

User Parameters

ParameterTypeDefaultRangeDescription
PresetoptionAmbient1-5Composition style preset
Max_clipspositive303-100Maximum clips to use from folder
Overlap_factorpositive1.00.1-3.0Multiplier for overlap calculations
Draw_visualizationbooleanyesyes/noDraw timeline visualization

Internal Constants

ConstantValueDescription
target_sr44100 HzTarget sampling rate
min_clips3Minimum clips required
intensity_floor40 dBMinimum intensity for analysis
pitch_floor75 HzMinimum pitch for analysis
pitch_ceiling600 HzMaximum pitch for analysis
n_hypotheses5Number of gesture types

Output Features

FeatureTypeRangeDescription
clip_classinteger1-5Dominant gesture type (1=Sustain, etc.)
clip_post_[1-5]probability[0,1]Posterior probability for each gesture
clip_flowcontinuous[0,1]Flow characteristic (high = smooth)
clip_growthcontinuous[0,1]Growth potential (high = swells)
clip_edgecontinuous[0,0.85]Edge/brightness (high = tense)
clip_spacecontinuous[0,1]Spatial quality (high = airy)
clip_softencontinuous[0,1]Softening factor (high = pulsed)

Complete Workflow

Step-by-Step Processing

🔄 Processing Pipeline

  1. Folder selection: User selects folder with audio clips
  2. File scanning: Scan for WAV, AIFF, FLAC files
  3. Clip loading: Load up to Max_clips files
  4. Preprocessing: Convert to mono, resample to 44.1kHz
  5. Feature extraction: Intensity, spectral, harmonic features
  6. Bayesian classification: Compute gesture probabilities
  7. Macro-feature computation: Derive flow, growth, edge, space, soften
  8. Timeline construction: Build narrative arc, select clips
  9. Overlap calculation: Compute overlap between segments
  10. Assembly: Apply fades, mix clips into final drone
  11. Normalization: Scale peak to 0.95
  12. Visualization: Draw timeline (if enabled)
  13. Cleanup: Remove temporary objects

Input Requirements

Audio clip specifications:
  • Formats: .wav, .aiff, .flac
  • Duration: 0.1–30 seconds (optimal: 3–10s)
  • Channels: Mono or stereo (converted to mono)
  • Sampling rate: Any (resampled to 44.1kHz)
  • Content: Any audio material (tonal, noisy, percussive, etc.)
  • Quantity: Minimum 3 clips, recommended 10+ for good selection

Output Results

Generated drone characteristics:
  • Format: Mono, 44.1kHz, 32-bit floating point
  • Duration: Variable (depends on clips and overlaps)
  • Naming: BayesianDrone_[PresetName]
  • Peak level: Normalized to 0.95 (-0.4 dBFS)
  • Structure: Four-phase narrative arc
  • Transitions: Adaptive fades and overlaps

Visualization Output

Timeline visualization (if enabled):
  • Top: Title with preset name
  • Main plot: Timeline with color-coded segments
  • Colors: Blue=Sustain, Green=Swell, Red=Tension, Purple=Air, Orange=Pulse
  • Labels: Clip indices within segments
  • Axes: Time (seconds) vs Segment number
  • Legend: Color-key for gesture types

Useful for understanding composition structure and clip usage

Advanced Usage Tips

Creative control strategies:
  • Curate input clips: Pre-select clips with desired characteristics
  • Mix clip types: Combine tonal, noisy, percussive materials
  • Control density: Use Overlap_factor: low = sparse, high = dense
  • Scale duration: Adjust Max_clips for longer/shorter output
  • Preset blending: Run multiple times with different presets, layer results
  • Post-processing: Apply additional effects (reverb, EQ, modulation)
  • Batch processing: Process multiple folders, compare results

Troubleshooting

Problem: "Need at least 3 files" error
Cause: Folder contains <3 valid audio files
Solution: Add more audio files, check formats/extensions
Problem: Output very short or very long
Cause: Clip durations extreme, overlap calculations unusual
Solution: Use more consistent clip durations (2-10s), adjust Overlap_factor
Problem: Gaps/silence between segments
Cause: Overlap_factor too low, or flow/space very low
Solution: Increase Overlap_factor, use clips with higher flow
Problem: Classification seems wrong
Cause: Features not capturing intended characteristics
Solution: Pre-process clips (normalize, filter), or modify likelihood formulas

Mathematical Foundation

📐 Bayesian Inference Details

Full probability model:

P(h|d) = P(d|h) × P(h) / P(d) WHERE: h ∈ {sustain, swell, tension, air, pulse} d = {intensity, std_int, motion, bright_khz, harm, voiced} PRIOR: P(h) = 0.2 (uniform) LIKELIHOOD APPROXIMATION: P(d|h) ≈ exp(L(h|d)) EVIDENCE (normalization): P(d) = Σ_h P(d|h)P(h) POSTERIOR: P(h|d) = exp(L(h|d) + log(0.2)) / Σ_h' exp(L(h'|d) + log(0.2))

Note: Log-likelihoods use quadratic/linear approximations of true probability distributions. Parameters tuned empirically.