RF Concatenative — Random Forest Corpus Synthesis

Activity-aware, microphrase-based concatenative synthesis guided by a multi-target Random Forest and compositional trajectories. Version 0.5.1 introduces source-contiguous phrases, neighborhood novelty, and optional energy/brightness rendering.

Author: Shai Cohen Affiliation: Department of Music, Bar-Ilan University, Israel Version: 0.5.1 experimental (2026) License: MIT License Repo: Praat AudioTools on GitHub

What this does

RF Concatenative reorganises a source recording into a new audio sequence. It extracts a 17-dimensional timbral description for each overlapping grain, trains a multi-output RandomForestRegressor to estimate local feature-state transitions X(t) → X(t+k), and combines those predictions with a chosen trajectory in standardised corpus-feature space.

Unlike versions that could jump to a new source grain on every output hop, v0.5 selects a starting point for a short, source-contiguous microphrase, then advances through neighboring grains before making another jump. A coarse activity schedule, neighborhood-level novelty penalty, and weighted timbral matching help the result develop rather than collapse into repeated isolated fragments. The engine preserves the source sample rate and channel count; the output duration is set independently.

Compositional idea: The forest provides a local continuation hypothesis; the trajectory specifies a broader direction; and microphrase-based selection preserves small gestures from the recording. This is guided recomposition rather than a guarantee of natural speech, beat synchronisation, or learned large-scale musical form.

What changed in v0.5 / v0.5.1?

Experimental status: The new controls are intended for listening-based evaluation on different sources. Higher grain diversity or better forecasting metrics do not automatically mean a better composition.

Quick start

  1. In Praat, open a recording and select exactly one Sound in the Objects window.
  2. Open and run RF_Concatenative_v0.5.1.praat using Open Praat script and Run.
  3. Choose one of the five presets, or Custom to set the grain/forest/trajectory controls directly.
  4. Set Target_duration_s; this and Seed are not overridden by the presets.
  5. Optionally adjust the v0.5 controls (Activity_target, phrase durations, Mfcc_weight, Render_strength). The presets do not override these v0.5 fields.
  6. Run the process. A new rf_concatenative Sound appears in Praat; optional plots and playback are controlled by the output checkboxes.
Python requirement: A Python interpreter and these packages are required: numpy, scipy, librosa, scikit-learn, and soundfile. Install them using python -m pip install numpy scipy librosa scikit-learn soundfile (or python3 -m pip ..., according to your system). The Praat script includes the Python engine, so a separate engine file is not required. It may use a compatible external rf_engine_v0.5.py if one is found.

The Praat front end automatically attempts python on Windows, and common python3 locations on macOS or Linux. Input is passed through a temporary 32-bit WAV; temporary files are removed after processing.

Five presets

These are the actual preset values in the v0.5.1 Praat script. All five retain the existing names and basic grain/trajectory/forest settings. The new experimental controls remain independently adjustable.

PresetGrain / hop (ms)TrajectoryTraj. weightRepeat penaltyTrees / depth / kMusical tendency
Flowing Crescendo120 / 30crescendo_brightening0.650.60100 / 15 / 1Progressively brighter, more active, and louder.
Spectral Descent100 / 25spectral_descent0.700.65100 / 15 / 1Movement from brighter toward darker material.
Organic Wander140 / 35random_walk0.450.90120 / 18 / 1Varied timbral exploration without a forced output-level ramp.
Tight Continuity80 / 20random_walk0.250.45150 / 20 / 1More forest-led selection with a lighter target pull.
Fragmented Mosaic60 / 15random_walk0.851.6080 / 12 / 2Shorter-grain mosaic and stronger novelty pressure.

Each preset can still sound quite continuous at the microphrase scale; Fragmented Mosaic is a stylistic description, not a guarantee of click-like stuttering. spectral_descent affects spectral brightness, not fundamental-frequency pitch.

New v0.5 controls

