Adding voice filters to a player

Hello devs!

Hope this isn’t asking for too much but I am wondering how I would add voice effects/filters like the AudioPitchShifter using the new Audio API. I setup the character like below (localscript)

local players = game:GetService("Players")

local function connect(src: Instance, dst: Instance)
	local wire = Instance.new("Wire", dst)
	wire.SourceInstance = src
	wire.TargetInstance = dst
end

local function onCharacterSpawned(from: Player, character: Model)
	local emitter = Instance.new("AudioEmitter", character)
	emitter.AudioInteractionGroup = "Player"
	emitter.Name = "Emittah"
	connect(from.MicrophoneInput, emitter)
	
	
	local listener = Instance.new("AudioListener", character)
	listener.AudioInteractionGroup = "Player"
	local deviceOutput = Instance.new("AudioDeviceOutput", listener)
	connect(listener, deviceOutput)
	
	
	local analyzer = Instance.new("AudioAnalyzer", character)
	connect(from.MicrophoneInput, analyzer)
	

end

local function onPlayerAdded(player: Player)
	local input = Instance.new("AudioDeviceInput", player)
	input.Name = "MicrophoneInput"
	
	
	if player.Character then
		onCharacterSpawned(player, player.Character)
	end
	player.CharacterAdded:Connect(function()
		onCharacterSpawned(player, player.Character)
	end)
end

players.PlayerAdded:Connect(onPlayerAdded)
for _, player in players:GetPlayers() do
	onPlayerAdded(player)
end

Hopefully this isn’t asking for too much! Thank you.

1 Like

At a quick glance your code seems to be structured correctly. One thing that seems to be missing though is that the AudioDeviceInput does not have its Player property set to the player it’s linked to.

To add voice filters you would probably want to add your AudioPitchShifter in between the player’s input device and the audio emitter. Right now you connect the audio stream from the AudioDeviceInput directly to an AudioEmitter inside their character. If I understand the API correctly you should instead instantiate a AudioPitchShifter and wire the input device to the pitch shifter & wire the pitch shifter to the AudioEmitter inside the character. From my understanding that should modify the audio stream from the player’s microphone before it’s being broadcast from their character model.

Also I’m not sure about how replication works with the new audio APIs, but generally it would be best to use a server script for this rather than a LocalScript. Voice chat runs through Roblox’s voice servers after all so even if a LocalScript happens to work (which I assume it won’t), it would be more proper to set up your instances inside a server script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.