Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Minis Sound Script
- -- https://developer.roblox.com/en-us/api-reference/class/Sound
- -- AddSound
- function AddSound(ID,Name,WhereToAdd)
- local NewSound = Instance.new("Sound",WhereToAdd)
- NewSound.SoundId = ID
- NewSound.Name = Name
- end
- -- Play
- function Play(Sound)
- Sound:Play()
- end
- -- Stop
- function Stop(Sound)
- Sound:Stop()
- end
- -- Resume
- function Resume(Sound)
- Sound:Resume()
- end
- -- Pause
- function Pause(Sound)
- Sound:Pause()
- end
- -- GetNumbSoundId
- function GetNumbSoundId(SoundId)
- local Split = string.split(SoundId,"/")
- local NumbId = tonumber(Split[3])
- return NumbId
- end
- -- GetSoundName
- function GetSoundName(SoundId)
- local MS = game:GetService("MarketplaceService")
- local NumbId = GetNumbSoundId(SoundId)
- local Asset = MS:GetProductInfo(NumbId)
- return Asset.Name
- end
- -- GetSoundStats (Loudness Is Based Off Scripts Position)
- function GetSoundStats(Sound)
- -- Log Properties That Will Be Changed
- local BPlaying = Sound.Playing
- local BTimePos = Sound.TimePosition
- local BMaxD = Sound.MaxDistance
- local BLooped = Sound.Looped
- local BEmitterSize = Sound.EmitterSize
- -- PrepForQuickPlay
- Sound.Playing = false
- Sound.TimePosition = 0
- Sound.Volume = 0
- Sound.PlaybackSpeed = 1
- Sound.EmitterSize = 99999
- Sound.Looped = false
- -- Running Test
- Sound.Playing = true
- local LoundessLog = {}
- local SampleCount = 0
- while Sound.Playing == true do
- SampleCount = SampleCount + 1
- table.insert(LoundessLog,1,Sound.PlaybackLoudness)
- wait(1/200)
- end
- -- GetAverageLoudness and HighestLoudness
- local AcumulatedLoudness = 0
- local HighestLoudness = 0
- for i = 1,#LoundessLog do
- AcumulatedLoudness = AcumulatedLoudness + LoundessLog[i]
- if LoundessLog[i] > HighestLoudness then
- HighestLoudness = LoundessLog[i]
- end
- end
- -- Data
- local SoundId = Sound.SoundId
- local Name = GetSoundName(Sound.SoundId) --
- local HighestLoudness = HighestLoudness --
- local AverageLoudness = AcumulatedLoudness / SampleCount --
- local Duration = Sound.TimeLength --
- local Data = {SoundId,Name,Duration,AverageLoudness,HighestLoudness}
- end
- -- SaveSoundData
- function SaveSoundData(Data)
- local DataStoreService = game:GetService("DataStoreService")
- local NewStore = DataStoreService:GetDataStore("Minimic2002SoundData")
- -- Makes It Into 1 String As You Cant Save Arrays
- local NewData = ""
- for i = 1,#Data do
- NewData = NewData .. ";" .. tostring(Data[i])
- end
- NewStore:SetAsync("Sound " ..Data[1],NewData) -- Sets All the Data To SoundId
- end
- -- GetSoundData
- function GetSoundData(SoundId)
- local DataStoreService = game:GetService("DataStoreService")
- local NewStore = DataStoreService:GetDataStore("Minimic2002SoundData")
- local Result = NewStore:GetAsync("Sound " ..SoundId)
- -- Turn Data Back Into An Array
- local Split = string.split(Result,";")
- local Data = {}
- for i = 1,#Split do
- local ToN = tonumber(Split[i])
- if ToN == nil then
- table.insert(Data,Split[i])
- else
- table.insert(Data,ToN)
- end
- end
- return Data
- end
- -- SoundData
- function SoundData(Sound)
- local SoundId = Sound.SoundId
- -- AttemptToGetData
- local SoundData = GetSoundData(SoundId)
- if SoundData == nil then
- -- Log Sound As There Is No Data On It
- local Clone = Sound:Clone() -- Clone It So Original Uneffected
- Clone.Parent = Sound.Parent -- Play From Same Location
- local SoundStats = GetSoundStats(Sound)
- SaveSoundData(SoundStats) -- Saves Data From Stats
- else
- return SoundData -- Found Data And Is Returning It
- end
- end
- -- PlaylistFunctions
- -- AddToPlaylist()
- function AddToPlaylist(Playlist,SoundId)
- local DataStoreService = game:GetService("DataStoreService")
- local NewStore = DataStoreService:GetDataStore("Minimic2002PlaylistData")
- local Result = NewStore:GetAsync("Playlist " ..Playlist)
- if Result == nil then -- Nothing There Yet
- -- Starts A New Store For That Playlist
- NewStore:SetAsync("Playlist " ..Playlist,SoundId)
- else
- -- Add Onto String
- local PlaylistData = Result .. ";" .. SoundId
- NewStore:SetAsync("Playlist " ..Playlist,PlaylistData)
- end
- end
- -- GetPlaylistData
- function GetPlaylistData(Playlist)
- local DataStoreService = game:GetService("DataStoreService")
- local NewStore = DataStoreService:GetDataStore("Minimic2002PlaylistData")
- local Result = NewStore:GetAsync("Playlist " ..Playlist)
- local Split = string.split(Result,";")
- local NewPlaylistData = {}
- for i = 1,#Split do
- table.insert(NewPlaylistData,Split[i])
- end
- return NewPlaylistData
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement