Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Answers to an Audio Question?

Asked by 10 years ago

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?

0
I can create a web API to do this, but I'm not sure it's possible with RBX.Lua Link43758 175 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago

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.

Ad

Answer this question