Hi, so I’m using the new AudioAPI, and I’m trying to make a visual voice chat on the corner of the screen (see video).
My question is, how can I detect if the localplayer
can hear a specific sound and how loud it is so I can change the bars’ sizes?
Script if needed later on
local function GetMappedBins(BinCount: number) : {number}
local Bins: {number} = AudioAnalyzer:GetSpectrum()
if not Bins or #Bins == 0 then
local Empty: {number} = {}
for Index = 1, BinCount do
table.insert(Empty, 0)
end
return Empty
end
local Result: {number} = {}
for Index: number = 1, BinCount do
local BinPosition: number = math.pow(#Bins, Index / BinCount)
local Lower: number = math.max(1, math.floor(BinPosition))
local Upper: number = math.min(#Bins, math.ceil(BinPosition))
local Fraction: number = BinPosition - math.floor(BinPosition)
Result[Index] = Lerp(Bins[Lower], Bins[Upper], Fraction)
Result[Index] = math.sqrt(Result[Index]) * 2
Result[Index] = math.clamp(Result[Index], 0, 10)
end
return Result
end
local VisualiserSquence = Setup()
AudioPlayer:Play()
while task.wait() do
local Bins = GetMappedBins(#VisualiserSquence+8)
for Index: number, Bar: Frame in pairs(VisualiserSquence) do
local Bin = Bins[#Bins - Index + 1]
Bar.Size = UDim2.new(0,3,Bin*5,0)
end
end