Control audio playback speed programmatically using CE.SDK’s headless engine for server-side audio processing, from quarter-speed (0.25x) to triple-speed (3.0x).
Playback speed adjustment changes how fast or slow audio plays without changing its pitch (though pitch shifting may occur depending on the audio processing implementation). A speed multiplier of 1.0 represents normal speed, values below 1.0 slow down playback, and values above 1.0 speed it up. This technique is commonly used for podcast speed controls, time-compressed narration, slow-motion audio effects, and accessibility features.
This guide covers how to adjust audio playback speed programmatically using the Engine API, understand speed constraints, and manage how speed changes affect timeline duration.
Understanding Speed Concepts#
CE.SDK supports playback speeds from 0.25x (quarter speed) to 3.0x (triple speed), with 1.0x as the default normal speed. Values below 1.0 slow down playback, values above 1.0 speed it up.
Speed and Duration: Adjusting speed automatically changes the block’s timeline duration following an inverse relationship: perceived_duration = original_duration / speed_multiplier. A 10-second clip at 2.0x speed plays in 5 seconds; at 0.5x speed it takes 20 seconds. This automatic adjustment maintains timeline synchronization when coordinating audio with other elements.
Common use cases: Podcast playback controls (1.5x-2.0x), accessibility features (0.75x for easier comprehension), time-compressed narration, dramatic slow-motion effects (0.25x-0.5x), transcription work, and music tempo adjustments.
Setting Up the Engine#
For headless audio processing, initialize CE.SDK’s Node.js engine. This provides full API access without browser dependencies, ideal for server-side automation and batch processing.
const engine = await CreativeEngine.init({});Setting Up Audio for Speed Adjustment#
Loading Audio Files#
We create an audio block and load an audio file by setting its fileURI property.
// Create an audio block and load the audio fileconst audioBlock = engine.block.create('audio');engine.block.setString(audioBlock, 'audio/fileURI', audioUri);
// Wait for audio resource to loadawait engine.block.forceLoadAVResource(audioBlock);Unlike video or image blocks which use fills, audio blocks store the file URI directly on the block itself using the audio/fileURI property. The forceLoadAVResource call ensures CE.SDK has downloaded the audio file and loaded its metadata, which is essential for accurate duration information and playback speed control.
Adjusting Playback Speed#
Setting Normal Speed#
By default, audio plays at normal speed (1.0x). We can explicitly set this to ensure consistent baseline behavior.
// Normal Speed Audio (1.0x - original playback rate)const normalAudioBlock = engine.block.duplicate(audioBlock);engine.block.appendChild(page, normalAudioBlock);engine.block.setTimeOffset(normalAudioBlock, 5);engine.block.setPlaybackSpeed(normalAudioBlock, 1.0);
// Query current speed to verify the changeconst currentSpeed = engine.block.getPlaybackSpeed(normalAudioBlock);console.log(`Normal speed block set to: ${currentSpeed}x`);Setting speed to 1.0 ensures the audio plays at its original recorded rate. This is useful after experimenting with different speeds and wanting to return to normal, or when initializing audio blocks programmatically to ensure consistent starting states.
Common Speed Presets#
Slow Motion Audio (0.5x)#
Slowing audio to half speed creates a slow-motion effect that’s useful for careful listening or transcription.
// Slow Motion Audio (0.5x - half speed, doubles duration)const slowAudioBlock = engine.block.duplicate(audioBlock);engine.block.appendChild(page, slowAudioBlock);engine.block.setTimeOffset(slowAudioBlock, 0);engine.block.setPlaybackSpeed(slowAudioBlock, 0.5);At 0.5x speed, a 10-second audio clip will take 20 seconds to play. This slower pace makes it easier to catch details, transcribe speech accurately, or create dramatic slow-motion audio effects in creative projects.
Maximum Speed (3.0x)#
The maximum supported speed is 3.0x, three times normal playback rate.
// Maximum Speed Audio (3.0x - triple speed, reduces duration to 1/3)const maxSpeedAudioBlock = engine.block.duplicate(audioBlock);engine.block.appendChild(page, maxSpeedAudioBlock);engine.block.setTimeOffset(maxSpeedAudioBlock, 10);engine.block.setPlaybackSpeed(maxSpeedAudioBlock, 3.0);At maximum speed, audio plays very quickly—a 10-second clip finishes in just 3.33 seconds. This extreme speed is useful for rapidly skimming through content to find specific moments, though comprehension becomes challenging at this rate.
Speed and Timeline Duration#
Understanding Duration Changes#
When we change playback speed, CE.SDK automatically adjusts the block’s timeline duration to reflect the new playback time.
// Log duration changes to demonstrate speed-duration relationshipconst slowDuration = engine.block.getDuration(slowAudioBlock);const normalDuration = engine.block.getDuration(normalAudioBlock);const maxDuration = engine.block.getDuration(maxSpeedAudioBlock);
console.log(`Slow motion (0.5x) duration: ${slowDuration.toFixed(2)}s`);console.log(`Normal speed (1.0x) duration: ${normalDuration.toFixed(2)}s`);console.log(`Maximum speed (3.0x) duration: ${maxDuration.toFixed(2)}s`);The original duration represents how long the audio takes to play at normal speed. When we double the speed to 2.0x, the duration is automatically halved. The audio content is the same, but it plays through in half the time, so the timeline block shrinks accordingly.
This automatic adjustment keeps your timeline synchronized. If you have multiple audio tracks or need to coordinate audio with video, the timeline will accurately reflect the new playback duration after speed changes.
Exporting Results#
After adjusting audio speeds, export the scene to preserve your work. The engine.scene.saveToString() method serializes the entire scene, including all audio blocks with their speed settings.
// Export the scene to a .scene fileconst sceneContent = await engine.scene.saveToString();await mkdir('output', { recursive: true });await writeFile('output/audio-speed-adjustment.scene', sceneContent);console.log('Scene exported to output/audio-speed-adjustment.scene');The exported .scene file can be loaded later for further editing or used as a template for batch processing workflows.
API Reference#
| Method | Description | Parameters | Returns |
|---|---|---|---|
engine.block.create(type) | Creates a new design block of the specified type | type: DesignBlockType | DesignBlockId |
engine.block.setString(id, property, value) | Sets a string property on a block | id: DesignBlockId, property: string, value: string | void |
engine.block.forceLoadAVResource(id) | Forces loading of audio/video resource metadata | id: DesignBlockId | Promise<void> |
engine.block.setPlaybackSpeed(id, speed) | Sets the playback speed multiplier. Valid range is [0.25, 3.0] for audio blocks. Also adjusts trim and duration | id: DesignBlockId, speed: number | void |
engine.block.getPlaybackSpeed(id) | Gets the current playback speed multiplier | id: DesignBlockId | number |
engine.block.getDuration(id) | Gets the playback duration of a block in seconds | id: DesignBlockId | number |
engine.scene.saveToString() | Serializes the current scene into a string | allowedResourceSchemes?: string[] | Promise<string> |