Hello. I’m facing a problem where RmsLevel is returning 0! And since I’ve never used this function, I don’t know what to do D:
LocalScript:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
local audioInput = Instance.new("AudioDeviceInput")
audioInput.Parent = player:WaitForChild("PlayerGui")
local audioAnalyzer = Instance.new("AudioAnalyzer")
audioAnalyzer.Parent = player:WaitForChild("PlayerGui")
local wire = Instance.new("Wire")
wire.SourceInstance = audioInput
wire.TargetInstance = audioAnalyzer
wire.Parent = player:WaitForChild("PlayerGui")
local function printRMS()
local rmsValue = audioAnalyzer.RmsLevel
print("(RMS):", rmsValue)
end
RunService.RenderStepped:Connect(printRMS)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Get the local player
local player = Players.LocalPlayer
-- Create an AudioDeviceInput instance and parent it to the PlayerGui
local audioInput = Instance.new("AudioDeviceInput")
audioInput.Parent = player:WaitForChild("PlayerGui")
-- Create an AudioAnalyzer instance and parent it to the PlayerGui
local audioAnalyzer = Instance.new("AudioAnalyzer")
audioAnalyzer.Parent = player:WaitForChild("PlayerGui")
-- Create a Wire instance to connect AudioDeviceInput to AudioAnalyzer
local wire = Instance.new("Wire")
wire.SourceInstance = audioInput
wire.TargetInstance = audioAnalyzer
wire.Parent = player:WaitForChild("PlayerGui")
-- Check RmsLevel in a debug function
local function printRMS()
local rmsValue = audioAnalyzer.RmsLevel
print("(RMS):", rmsValue)
end
-- Debug to check if audioAnalyzer.RmsLevel is being properly updated
local function debugRmsLevel()
while true do
wait(1) -- Adjust the interval as needed
printRMS()
end
end
-- Run the debug function
debugRmsLevel()
Are you sure you enabled the audioAPI? This is from the AudioAPI release post:
To control voice with the beta Audio API, you’ll need to specifically enable it by navigating to Model > Advanced > Service, and inserting the VoiceChatService.
Make sure the audioAPI is enabled by checking if the UseAudioApi property in the VoiceChatService is set to Enabled.
After doing so, your code would look like this:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local player = Players.LocalPlayer
--new property added to the localplayer when enabling API, which is needed
local audioInput = player.AudioDeviceInput
local wire = Instance.new("Wire")
local AudioAnalyzer = Instance.new("AudioAnalyzer")
wire.SourceInstance = audioInput
wire.TargetInstance = AudioAnalyzer
wire.Parent = AudioAnalyzer
AudioAnalyzer.Parent = audioInput
local function printRMS()
--check if the wire actually connected to the audioinput
if wire.Connected then
local rmsValue = AudioAnalyzer.RmsLevel
local peakValue = AudioAnalyzer.PeakLevel
print("(RMS):", rmsValue)
print("(PEAK):", peakValue)
end
end
RunService.RenderStepped:Connect(printRMS)
Also, note that you should set the correct permissions for users to access the microphone in the game. (should be in game settings)