Audio Syncing Plugin

Simple Audio Syncing

Hello, Developer Forum! This is my first community resource, and I believe it is my first full post at all.

I recently had to synchronize some stuff to music in my game, and I realized how difficult it was to time ordinarily, especially because stuff happened throughout the song. So, I made a plugin to speed up the process a lot.

It is a fairly simple plugin, I made it in about four hours definitely didn’t spend several weeks procrastinating and I think it works well for what it is.

So.. What is it?

If you hadn't guessed already, this plugin is made to ease the process of syncing code to audio cues. Whether that be during beats in music or different parts of sound effects, this will most certainly make it easier. I couldn't find any (working) plugins that already did this, so I decided to do it myself.

How do I use it?

First, you must install it. Thats a given, look towards the bottom of the post for that.

Second, open the widget. Hopefully nobody has gotten lost yet… Very complex steps so far :fearful:

gif1

Yes, this was necessary. No, you cannot ask why

Next, find whatever audio you desire to do the timing on. Make sure you and whatever place you are in has access to it, otherwise it won’t work!
Get the ID and paste it into the box, and press enter to finalize it.

gif1

So far, if everything has been done correctly, you should see the time section update. If it doesn’t work, please try to restart the plugin. If you installed it from the plugin page rather than as a local file, you may have to leave and re-enter that game in studio.

Next press play, and mark your beats on the audio. You can use the progress bar in the middle to skip around if you need to.

gif2

After you’ve done that, click on the place you want the script with the timings to come out, and it’ll save there. If you select nothing, it’ll default to server storage.

gif3

Now, you may ask…

Okay but.. How do I use the module?

Well, open the module up, you’ll see that it consists of several things.

local module = {}
local savedBeats = {}

function module.GetBeats()
	return savedBeats
end

function module.BeatPassed(sound : Sound, beat : number)
	return (sound.TimePosition >= beat)
end

savedBeats = {["1"] = 1.6176, ["2"] = 2.5665, ["3"] = 3.5178, ["4"] = 4.4187, ["5"] = 9.8603, ["6"] = 12.0942, ["7"] = 13.2767, ["8"] = 7.4141, ["9"] = 8.3802} --Shortened for the sake of legibility

return module

These all serve a purpose.
This doesn’t come with a way to automatically do EVERY single bit of timing for you – but it does come with a way to make it easier.
For a script to get the beats, you simply require it and run module.GetBeats()
I figured this was the best way because it fit the most use cases.
You can see if a beat has passed fast with the function BeatPassed, and while its somewhat unnecessary, I think it is useful.
The saved beats are set by the plugin on the painfully obvious line.

To use this module though, you have to write a bit of your own code.
I wrote a little example for you all.

local timingModule = require(game.ServerStorage.SoundTimingModule) --Require the module that has the beats and functions
local queuedBeats = timingModule.GetBeats() --Just queue every single beat for detection
local runservice = game:GetService("RunService")
local sound = game.Workspace.Sound
local connection = nil --Will be used to disconnect the connection after every beat has been run
connection = runservice.Heartbeat:Connect(function() --Run every single PreRender, this is a bit excessive and could definitely be lowered in frequency for many scripts.
	for i,v in pairs(queuedBeats) do
		if timingModule.BeatPassed(sound, tonumber(i)) then --Check if the beat has passed
			queuedBeats[i] = nil --Prevent it from firing several times
			print("Blahblahblahblahblahblah...") --Do whatever you want the beat to do at this point
		end
	end
	if (next(queuedBeats) == nil) then --It is a dictionary, so this sees if it is empty
		print("Disconnected")
		connection:Disconnect() --Prevent further PreRenders from being connected to
	end
end)

Comments explain most of it, but this is an example of how you’d use the module to time it.
gif4
That’s the output of the given script.

That's great! How do I install it?

There are two safe ways you can. You can either get it from the roblox marketplace or install it from the rbxl file directly.

You can get it here: https://create.roblox.com/dashboard/creations/store/92610924548518/configure

Or you can use the file
Script.rbxm (75.9 KB)

You may not monetize off this plugin directly. If you wish to use my code for your own plugin, please ask me for permission first. You may contact me anywhere.

Will you release more updates?

Most likely, yes. If you look in the rbxl you'll see an entirely unused UI, I am planning to add layers to it, so you can sync several different things to the same audio at once. I also plan to fix any bugs that are fixable within reason. Please do report them under this post if you find any major ones. I am already aware that sometimes the audio just doesn't load, and you need to restart the whole plugin.

End

Should make more plugins? I never plan to monetize them, I just don't know what else I could make. Also, do you find this plugin useful if you did use it?
  • Yes, make more
  • No, don’t make more
  • It is useful
  • I am not sure if it is useful
  • It isn’t useful
  • I didn’t use it, but I might in the future
  • I didn’t use it, and I probably won’t

0 voters

6 Likes

Fixed an issue where the beats already placed wouldn’t be deleted when you changed the audio, sorry about that!