Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Answers to an Audio Question?

How can you check the length of an audio piece, without having to listen for however long it is? Is there some sort of function that checks this?

1 comment

0

I can create a web API to do this, but I'm not sure it's possible with RBX.Lua

1 answer

✓ Accepted answer

Yes, I made a function that allows you to figure it out, however, it does take some time. The amount of time it takes to get a length depends on the getSpeed argument, however, when the getSpeed increases the length is less accurate. (Still pretty accurate,however.)

-- Created by Basscans
function getSoundLength(sound,getSpeed) -- The max for getSpeed is 9.519
	local restoredP,restoredV=sound.Pitch,sound.Volume
	sound.Pitch=getSpeed
	sound.Volume=0
	sound:Play()
	local timestamp=tick()
	repeat wait() until sound.IsPlaying==false
	sound:Stop()
	sound.Pitch=restoredP
	sound.Volume=restoredV
	return ((tick()-timestamp)*getSpeed)
end

Please set this as the correct answer and upvote my reputation if this helped/worked.

This discussion is preserved as it was. New answers, comments, and votes are closed.