AudioMarker | Module for adding events to specific Audio timestamps

AudioMarker

AudioMarker is a lightweight module that allows you to attach events to be
fired at specific timestamps in a Sounds playback
https://create.roblox.com/store/asset/125036103366628/AudioMarker


Functions

Constructor
local Cue = AudioMarker.new(Sound)

New Audio Cue
--Cue:AddCue(TimeStamp, Callback function)

Cue:AddCue(2, function()
    print("Cue fired")
end)

Initialization
Cue:Start()

-- starts listening for when cue timestamps are reached
-- and then fires the callback event

Termination / Stop listening
Cue:Stop()

-- Stops listening for when cue timestamps are reached
-- Automatically fires if the Sound instance is destroyed

Usage

Code example
local AudioMarker = require(path.to.module)
local Sound = Instance.new("Sound", workspace)
Sound.SoundId = "rbxassetid://0"

local Cue = AudioMarker.new(Sound)

Cue:AddCue(2, function()
    print("1st Cue reached")
    --do something
end)

Cue:AddCue(5, function()
    print("wow 2nd Cue reached")
end)

Cue:Start()

Sound.Ended:Connect(function()
    -- either just delete the sound
    -- or stop the cues
    -- deleting auto-stops cues

    Cues:Stop()
end)

I made this module in about 30 minutes so its not the best, but if i see the module had enough interest, i might add things like custom named cues and mass adding cues with the :AddCue function

5 Likes