Praat fieldDefaultWhat it changesPractical note
Activity_target0.78Approximate fraction of output hops scheduled as active.Uses a corpus-relative RMS proxy, not voice recognition. With an all-active source, the engine keeps the output active rather than manufacturing rests.
Min_phrase_ms140Minimum intended duration of a run of adjacent source grains.Converted to hop counts. Actual phrases may end sooner at activity boundaries or the end of the source.
Max_phrase_ms420Maximum intended microphrase duration.Shorter ranges encourage more jumps; longer ranges preserve more of each source gesture.
Mfcc_weight0.12Relative distance weight of MFCCs 2–13 in candidate matching.RMS, centroid, flatness, ZCR and MFCC1 have fixed separate weights. This does not remove MFCCs from RF training.
Render_strength1.0Scales the final trajectory-driven energy and high-frequency contour.0 disables this rendering stage; selection still follows the trajectory. random_walk has no additional render envelope.

Other important controls

Trajectory_weight (default 0.6) balances the RF continuation estimate against the target on the actively guided feature dimensions. Repeat_penalty (default 0.5) scales the neighborhood novelty cost. Match_input_RMS (on by default) applies a global post-rendering RMS adjustment, with upward gain capped at roughly +12 dB; Safety_peak (0.99 by default) attenuates peaks above the chosen ceiling.

The script clamps user inputs to supported ranges; phrase lengths are discretised by the hop size. A global RMS adjustment does not eliminate the within-file crescendo contour.

Processing pipeline

1 — Load and choose the analysis channel

Read the recording at its native sample rate and preserve all source channels. Mono input is analysed directly; multichannel input is analysed through the actual channel with the highest RMS, not a channel average. The resulting source-grain indices are later applied to all channels.

2 — Extract and standardise grain features

Segment the selected channel into overlapping windows; calculate RMS, spectral centroid, flatness, zero-crossing rate and MFCCs 1–13. Standardise the resulting 17-column corpus using StandardScaler. The STFT is reused for the spectral features.

3 — Learn feature-state transitions

Train a multi-target Random Forest on pairs Z[t] → Z[t+k]. Report overlap-biased OOB diagnostics and a separate chronological test with a gap to reduce overlapping-frame leakage. These are forecasting diagnostics, not subjective measures of musical success.

4 — Build the target and activity schedule

Construct crescendo_brightening, spectral_descent or random_walk over the requested output duration. A smoothed source-level contour defines where active or low-energy material is preferred. In the crescendo mode, the scheduler also biases activity toward later portions of the output.

5 — Select microphrases

At each new phrase boundary, blend the forest prediction with the relevant trajectory features. Score candidate source starts by weighted feature distance, a short future-feature average, activity agreement, join cost and a decaying ~350 ms source-neighborhood novelty penalty. Continue with adjacent source hops until the phrase expires, activity changes, or the corpus ends.

6 — Resynthesise and render

Use periodic Hann windows and overlap-add with window-envelope compensation. Trim to the exact target duration; apply final edge fades; optionally render an energy/spectral-tilt trajectory; then perform optional global RMS matching and attenuation-only peak safety. Write a 32-bit floating-point audio file for the Praat handoff.

7 — Return result and report statistics

Praat imports a Sound named rf_concatenative and can generate input/output waveforms, a grain map, match distances, optional spectrograms and a parameter summary. The engine also writes additional statistical fields to its temporary report.

Matching is no longer plain equal-weight L2: v0.5 uses a weighted feature distance and short-horizon candidate comparison, with explicit activity and novelty costs. The source-time grain map can show contiguous diagonal passages interrupted by jumps to other source regions.

Feature space — 17 dimensions

RMS energy

Amplitude-related measure; emphasised in candidate scoring and used to estimate activity.

Spectral centroid

Broad indicator of spectral brightness; a principal target in crescendo and descent trajectories.

Spectral flatness

Distinguishes spectrally flat/noisy material from more tonal spectra.

Zero-crossing rate

Time-domain proxy that can correlate with noisiness and high-frequency content.

MFCCs 1–13

Descriptor of spectral-envelope shape; coefficient 0 is excluded. MFCC1 has its own matching weight; MFCCs 2–13 share Mfcc_weight.

