Perceptual Graph Explorer: Audio Texture Segmentation
A Praat script that analyzes audio through perceptual feature extraction and k-means clustering to separate different texture types into distinct audio layers.
What this does
The Perceptual Graph Explorer analyzes audio by extracting three perceptual features from sliding windows, creating a 3D feature space, clustering similar windows together, and reconstructing separate audio streams for each cluster. Think of it as "color separation for audio" - different texture types are extracted into separate layers.
π Core Process Pipeline
- Windowing: Divide audio into overlapping frames (50ms windows by default)
- Feature Extraction: Calculate three perceptual features for each frame
- Normalization: Scale features to 0-1 range for clustering
- Clustering: Group similar frames using k-means algorithm
- Reconstruction: Create separate audio files for each cluster
- Visualization: Display feature space and cluster distributions
Key Innovation: Instead of traditional frequency-based analysis, this uses perceptual features that correspond to how humans hear textures. The result is intuitive separation based on "what sounds similar" rather than mathematical similarity.
Quick Start
- In Praat, select exactly one Sound object (mono or stereo).
- Open the script editor and load
Perceptual_Graph_Explorer.praat. - Choose a Preset or use Custom settings:
- 2 Clusters - Basic Split: Good starting point
- 3 Clusters - Detailed: More nuanced separation
- 4 Clusters - Fine Analysis: For complex audio
- Adjust parameters if needed (see guide below).
- Enable Draw_visualization for graphical output.
- Click Run β Run (or Ctrl+R).
- Listen to the resulting cluster sounds individually.
- Start with short audio (10-30 seconds) for testing
- Use 3 Clusters - Detailed preset for most material
- Enable visualization to understand the clustering
- Listen to each cluster sound separately first
- For speech: Try 2-3 clusters (voice, silence, noise)
- For music: Try 3-4 clusters (melody, harmony, percussion, background)
- Audio length: Must have enough frames for clustering (at least 2Γ number_of_clusters)
- Processing time: Scales with audio length and number of clusters
- Feature simplicity: Uses only 3 features - may miss subtle differences
- Fixed clustering: k-means requires pre-specified cluster count
- Overlap artifacts: Crossfade helps but may not eliminate all artifacts
Perceptual Feature Theory
The Three Perceptual Dimensions
ποΈ Dimension A: Energy (Intensity)
What it measures: Loudness/amplitude envelope of the audio frame
Separation examples: Loud vs. soft sections, foreground vs. background, speech vs. silence
π΅ Dimension B: Stability (Harmonicity)
What it measures: Degree of periodicity/pitchedness in the frame
Separation examples: Voice vs. noise, melody vs. percussion, harmonic vs. inharmonic
π Dimension C: Brightness (Spectral Centroid)
What it measures: Center of gravity of the frequency spectrum
Separation examples: Bass vs. treble, dark vs. bright textures, low vs. high instruments
Why These Three Features?
Perceptual Foundations: These three features correspond to fundamental auditory dimensions:
- Energy: Related to auditory attention (loud sounds grab attention)
- Stability: Related to source identification (pitched = likely voice/instrument)
- Brightness: Related to timbre perception and auditory stream formation
Computational Efficiency: Three features provide enough discrimination while remaining computationally tractable. More features could lead to overfitting or the "curse of dimensionality."
Interpretability: Each feature has clear perceptual meaning, making results interpretable to human listeners.
Feature Space Construction
Clustering Algorithm: K-Means Implementation
π― Custom K-Means Clustering in Praat
Algorithm Steps:
Distance Metric: Euclidean in 3D Space
Why Euclidean distance? Simple, fast, and works well for normalized features. In the unit cube [0,1]Β³, Euclidean distance has clear geometric interpretation.
Cluster Characterization
π·οΈ Automatic Cluster Labeling
Label generation based on feature averages:
| Feature Range | Label | Interpretation |
|---|---|---|
| Energy > 0.66 | _HighEnergy | Loud sections |
| Energy < 0.33 | _LowEnergy | Quiet sections |
| Stability > 0.66 | _Stable | Pitched/tonal |
| Stability < 0.33 | _Unstable | Noisy/unpitched |
| Brightness > 0.66 | _Bright | High-frequency content |
| Brightness < 0.33 | _Dark | Low-frequency content |
Example labels: Cluster_1_HighEnergy_Stable_Bright would be loud, pitched, high-frequency content (e.g., trumpet melody).
Audio Reconstruction from Clusters
Crossfade importance: Without crossfade, concatenated windows would create clicks at boundaries. 5ms crossfade (default) provides smooth transitions.
Parameters Explained
Preset Configurations
| Preset | Clusters | Window (ms) | Step (ms) | Overlap (ms) | Best For |
|---|---|---|---|---|---|
| 2 Clusters - Basic Split | 2 | 60 | 30 | 5 | Simple separation (speech/background) |
| 3 Clusters - Detailed | 3 | 50 | 25 | 5 | Most audio (default) |
| 4 Clusters - Fine Analysis | 4 | 40 | 20 | 5 | Complex music, detailed analysis |
| Custom | User | User | User | User | Experimental, specific needs |
Analysis Parameters
π§ Window_length_ms (grain size)
Range: 20-200 ms (typical: 40-80 ms)
Effect:
- Too small (οΌ30ms): Poor frequency resolution, noisy features
- Optimal (40-80ms): Good tradeoff for most audio
- Too large (οΌ100ms): Poor temporal resolution, misses rapid changes
Musical correlation: ~50ms β sixteenth note at 120 BPM
βοΈ Step_size_ms (hop size)
Range: 10-50 ms (typically Β½ to ΒΌ of window length)
Effect:
- Small step (high overlap): More frames, smoother reconstruction, slower processing
- Large step (low overlap): Fewer frames, may miss transitions, faster processing
Default: 25ms provides 50% overlap with 50ms window (good balance)
π― Number_of_clusters
Range: 2-8 (practical limit based on audio complexity)
Choosing the right number:
- 2 clusters: Binary separation (foreground/background)
- 3 clusters: Most natural audio (voice, music, noise)
- 4 clusters: Complex music (melody, harmony, percussion, effects)
- οΌ4 clusters: May create artificial splits
Rule of thumb: Start with 3, adjust based on results
Smoothing & Output Parameters
| Parameter | Default | Range | Effect |
|---|---|---|---|
| Overlap_time_ms | 5 ms | 1-20 ms | Crossfade between concatenated windows |
| Scale_peak | 0.95 | 0.1-1.0 | Output amplitude normalization |
| Draw_visualization | On | On/Off | Display feature space and clusters |
| Play_result | On | On/Off | Play first cluster after processing |
Output & Interpretation
Generated Sound Objects
Output naming convention: Cluster_X_Description
Examples:
Cluster_1_HighEnergy_Stable_Bright- Loud, pitched, high-frequencyCluster_2_MidEnergy_Unstable_Dark- Medium volume, noisy, low-frequencyCluster_3_LowEnergy_Stable_MidBright- Quiet, pitched, mid-frequency
What each cluster contains:
- Temporal structure: Windows appear in original time order
- Gaps: Between windows from same cluster may have silence
- Continuity: Crossfade provides smooth transitions within cluster
- Duration: Same as original audio (with silences where other clusters were)
Information Window Output
Interpreting Cluster Statistics
Frame count: How many windows assigned to each cluster. Larger clusters = more prevalent texture.
Energy values (0-1):
- 0.8-1.0: Very loud sections
- 0.4-0.7: Medium volume
- 0.0-0.3: Quiet sections
Stability values (0-1):
- 0.8-1.0: Highly periodic (voice, sustained instruments)
- 0.4-0.7: Moderately periodic
- 0.0-0.3: Noise-like (percussion, fricatives, wind)
Brightness values (0-1): Normalized frequency position. Higher = brighter timbre.
Applications & Use Cases
Audio Analysis & Research
π¬ Texture Analysis in Soundscapes
Use case: Analyzing environmental recordings
Method:
- Record or load soundscape (forest, city, underwater)
- Use 4 Clusters - Fine Analysis preset
- Examine cluster characteristics
- Interpret: Which clusters correspond to which sources?
Example results:
- Cluster 1: Bird songs (HighEnergy, Stable, Bright)
- Cluster 2: Wind/leaves (MidEnergy, Unstable, MidBright)
- Cluster 3: Distant traffic (LowEnergy, Unstable, Dark)
- Cluster 4: Occasional events (variable)
Music Production & Sound Design
π΅ Isolating Musical Elements
Use case: Extracting drum groove from full mix
Method:
- Load music track with drums, bass, melody
- Use 3 Clusters preset
- Listen to each cluster separately
- Identify which cluster contains drums (typically Unstable, MidBright)
- Use that cluster as starting point for drum processing
Creative applications:
- Create "stems" from finished mixes
- Isolate vocal breaths/artifacts for removal
- Extract specific instrument characteristics
- Create texture-based effects
Speech & Voice Processing
π£οΈ Voice/Noise Separation
Use case: Cleaning noisy speech recordings
Method:
- Load noisy speech recording
- Use 2 Clusters - Basic Split preset
- Cluster 1 will likely be voice (Stable, MidEnergy)
- Cluster 2 will likely be noise (Unstable, variable Energy)
- Save Cluster 1 as cleaned speech
- Optional: Mix small amount of Cluster 2 back for naturalness
Limitations: Works best when voice and noise have different feature profiles. May struggle with similar noise types.
Educational & Cognitive Studies
π§ Perceptual Grouping Demonstrations
Use case: Teaching auditory scene analysis principles
Method:
- Create or use audio with multiple concurrent streams
- Run perceptual graph analysis
- Show how clusters correspond to perceptual groups
- Discuss which features drive segregation
- Compare with Bregman's ASA principles
Example: Bach fugue - Show how different voices separate into clusters based on pitch range and timing.
Visualization Guide
π Understanding the Graphical Output
Six visualization panels:
| Panel | Content | Purpose |
|---|---|---|
| Title | Script name, filename, preset | Context |
| Original Waveform | Complete input waveform (gray) | Reference |
| Cluster Waveforms | Separate waveforms for each cluster (colored) | Show temporal distribution |
| Feature Space | 2D plot: Energy vs Brightness, colored by cluster | Show clustering in feature space |
| Cluster Centroids | Black crosses in feature space | Show cluster centers |
| Cluster Distribution | Bar chart of frame counts per cluster | Show cluster sizes |
| Parameters | Settings used | Documentation |
Color Coding
Interpreting the Feature Space Plot
Axes:
- X-axis (Energy): 0 = minimum energy, 1 = maximum energy
- Y-axis (Brightness): 0 = darkest/lowest frequencies, 1 = brightest/highest frequencies
Points: Each dot represents one 50ms window of audio.
Clustering patterns:
- Tight clusters: Distinct texture types
- Spread along diagonal: Correlation between energy and brightness
- Vertical spread at certain energies: Same loudness but different timbres
- Horizontal spread at certain brightness: Same timbre but different volumes
Ideal clustering: Well-separated clusters with minimal overlap.
Troubleshooting Visualization Issues
Causes: Poor feature range, all windows similar, normalization issue
Solutions: Check audio diversity, try different window size, examine raw features
Problem: Clusters overlap heavily in visualization
Causes: Too many clusters for audio complexity, poor feature discrimination
Solutions: Reduce number_of_clusters, examine which features are not discriminating
Problem: Visualization missing or incomplete
Causes: Audio too short, not enough frames, Praat viewport issues
Solutions: Use longer audio, reduce step_size for more frames, check Praat version