setPlaybackRate
setPlaybackRate(id: string, rate: number, skipDispatchEvent?: boolean): void;
Set the playback speed of a sound. A rate of 1 is normal speed; 0.5 is half speed; 2 is double speed. Pitch changes along with the rate (Web Audio API behaviour).
| Parameter | Type | Description |
|---|---|---|
id | string | ID of the sound |
rate | number | Playback speed multiplier (e.g. 0.5, 1, 2) |
skipDispatchEvent | boolean (optional) | When true, skips dispatching the rate change event |
tip
You can also set the initial rate at play time via PlayOptions.playbackRate.
Example
await soundManager.loadSounds([{ id: 'intro', url: 'intro.mp3' }]);
soundManager.play('intro');
// Half speed
soundManager.setPlaybackRate('intro', 0.5);
// Double speed
soundManager.setPlaybackRate('intro', 2);
// Back to normal
soundManager.setPlaybackRate('intro', 1);
⚡ Playback Rate1× (normal)
0.25×1× (normal)2×
Try it: Play the intro speech and drag the slider to hear the rate change in real time. Note that pitch shifts along with speed — this is native Web Audio API behaviour.