Detecting Player Voice Chat Volume

INTRODUCTION

Hey everyone! In this tutorial im gonna be showing you how you can access the player’s voice chat volume permitting you to make the player do actions like jump and etc.

STEP 1 : Enabling Voice Chat

  1. To enable voice chat you must open Game Settings which you can find in Home.
  2. Click on Communication.
  3. Enable Enable Microphone.
    imageimageimage

STEP 2 : VoiceChatService

If you dont have VoiceChatService in your explorer you can get it by following these steps :

  1. Go to Home and then Service.
  2. Select VoiceChatService.
  3. Click Insert.
    imageimageimage

STEP 3 : Enabling UseAudioApi

In order to access the Player’s microphone we have to use roblox’s Audio API here

  1. Select the VoiceChatService that we just inserted into the explorer.
  2. In the Properties make sure EnableDefaultVoice and UseAudioApi are both enabled.
    image

STEP 4 : AudioAnalyzers

Almost Done!

  1. Create a folder in ReplicatedStorage and name it Analyzers.
  2. Create a Script in ServerScriptService.
game.Players.PlayerAdded:Connect(function(player)
	local audiodeviceinput = player:WaitForChild("AudioDeviceInput")
	local Analyzer = Instance.new("AudioAnalyzer")
	Analyzer.Name = player.Name.."'s Analyzer"
	Analyzer.Parent = game.ReplicatedStorage.Analyzers
	local Wire = Instance.new("Wire")
	Wire.Parent = Analyzer
	Wire.SourceInstance = audiodeviceinput
	Wire.TargetInstance = Analyzer
end)

This script will create an AudioAnalyzer for every player that joins which will take measurements by wiring it to the player’s AudioDeviceInput that we got by enabling the UseAudioApi.

Making a Speak to Jump System :

Step 1 :

To avoid players from jumping manually you should create a localscript and unbind the Jump Action.

local ContextService = game:GetService("ContextActionService")
ContextService:UnbindAction("jumpAction")

Step 2 :

Make a Localscript for example in StarterPlayerScripts which will handle the Jumping when a player speaks.

NOTE : THIS IS JUST AN EXAMPLE

local Player = game.Players.LocalPlayer
local Analyzer = game.ReplicatedStorage.Analyzers:WaitForChild(Player.Name.."'s Analyzer")
local Debounce = false
while task.wait(0.1) do
	local PeakLevel = math.floor(Analyzer.PeakLevel * 100)
	if PeakLevel >= 40 then -- feel free to change this to what you think suits you the most
		if Debounce == true then continue end
		Debounce = true
		local char = Player.Character or Player.CharacterAdded:Wait()
		local Humanoid = char:WaitForChild("Humanoid")
		if Humanoid.Health <= 0 then continue end
		if Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
			Humanoid.JumpHeight = PeakLevel / 7 -- feel free to change this to what you think suits you the most
			Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		end
		task.wait(1)
		Debounce = false
	end
end

In this example we’re gonna be using the PeakLevel Property of the AudioAnalyzer you can use the RmsLevel Aswell.
there is a statement to check if the PeakLevel is greater or equal to 40 just to avoid any low sounds caused by the user you can change that number to what you think suits you the most.

Conclusion

I hope that you enjoyed reading this tutorial and found it both beneficial and helpful.

12 Likes