Create desired Sound length using PlaybackSpeed

Hello, I’m trying to change a Sound’s length without cutting of the Sound. My goal is to be able to have a number of seconds in mind that I want the Sound to play for and I’d like to make a script that can find out the Playback Speed based on how long I want the Sound to play for. Any help is appreciated, thanks!

Divide the audio length by how long you want it to play for. That will give you the playback speed.

2 Likes

soundLength / desiredLength = speed?

2 Likes

You can first get the length of the current playing sound from sound.TimeLength, which returns a number in seconds.
After that, you can set the playback speed as:

local timeLength = sound.TimeLength
local targetLength = nil -- your desired length in seconds
local targetSpeed = timeLength / targetLength
-- ex. if your sound is 60s and your target is 50, then this value would be 1.2 - the new playback speed.

sound.PlaybackSpeed = targetSpeed

Remeber, sound must be loaded first.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.