I’ve been trying to use the Audio API to set up voice chat i can hook to and analyse for a game, but for some reason the AudioAnalyzer doesn’t work with my setup.
I copied the same code used in The Audio API Tutorial to create the AudioDeviceOutput, AudioDeviceInput and AudioListeners and managed to get a speaker working with the voice chat. However when I try and connect an AudioAnalyzer to the AudioListener listening to the mic, it doesn’t hear anything
I swapped out the AudioListener for a AudioPlayer on the same test asset the tutorial used, and it produced the spectrogram perfectly fine, but simply swapping it for the AudioListener breaks it.
How come my speaker works but my analyzer doesnt?
function SoundUtils.HookDefaultPlayerVoiceChat(Player: Player): AudioEmitter
-- Since we disabled the original voice chat, we need to attach it to their character
local Character = Player.Character or Player.CharacterAdded:Wait()
local AudioEmitter = Instance.new("AudioEmitter")
AudioEmitter.AudioInteractionGroup = "VoiceChat"
AudioEmitter.Parent = Character
local Wire = SoundUtils.Connect(Player.VoiceChatInput, AudioEmitter)
return AudioEmitter
end
function SoundUtils.PlayerAdded(Player: Player)
local AudioDeviceInput = Instance.new("AudioDeviceInput") -- Input for the player's mic
AudioDeviceInput.Player = Player
AudioDeviceInput.Name = "VoiceChatInput"
AudioDeviceInput.Parent = Player
SoundUtils.HookDefaultPlayerVoiceChat(Player)
SoundUtils.VisualiseWires(workspace)
Player.CharacterAdded:Connect(function()
SoundUtils.HookDefaultPlayerVoiceChat(Player)
end)
end
And the script for the camera’s listener:
local Player = game.Players.LocalPlayer
local Camera = workspace.CurrentCamera
local AudioListener = Instance.new("AudioListener")
AudioListener.Parent = Camera
local AudioDeviceOutput = Instance.new("AudioDeviceOutput")
AudioDeviceOutput.Parent = Camera
local Wire = Instance.new("Wire")
Wire.SourceInstance = AudioListener
Wire.TargetInstance = AudioDeviceOutput
Wire.Parent = AudioListener