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.
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:
- 4 Compositional Forms — sorted, braid, phase, walk
- Automatic Event Segmentation — silence-based detection
- 7 Feature Trajectories — pitch, intensity, HNR, voiced, spectral centroid, spectral spread, ZCR
- Self-Supervised CNN — multi-scale convolutions, contrastive learning (pure NumPy)
- K-means Clustering — discovers morphological families
- Morphology Scoring — quantifies cluster complexity from CNN activations + raw features
- Montage Plan — reorders events, visualized with cluster-colored timeline
- Comprehensive Visualization — 6-panel display with waveforms, cluster timeline, morphology scores, embedding scatter
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
- In Praat, select exactly one Sound object (any duration, any content).
- Run script… → select
recomposer.praat. - Choose Compositional_form (sorted, braid, phase, walk).
- Set analysis parameters: silence threshold, min event duration, pitch range, fade time.
- Enable Draw_visualization for analysis display.
- Click OK — engine segments, extracts features, trains CNN, clusters, reassembles.
Morphological Composition Theory
Event Segmentation
Feature Trajectories
📊 7-Dimensional Feature Space
For each event, we extract time-varying trajectories resampled to T=128 frames:
| Feature | Description | Units |
|---|---|---|
| pitch_hz | Fundamental frequency (0 = unvoiced) | Hz |
| intensity_db | Amplitude envelope | dB |
| hnr_db | Harmonics-to-Noise Ratio | dB |
| voiced | Voicing flag (0/1) | binary |
| spectral_centroid_hz | Center of gravity of spectrum | Hz |
| spectral_spread_hz | Standard deviation around centroid | Hz |
| zcr | Zero-crossing rate (per frame) | crossings/frame |
These trajectories capture the internal temporal evolution of each event — its morphology.
CNN Architecture
Morphology Scoring
Embedding Space
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
| Parameter | Default | Description |
|---|---|---|
| Compositional_form | sorted | sorted, braid, phase, walk |
Analysis Parameters
| Parameter | Default | Description |
|---|---|---|
| Silence_threshold_db | -25 | Intensity below this = silence (dB) |
| Min_event_dur_s | 0.03 | Minimum event duration (seconds) |
| Pitch_floor_hz | 60 | Minimum pitch for analysis (Hz) |
| Pitch_ceiling_hz | 600 | Maximum pitch for analysis (Hz) |
| Fade_ms | 5 | Crossfade between events (ms) |
Output
| Parameter | Default | Description |
|---|---|---|
| Play_result | 1 | Audition after processing |
Visualization & Analysis
6-Panel Display
Reading the Cluster Timeline
- 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
- 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)
[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:
- Select a 20-60 second recording with diverse event structure
- Run with phase form to create stable-then-complex narrative
- Examine cluster timeline and morphology scores
- Export and use as movement in larger work
Algorithmic Composition
Use case: Generating new structures from existing material
Technique: Different forms on same source produce variations
Examples:
- Sorted: Gradual evolution from simple to complex
- Braid: Textural alternation between families
- Phase: Narrative arc
- Walk: Smooth morphological traversal
Sound Design for Media
Use case: Creating evolving textures, transitions, structural variations
Technique: Walk or braid on appropriate sources
Applications:
- Background evolution: Walk creates smooth changes
- Contrasting sections: Braid alternates families
- Narrative cues: Phase builds from stable to complex
Research & Education
Use case: Studying event-based structure, CNN embeddings, clustering
Technique: Compare forms on same source, examine cluster assignments
Learning outcomes:
- Understand how CNNs learn morphological features
- See how contrastive learning creates embedding spaces
- Explore relationship between raw features and clusters
- Observe how different forms produce different structures
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
Cause: Python not installed, or packages missing
Solution: Install Python and required packages: pip install numpy scikit-learn
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
Cause: Too few events (<4) or numerical instability
Solution: System falls back to random weights — still works, but embeddings less structured
Cause: Source too homogeneous, or CNN not learning
Solution: Use more varied source, or reduce k (currently 4) in Python
Cause: Fade_ms too short or zero
Solution: Increase fade_ms to 5-10ms
Advanced Techniques
In Python script, modify N_CLUSTERS (currently 4) to change number of morphological families.
Modify kernel sizes, number of channels, embedding dimension in NumpyCNN class.
In build_feature_tensor(), select which features to use by modifying F_DIM and the feature order.
Script converts to mono for analysis but preserves stereo in output. For true stereo processing, modify to extract features from both channels.