CNN Event Recomposer — Morphological Composition Engine — User Guide

An event-based acoustic recomposition system that automatically segments a selected Sound into events, extracts feature trajectories, and sends them to a self-supervised CNN engine in Python. The CNN learns a latent morphology space of events, clusters them, computes dramaturgical scores, and returns a montage plan for reassembly.

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

What this does

This script implements a CNN Event Recomposer — a morphological composition engine that automatically segments a selected Sound into events, extracts feature trajectories, and sends them to a self-supervised CNN engine in Python. The CNN learns a latent morphology space of events, clusters them, computes dramaturgical scores, and returns a montage plan. Praat then reassembles the original audio by cutting and concatenating events in the new order (no pitch manipulation or spectral processing).

🧠 What is Morphological Composition?

This system treats each event as a morphological object with a temporal trajectory of acoustic features:

  • Events are detected via intensity-based segmentation
  • Feature trajectories (pitch, intensity, HNR, voiced, spectral centroid, spectral spread, ZCR) are extracted per event
  • CNN (multi-scale convolutional network) learns embeddings via contrastive self-supervision
  • Clustering (K-means) groups events into morphological families
  • Morphology scores quantify each cluster's complexity/richness
  • Montage plan reorders events according to compositional form (sorted, braid, phase, walk)

The result is a structural AI engine for event-based acoustic form — no sound synthesis, just intelligent reordering.

Key Features:

Technical Implementation: (1) Event Segmentation: Intensity → TextGrid → sounding intervals. (2) Feature Extraction: Per event, extract 7 feature trajectories resampled to 128 frames. (3) CNN Training: Multi-scale conv (k=9,21), max-pool, global pool, dense to 32-dim embedding. Contrastive NT-Xent loss. (4) Clustering: K-means on embeddings. (5) Morphology Scoring: Weighted combination of voiced ratio, HNR variance, intensity slope, CNN activation entropy. (6) Montage Planning: Reorder events per selected form. (7) Reassembly: Concatenate events with fades.

Quick start

  1. In Praat, select exactly one Sound object (any duration, any content).
  2. Run script… → select recomposer.praat.
  3. Choose Compositional_form (sorted, braid, phase, walk).
  4. Set analysis parameters: silence threshold, min event duration, pitch range, fade time.
  5. Enable Draw_visualization for analysis display.
  6. Click OK — engine segments, extracts features, trains CNN, clusters, reassembles.
Quick tip: Start with sorted form on a 10-20 second recording with varied texture. Enable visualization — you'll see the original waveform with event boundaries (red lines), the recomposed waveform, and a colored cluster timeline. The CNN will discover morphological families (colors) and reorder events by cluster morphology score. The output appears as "source_recomposed_CNN" in the Objects window.
Important: PYTHON DEPENDENCIES — Requires Python with numpy and scikit-learn. CNN TRAINING happens on-the-fly and may take 1-3 minutes for 100+ events. EVENT SEGMENTATION uses intensity threshold — adjust silence_threshold_db for your material. MIN EVENT DURATION should be at least 0.03s; smaller events may be noise. FADE_MS prevents clicks at event boundaries (5ms recommended).

Morphological Composition Theory

Event Segmentation

Events are detected via intensity-based silence detection: intensity < silence_threshold_db → silence intensity ≥ silence_threshold_db → sounding Sounding intervals are kept if duration ≥ min_event_dur_s. Silence intervals shorter than 0.08s are merged. Result: N events with precise start/end times.

Feature Trajectories

📊 7-Dimensional Feature Space

For each event, we extract time-varying trajectories resampled to T=128 frames:

FeatureDescriptionUnits
pitch_hzFundamental frequency (0 = unvoiced)Hz
intensity_dbAmplitude envelopedB
hnr_dbHarmonics-to-Noise RatiodB
voicedVoicing flag (0/1)binary
spectral_centroid_hzCenter of gravity of spectrumHz
spectral_spread_hzStandard deviation around centroidHz
zcrZero-crossing rate (per frame)crossings/frame

These trajectories capture the internal temporal evolution of each event — its morphology.

CNN Architecture

