LoudFilter
LoudFilter is the perfect solution for detecting the average loudness of a sound on the server. It is especially useful for filtering out audio that is too loud.
Use case
If you have ever played a game that gives the player some sort of ability to play songs, then you have probably experienced extremely loud audio. This is something that can be difficult to moderate automatically, especially since you are unable to detect how loud a sound is purely on the server.
Thanks to this module you are able to detect the average loudness of a sound meaning you are able to stop it from being played in the first place.
Method
Since we are unable to check PlaybackLoudness
on the server, we instead send the sound to every player in the server and let them report the loudness. This might seem like a bad idea, but since we are only returning the median an exploiter can only have minimal effect on the result.
Docs
LoudFilter.New
Creates a new loudness state with the specified parameters
@param audioId {Number} The id of the audio to scan
@param duration {Number} How long to scan the audio for
@param amount {Number} How many instances to scan
@returns {LoudFilter} The loud filter state
LoudFilter:GetLoudness
Gets the loudness of the previously defined sound
@param volumeBound {Number} Any number higher than this is ignored
@returns {Number} The average loudness of the sound
Example
local LoudFilter = require("LoudFilter")
local id = 0000
local start = tick()
local duration = 2
local amount = 2
local bounds = 1000
local filterState = LoudFilter.New(id, duration, amount)
local loudness = filterState:GetLoudness(bounds)
print("Average loudness:", loudness)
print("Time taken:", tick() - start)
print("Duration:", duration)
print("Amount:", amount)
if (loudness > 800) then
-- Do something
end
Credit
Thanks to Dummiez for their audio scrubbing method - How can I get a song's max playback loudness? - #22 by Dummiez
Feedback
If you have a better method for detecting the average loudness, or a general suggestion on something in the module code feel free to contact me on DevForum.