The Audio.setPlaybackRate()
method is a function in the Three.js library that allows you to adjust the playback speed of an audio object.
audio.setPlaybackRate(rate);
rate
- A number value that specifies the playback rate. The default value is 1.The Audio.setPlaybackRate()
function changes the playback speed of an audio object. The value of rate
parameter determines the speed of the audio, with a default value of 1. A rate
value of 2.0 would play the audio twice as fast as the original, while a value of 0.5 would play the audio at half the speed.
// create a new audio object
var audio = new THREE.Audio( listener );
// set the audio source
var audioLoader = new THREE.AudioLoader();
audioLoader.load( 'path/to/your/audio/file.mp3', function( buffer ) {
audio.setBuffer( buffer );
// set the playback rate to 0.5 (half the speed)
audio.setPlaybackRate(0.5);
audio.play();
});
In this example, we create a new audio object and set the audio source using THREE.AudioLoader()
. We then set the playback rate to 0.5 using Audio.setPlaybackRate()
before playing the audio.
setPlaybackRate()
method can be useful for slowing down or speeding up audio depending on the context of the scene being rendered.playbackRate
property.