Input: X ∈ ℝ¹²⁸×⁷ (event resampled to 128 frames × 7 features) Branch A: Conv1D(k=9, C_in=7, C_out=8, same) → ReLU Branch B: Conv1D(k=21, C_in=7, C_out=8, same) → ReLU Concat → [128, 16] MaxPool1D(size=4) → [32, 16] Conv1D(k=9, C_in=16, C_out=16, same) → ReLU → [32, 16] GlobalMeanPool + GlobalMaxPool → [32] Dense(32 → 32) → embedding e ∈ ℝ³² Contrastive loss (NT-Xent) with augmentations (noise, dropout, jitter, warp)

Morphology Scoring

For each cluster c: morphology_score[c] = 0.25 × voiced_mean + 0.25 × tanh(HNR_variance) + 0.25 × tanh(intensity_slope_mean) + 0.25 × entropy(mean_CNN_activation) / log(16) where: • voiced_mean = fraction of voiced frames in cluster • HNR_variance = mean variance of HNR trajectories • intensity_slope = mean absolute slope of intensity • CNN_activation_entropy = entropy of mean pool-layer activations Score normalized to [0,1]. Higher = more complex, morphologically rich.

Embedding Space

The contrastive CNN learns to map events to a 32-dimensional space where: • Similar events (augmentations of same event) are close • Dissimilar events are far apart K-means clustering (k=3-4) discovers morphological families. The embedding norm per event is visualized in the scatter plot.

Compositional Forms

Form 1: Sorted

📊 Cluster Blocks by Morphology Score

Clusters are ordered by ascending morphology score (least complex → most complex). Within each cluster, events are in chronological order.

Effect: Gradual progression from simple, stable material to complex, rich material.

Example: C0 (stable) → C0 → C0 → C1 → C1 → C2 → C2 → C2

Form 2: Braid

🪢 Interleaved Round-Robin

Clusters are interleaved round-robin style in score order. Events from each cluster are taken in chronological order until that cluster is exhausted.

Effect: Constant alternation between morphological families — creates texture of contrasting materials.

Example: C0₁ → C1₁ → C2₁ → C0₂ → C1₂ → C2₂ → ...

Form 3: Phase

🔄 Stable-Then-Complex

The first half of the montage uses only the two lowest-score clusters (stable material). The second half introduces the remaining clusters in score order.

Effect: Builds from stable foundation to complex development — narrative arc.

Example: C0 → C0 → C1 → C1 → C1 → C2 → C2 → C3 (if k=4, half=2)

Form 4: Walk

🚶 Nearest-Neighbor Traversal

Greedy nearest-neighbor walk through embedding space. Start from event with lowest embedding norm (most central), then repeatedly move to the nearest unused event.

Effect: Smooth traversal through morphological space — organic evolution.

Traversal log: The Python script prints the event ID sequence and cluster sequence to the Info window, e.g., "12 → 7 → 43 → 28 → ..." and "C0 → C2 → C1 → C0 → ..."

Parameters & Controls

Compositional Parameters

ParameterDefaultDescription
Compositional_formsortedsorted, braid, phase, walk

Analysis Parameters

ParameterDefaultDescription
Silence_threshold_db-25Intensity below this = silence (dB)
Min_event_dur_s0.03Minimum event duration (seconds)
Pitch_floor_hz60Minimum pitch for analysis (Hz)
Pitch_ceiling_hz600Maximum pitch for analysis (Hz)
Fade_ms5Crossfade between events (ms)

Output

ParameterDefaultDescription
Play_result1Audition after processing

Visualization & Analysis

6-Panel Display

CNN Event Recomposer Visualization: Panel 1: TITLE • Script name, source name, event count, cluster count, form Panel 2: ORIGINAL WAVEFORM • Gray waveform • Red dotted lines = event boundaries • Title: "Original sound + event boundaries" Panel 3: RECOMPOSED WAVEFORM • Blue waveform • Title: "Recomp." • X-axis: Time (s) Panel 4: CLUSTER TIMELINE • X-axis: Recomposed time, Y-axis: cluster (0-1) • Colored horizontal bars = each event, colored by cluster • White text = cluster ID (e.g., "C0", "C1") for longer events • Title: "Cluster timeline (sorted by morphology score)" Panel 5: CLUSTER MORPHOLOGY SCORES • X-axis: Cluster ID, Y-axis: Score (0-1) • Colored bars matching timeline colors • Score values displayed above bars • Title: "Cluster morphology scores (CNN-derived)" Panel 6: EMBEDDING NORM SCATTER • X-axis: Montage position, Y-axis: embedding norm (‖emb‖) • Colored circles = each event, color by cluster • Shows how embedding norm varies through montage • Title: "Embedding norm per event (montage order, coloured by cluster)" Panel 7: SUMMARY PANEL • Source info, duration, events, clusters • Frame step, pitch range, fade time • CNN architecture summary

