Spectral Noise Shaping
Corpus-driven random-phase spectral resynthesis. Learn spectral shapes and temporal envelopes from recorded sounds, then compose new stereo textures through random sampling, observed transitions, morphological replay, feature-directed migration, or spectral counterpoint.
What it does
Spectral Noise Shaping analyses a folder of recordings and builds an ordered bank of level-independent spectral magnitude profiles. It also learns temporal RMS envelopes. The generator then reconstructs new audio by combining learned spectral magnitudes with random phases extracted from independently generated white-noise signals for the left and right channels.
Unlike a conventional playback, time-stretching, or granular sampler, the output does not directly reuse the source waveforms or their phases. The Generation mode determines how the learned spectral material unfolds over musical time, while the Texture preset determines its analysis/synthesis grain and degree of variation.
Five synthesis modes
Random cloud, Markov spectral walk, morphological replay, spectral migration, and spectral counterpoint.
Two independent stereo phases
The channels use distinct noise phases. In Counterpoint they can also follow distinct spectral paths.
Temporal morphology
Choose a corpus-mean envelope, the selected spectral trajectory's RMS, or a flat envelope.
Corpus-to-result inspection
Compare mean spectra, amplitude envelopes, intended and realised centroids, and the resulting waveform.
Quick start
Spectral_Noise_Shaping.praat from Praat AudioTools. The script first checks that Python and the required libraries are available.Input_folder, or leave it blank to select a folder after submitting the form. The default Generation mode is Markov spectral walk.Duration = 3.0 seconds and Texture_preset = Manual. A named texture preset overrides the main form's Variation and Spectral continuity values.Seed in Random cloud, Markov spectral walk, and Morphological replay. Compare how each mode turns the same learned profiles into a different form of musical time. Set Seed = 0 for a new random result each run.pip install numpy scipy soundfile. Processing time depends on corpus size, output duration, FFT settings, and computer performance; large corpora are not guaranteed to finish in seconds.Generation modes
The Generation_mode menu contains eight choices representing five underlying synthesis algorithms. Spectral migration appears as four separately selectable directions.
| Menu selection | How it uses the corpus | Compositional character |
|---|---|---|
| Random cloud (v1.4 classic) | Randomly selects and blends two spectral frames at each hop, mixes them with the mean profile, and can apply spectral inertia. | Textures that do not follow the corpus's original order. |
| Markov spectral walk default | Usually follows observed frame-to-frame successors; otherwise jumps to spectrally similar states, with occasional unrestricted jumps. | New paths that retain local connections to the corpus. |
| Morphological replay | Traverses a selected source file's temporal sequence, including silence positions and RMS levels, at a chosen time stretch. | Source-derived gestures and temporal shapes rebuilt with random phases. |
| Spectral migration: rising | Traverses profiles towards increasingly high values of the selected feature. | Dark-to-bright (Centroid) or tonal-to-noisy (Flatness) tendency. |
| Spectral migration: falling | Traverses the same feature in descending order. | Bright-to-dark or noisy-to-tonal tendency. |
| Spectral migration: arch | Moves from lower to higher feature values, then returns. | An arch-like trajectory. |
| Spectral migration: valley | Moves from higher to lower feature values, then returns. | A valley-like trajectory. |
| Spectral counterpoint | Builds independent stochastic walks for left and right; blends their spectral shapes using Stereo coupling. | Interacting stereo timbral trajectories rather than phase decorrelation alone. |
Variation = 0 largely collapses the spectral profiles towards the corpus mean, so a sophisticated path may no longer be clearly audible. To hear a mode's path behaviour, use moderate-to-high Variation. Spectral_continuity is interpreted differently across modes; it is not a universal time-stretch control.Texture presets
Texture presets are complete starting snapshots for Chunk size, Hop length, N fft, Variation, and Spectral continuity. They affect the sound's spectral time resolution and the amount and smoothness of variation.
| Texture preset | Chunk / Hop / FFT | Variation | Continuity | Intended starting character |
|---|---|---|---|---|
| Manual default | 2048 / 512 / 2048 | 0.70 | 0.75 | Use the values from the main dialog; the analysis grid starts at 2048 / 512. |
| Stable portrait | 4096 / 512 / 4096 | 0.10 | 0.95 | Relatively stable spectral identity, near the corpus mean. |
| Granular flutter | 1024 / 256 / 1024 | 0.85 | 0.20 | Fine, rapid spectral activity and more varied texture. |
| Diffuse cloud | 2048 / 512 / 2048 | 0.70 | 0.50 | A middle ground between dispersed events and perceptible continuity. |
| Slow wash | 8192 / 1024 / 8192 | 0.25 | 0.95 | Broader, smoother spectral motion with restrained variation. |
At 44.1 kHz, the chunk lengths 1024, 2048, 4096, and 8192 correspond to approximately 23, 46, 93, and 186 ms respectively. These presets are proposed creative starting points; the script's comments explicitly state that they have not been established through systematic listening tests.
Main controls and defaults
| Control in Praat | Default | Meaning |
|---|---|---|
Input_folder | Blank | Corpus folder; if left blank, a folder chooser opens after the form. |
Generation_mode | Markov spectral walk | Choose one of the eight menu entries described above. |
Texture_preset | Manual | Choose a complete texture snapshot, or retain manual parameters. |
Duration | 3.0 s | Output duration in seconds. Must be positive. |
Seed | 0 | 0 = new random generator seed; positive integer = reproducible result with identical input and settings. |
Variation | 0.70 | 0–1. Blend between mean spectral shape and mode-specific profiles. Replaced by a named texture preset unless overridden in Advanced. |
Spectral_continuity | 0.75 | 0–1. Controls spectral inertia, likelihood of following observed successors, or permitted local deviations, depending on mode. |
Envelope | Auto | Auto: Follow trajectory for Replay, Learned mean for other modes. Explicit choices: Learned mean, Follow trajectory, Flat. |
Corpus_weighting | Equal per file | Equal: choose source files with equal probability when sampling; By duration: prefer longer files / more represented frames. The latter is the v1.4-style choice. |
Show_advanced_settings | Off | Opens a second dialog before generation for fine controls. |
Draw_visualization | On | Draw a comparative figure in Praat's Picture window. |
Play_result | On | Play the generated Sound after import. |
Envelope modes
Auto
Uses Follow trajectory in Morphological replay; uses Learned mean in other modes.
Learned mean
Applies the average of individually peak-normalised file RMS envelopes, each resampled to 200 points.
Follow trajectory
Applies frame RMS levels associated with the selected path. In Replay this carries the source's temporal gaps and gesture.
Flat
No learned RMS contour is imposed. The output still receives the final fades and peak normalisation.
Advanced settings
Enable Show_advanced_settings to open a second Praat dialog. It shows the effective Variation and Continuity values, and permits manual override of the analysis grid and mode-specific parameters.
| Advanced control | Starting value | Function / constraint |
|---|---|---|
Variation | Effective form/preset value | 0–1; Advanced overrides the main form or selected preset. |
Spectral continuity | Effective form/preset value | 0–1; interpretation depends on the generation mode. |
N fft | Preset Chunk size (Manual: 2048) | Canonical spectral frequency grid. Minimum 64; need not be identical to Chunk size after an Advanced edit. |
Chunk size | Preset value (Manual: 2048) | Analysis and synthesis frame length in samples. Must be a power of two, at least 64, and at least twice Hop length. |
Hop length | Preset value (Manual: 512) | Advance between neighbouring frames. Must be at least 1 sample. |
Sample rate | 44100 Hz | Target analysis and output sample rate; minimum 8000 Hz. |
Max profiles | 20000 | Hard limit on retained active spectral frames; minimum 100. The engine uses per-file decimation when needed. |
Replay stretch | 0 | 0 = automatically fit the initially selected source's timeline to Duration. 2 = half-speed traversal (2 output seconds per source second); positive values only. |
Migration feature | Centroid (dark–bright) | Either spectral Centroid or Flatness (tonal–noisy); applies to all four migration directions. |
Stereo coupling | 0.30 | Counterpoint only: 0 = independent spectral paths, 1 = the right spectral shape follows the left. Noise phases remain independent. |
A corpus with more readable, usable files than Max profiles is rejected with a clear message, because at least one timeline slot per file must be reserved. The cap applies to retained spectral profiles, not to the size of a file while it is temporarily loaded for analysis.
How the engine works: five stages
- Scan and load. Read metadata for WAV/AIFF/FLAC files recursively; skip sources shorter than 0.2 s. During analysis, load files one by one, resample as required, and peak-normalise each file to 0.95. For multichannel material, combine channel magnitude powers rather than arbitrarily selecting one channel or cancelling out-of-phase channels.
- Analyse and learn. Analyse overlapping Hann-windowed frames, create unit-RMS spectral magnitude profiles, preserve frame order and links to successive frames, and learn RMS envelopes. If needed, retain an order-preserving subset under the hard Max profiles cap. Morphological replay additionally stores a time-aligned timeline including silent slots.
- Construct a spectral path. Select, transition between, replay, order, or independently traverse the learned profiles according to Generation mode. Variation controls how strongly those profiles replace the mean spectral shape.
- Resynthesise and shape. Generate independent left/right white-noise phases, impose the intended magnitude spectrum on each frame, inverse-transform and overlap-add. Apply the chosen RMS contour (smoothed over approximately 20 ms), then a short fade-in/out and a single global peak normalisation towards 0.90, preserving stereo balance.
- Save and measure. Write a stereo floating-point WAV, compute comparative QC data, and write an explicit completion marker only after the required stages succeed. Praat imports the Sound, draws the optional figure, and removes temporary files.
spectral_noise_shaped_random, spectral_noise_shaped_walk, spectral_noise_shaped_replay, spectral_noise_shaped_migration, or spectral_noise_shaped_counterpoint, according to the active synthesis algorithm. All modes render stereo audio.Visualization and quality-control metrics
With Draw_visualization enabled, Praat produces a corpus-to-result comparison rather than the older waveform/spectrogram-only display. The figure contains a title and settings strip, a corpus and metrics summary, four plots, and a result summary.
| Plot | What is shown | How to read it |
|---|---|---|
| Spectral character | Normalised corpus-mean magnitude (blue) versus rendered-output mean (red), on a logarithmic frequency axis. | Compares overall spectral character; it does not measure whether source events occurred in their original order. |
| Temporal shape | Target RMS envelope (blue) versus actual output RMS (red), over normalised time. | Shows how closely the amplitude contour was realised. |
| Spectral trajectory | Intended spectral centroid versus realised output centroid over seconds. Counterpoint shows distinct traces for left and right. | Reveals whether the time-varying spectral path was acoustically realised. |
| Generated stereo result | Waveform of the resulting stereo Sound. | Shows the final amplitude shape and distribution of activity through time. |
Metrics in the figure
| Metric | Interpretation | Limits |
|---|---|---|
| Spectral similarity | Cosine similarity between average corpus and output magnitude spectra, computed using the same analysis window/FFT pipeline. | High similarity means similar average spectra, not matching temporal organisation. The figure presents it as a percentage. |
| Envelope similarity | Cosine similarity of target and output RMS envelopes. | Measures resemblance of overall contours; not an exact waveform match. |
| Temporal structure | Ratio of output to corpus slow-scale spectral movement. Around 1 means a similar amount of movement; values above 1 indicate more movement. | The ratio is capped at 2 and is reported as n/a when the corpus is too static or the comparison is not meaningful. It is not a measure of event-order fidelity. |
| Path fidelity r | Correlation between intended and realised spectral-centroid trajectories. | Ranges from -1 to 1 when defined. It may be n/a for nearly constant intended paths. In Counterpoint it is reported separately for L and R. |
| L–R centroid correlation | Correlation between realised left/right centroid trajectories in Counterpoint. | Measures similarity of spectral motion between channels, not overall stereo width or phase correlation; reported as n/a where not meaningful. |
The Python engine exports temporary profile, envelope, trajectory and summary CSV files for Praat. The summary CSV includes validity flags for optional QC metrics, so an undefined value is distinguished from a legitimate correlation of -1. Temporary files are normally deleted after the Praat figure is drawn.
Compositional approaches
Timbral portrait
Try Random cloud with Stable portrait, or reduce Variation manually. Listen for the corpus's overall spectral identity without its original gestures.
Source gesture without source phase
Use Morphological replay with Envelope = Auto. Adjust Replay stretch and Duration to reshape time while keeping the selected file's temporal contour.
Statistical exploration
Use Markov spectral walk, then vary Spectral continuity to move between locally connected paths and more disruptive jumps.
Directed timbral form
Choose Spectral migration rising, falling, arch or valley, and compare Centroid with Flatness as the organising feature.
Spectral stereo dialogue
Choose Spectral counterpoint. Move Stereo coupling from 0 towards 1 to progress from independent timbral trajectories to shared spectral motion.
Fair corpus exploration
Use Equal per file when recordings differ greatly in length. Use By duration when the distribution of recorded time should influence selection.
Musical descriptors such as “smooth”, “fluttery”, and “dark–bright” describe intended tendencies, not guaranteed perceptual outcomes. The actual character depends on the recorded corpus and the selected mode.
FAQ and troubleshooting
Praat cannot find Python or reports missing dependencies.
Install Python 3 and numpy, scipy, and soundfile in the interpreter Praat can call. On Windows the script probes python, py and python3; on other systems it tries python3, python and py. The dependency probe runs before the main settings form.
Praat cannot find praat_spectral_gen.py.
The Praat script first looks for py/praat_spectral_gen.py inside plugin_AudioTools under the Praat preferences directory, and otherwise looks for praat_spectral_gen.py in Praat's current default directory. Make sure the Python engine is installed at one of those locations.
What do “Chunk size must be a power of 2” and “at least 2 x Hop length” mean?
Choose a power-of-two Chunk size (for example 1024, 2048, 4096, or 8192) and keep Chunk size ≥ 2 × Hop length. A named Texture preset selects a validated combination; Advanced values are checked before the engine starts.
Why do the main Variation and Continuity fields seem to have no effect?
When a named Texture preset is selected, it explicitly replaces those two values. Select Manual to use the main form values, or open Advanced settings to override the effective preset values there.
Does Morphological replay reproduce the original recording?
No. It follows the selected source's ordered spectral and RMS timeline, including represented silence positions, but each output frame is reconstructed from learned magnitudes and random noise phases. Decimation, frame resolution, smoothing, and the chosen settings can alter fine details.
Why are there two different-looking stereo channels?
All modes use independent white-noise phases for L and R. In Random, Walk, Replay and Migration, the underlying spectral paths are shared. In Counterpoint, the paths may differ; Stereo coupling = 1 matches their spectral magnitudes, not their noise phases.
“Max profiles” error or slow analysis on a large corpus?
Max profiles places a hard cap on retained active spectral profiles, with per-file decimation where needed. If the corpus contains more usable files than the cap, the script stops with an explanation. A file is still loaded in memory during its analysis, so huge individual recordings can require substantial RAM. Lower the corpus size or change the cap in Advanced as appropriate.
Why is a metric shown as n/a?
Some metrics are mathematically uninformative for a nearly static spectral trajectory or for inadequate active material. In v1.5.1 the engine exports validity flags rather than using -1 to stand for a missing measurement.
Python did not complete, but an output WAV exists.
Praat requires both a WAV and the explicit done.ok marker produced after successful processing. A partial WAV does not count as success. If generation fails, the script reports information from the engine's stats and Python log.
Where are the generated files?
The finished stereo Sound is imported into Praat's Objects list. Intermediate WAV and CSV files are created in a temporary directory and normally removed after import and optional visualization. Save or export the Sound from Praat if you want to retain the audio as a file.