What you can do is:
1. calculate difference in X between player and target event (in the below example, event number 5)
2. calculate difference in Y between player and target event
3. Pythagoras to get a distance value in a straight line, multiply by some factor (in the below example, 10)
4. calculate the volume of the sound; basically just "100 minus calculated distance value", with a conditional to return 0 if the calculation is below 0.
5. play the sound
Some parts of this you can do with event commands, but I prefer to just put the whole thing in a script. This will need to be a parallel event so you may want to put in a wait of 5 frames or more.
JavaScript:
◆Wait:5 frames
◆Script:const Dist5X = Math.abs($gamePlayer.x - $gameMap.event(5).x);
: :const Dist5Y = Math.abs($gamePlayer.y - $gameMap.event(5).y);
: :const Dist = Math.round(10*Math.sqrt(Dist5X ** 2 + Dist5Y ** 2));
: :const BgsVol = (100-Dist <= 0 ? 0 : 100-Dist)
: :AudioManager.playBgs({name:'HeavyBreathing', volume: BgsVol, pitch:100});