Reading the Cluster Timeline

What the colors mean:
  • Each color represents a morphological family (cluster) discovered by the CNN
  • Color sequence shows the montage plan — how events are reordered
  • Bar length = event duration in the recomposed output
  • White labels (C0, C1, etc.) help identify clusters for longer events
  • The order of clusters in the legend follows morphology score (lowest to highest)

Reading the Embedding Scatter

What the dots show:
  • X-axis: Position in montage (1 to N)
  • Y-axis: Embedding norm — a measure of how "extreme" the event is in latent space
  • Color: Same cluster assignment as timeline
  • Patterns: In "sorted" form, you may see norm increase over time as more complex events appear
  • Walk form: Dots will show smooth transitions between neighbors

Traversal Log (Info Window)

For walk form, the Python script prints:
[walk] traversal: 12 -> 7 -> 43 -> 28 -> ...
[walk] clusters:  C0 -> C2 -> C1 -> C0 -> ...

This shows the exact event ID sequence and cluster sequence, useful for understanding the path through embedding space.

Applications

Electroacoustic Composition

Use case: Creating structural recompositions from existing material

Technique: All forms, especially phase and walk

Workflow:

Algorithmic Composition

Use case: Generating new structures from existing material

Technique: Different forms on same source produce variations

Examples:

Sound Design for Media

Use case: Creating evolving textures, transitions, structural variations

Technique: Walk or braid on appropriate sources

Applications:

Research & Education

Use case: Studying event-based structure, CNN embeddings, clustering

Technique: Compare forms on same source, examine cluster assignments

Learning outcomes:

Practical Workflow Examples

🎬 Film Scene: Emotional Arc

Goal: Create 60-second cue with emotional arc (stable → complex)

Settings:

  • Source: 30-second ambient recording
  • Form: phase
  • silence_threshold_db = -30 (more sensitive)

Result: First half: stable, consonant events; second half: complex, rich events — emotional build

🎚️ Electronic Music: Textural Variation

Goal: Create textural variation from drum loop

Settings:

  • Source: 8-second drum loop
  • Form: braid
  • min_event_dur_s = 0.05 (finer segmentation)

Result: Alternating between morphological families (e.g., kick-dominant, snare-dominant, cymbal-dominant)

🎙️ Voice Processing: Morphological Journey

Goal: Transform spoken phrase into abstract journey

Settings:

  • Source: 10-second spoken phrase
  • Form: walk

Result: Smooth traversal through embedding space — voice morphs through its own events in a continuous path

Troubleshooting Common Issues

Problem: Python not found or missing packages
Cause: Python not installed, or packages missing
Solution: Install Python and required packages: pip install numpy scikit-learn
Problem: No events detected
Cause: silence_threshold_db too high or too low, or source has no clear silences
Solution: Adjust threshold (-20 to -40 dB range), or reduce min_event_dur_s
Problem: CNN training diverges
Cause: Too few events (<4) or numerical instability
Solution: System falls back to random weights — still works, but embeddings less structured
Problem: All events in one cluster
Cause: Source too homogeneous, or CNN not learning
Solution: Use more varied source, or reduce k (currently 4) in Python
Problem: Output has clicks
Cause: Fade_ms too short or zero
Solution: Increase fade_ms to 5-10ms

Advanced Techniques

Custom k value:

In Python script, modify N_CLUSTERS (currently 4) to change number of morphological families.

CNN architecture tuning:

Modify kernel sizes, number of channels, embedding dimension in NumpyCNN class.

Feature selection:

In build_feature_tensor(), select which features to use by modifying F_DIM and the feature order.

Multi-channel input:

Script converts to mono for analysis but preserves stereo in output. For true stereo processing, modify to extract features from both channels.