No explicit pitch track: The engine does not estimate or impose F0. Its spectral_descent option is a brightness descent, not a transposition algorithm.

Trajectory rendering and the crescendo

Selection can alter loudness and brightness indirectly by choosing different grains. Version 0.5 also offers a separate, controllable post-concatenation rendering stage that shapes output energy and high-frequency content over time. It is enabled at Render_strength = 1.0 and applied before RMS matching and the safety ceiling.

TrajectoryAdditional gain contour (strength 1)High-frequency contour (strength 1)
crescendo_brightening−4.5 → +4.5 dB−7 → +7 dB
spectral_descentNo programmed level ramp+7 → −7 dB
random_walkNo additional renderingNo additional rendering

The contours follow a smoothstep curve; the spectral treatment emphasises or attenuates a high-passed component (cutoff normally 1.8 kHz, or lower at low sample rates). The figures describe the programmed processing, not guaranteed measured output changes, because source selection, RMS matching and peak limiting also affect the final result.

The crescendo is intentional

On speech, a pronounced rise toward the end may be unexpected. On percussion loops and repetitive attacks, that same rise in energy, brightness and activity can supply a compelling sense of forward motion. For that reason, v0.5.1 keeps the crescendo behavior instead of automatically flattening the ending. To compare without the separate rendering stage, set Render_strength = 0 under Custom while retaining crescendo_brightening.

Creative applications

Percussion loops → evolving gestures

Use Flowing Crescendo to reassemble attacks into short source-contiguous gestures while building energy and spectral brightness. Try a rhythmic loop with diverse timbres or a longer percussion performance. The algorithm does not perform beat tracking or tempo locking.

Voice → microphrase recomposition

Use Organic Wander to preserve small voice gestures while relocating them in time. Adjust Activity_target and phrase lengths to balance articulation, pauses and reordering.

Instrumental texture → spectral descent

Spectral Descent prioritises darker material as the output progresses, supplemented by a decreasing high-frequency contour. It does not shift musical pitch directly.

Field recording → corpus exploration

Organic Wander or Fragmented Mosaic reorders environmental fragments with different balances of natural continuity, novelty and short-grain activity.

Practical listening comparison: For the same source, keep Target_duration_s and Seed constant when switching presets or changing only Render_strength. This helps separate changes caused by phrase selection from those caused by final spectral/level rendering.

Diagnostics and visualisation

Interpreting RF skill: The OOB row R² and skill versus persistence are optimistic for overlapping source windows. The separately logged chronological held-out test is a more useful additional check, but even positive predictive skill does not establish musical coherence. Trust listening alongside the grain map and activity diagnostics.

The additional v0.5 diagnostic fields are currently recorded by the Python engine; not all are displayed in the Praat visual summary panel.

Troubleshooting

IssueWhat to check
Python does not startVerify a working Python interpreter on the PATH (Windows: python; macOS/Linux: python3) and install the required packages in that interpreter.
Unexpectedly quiet or pause-heavy outputExamine Activity_target and the input recording's pauses; try a higher target for more active material. Also check input and output RMS, the +12 dB gain ceiling, and whether peak limiting subsequently attenuated the result.
Too many abrupt jumpsIncrease Min_phrase_ms / Max_phrase_ms for more source-contiguous material. Keep adequate grain overlap (e.g. a hop of about one quarter of the grain length).
Not enough variationTry shorter microphrases, higher Repeat_penalty, or a different Trajectory_weight. A stationary source cannot provide novelty it does not contain.
Output grows louder toward its endThis is an intended part of Flowing Crescendo: the source selection, activity schedule and Render_strength work together to create a rise. Use Render_strength = 0 for a comparison, or choose Organic Wander for no forced output gain ramp.
Negative RF diagnostic skillThe model is not outperforming persistence under that diagnostic. It is not necessarily a rendering failure. Check the separate chronological test and assess the musical output by listening.
Grain map has few visible pointsFor long renderings, Praat displays a subsample of up to 500 selections; it is an overview rather than a point for every grain.