How to get the BPM of a sound [CLOSED]

I’m currently working on a time-based game & want to have a clock ticking sound go with the beat of background music.

Is there any way to get the BPM of a sound, then set the PlaybackSpeed to match the BPM? Would i have to do this manually?

(This is my first topic, so if it is in the wrong category let me know.)

Have you considered checking the devforum for a topic like this first?
It’s a bad habit, and I sometimes succumb to it aswell, but I found a topic similar that was solved almost 4 years ago.

Wow you guys are fast! i will check out this post.

I have tried the answer to this post, but have no idea how to print the value of the BPM.

PS - If all else fails, i would like to match the Playbackspeed of my clock SFX to the background music. is there any way to preview 2 sounds at the same time, to make this easier?

local loudnessValues = {}
game:GetService("RunService").Heartbeat:Connect(function()
   local average = 0
   for _,v in ipairs(loudnessValues) do
        average = average + v
   end

   average = average / #loudnessValues
   local isBeat = sound.PlaybackLoudness >= average
   
    --visualizing code basted on isBeat etc.

    loudnessValues[#loudnessValues + 1] = sound.PlaybackLoudness
end)

The value of the BPM would be average I think. Try to print average later in the function, or make it a variable outside of the function and print it, after the function has ran.

p.s. sorry for not reading the second question, i dont know how to preview 2 sounds at the same time sorry

This keeps printing 0 for some reason. I put it at the end of the function, as leaving it after “end)” would mean its unknown. should i put “local average” out of the function, and leave the print out of the function aswell?

Nevermind. This still prints 0.

I have decided i will simply do it manually. Thank you for your help, vf49!

you can find the bpm by dividing the number of beats (length of loudnessValues table) by the length of the sound