I have the same issue and know a fix for this and possibly the reason.
The fix is to go into the system preferences -> Sound, then go to input and change the input source to something other than your headphones. (shortcut: option + any volume key)
I don't know how to fix this at an Xcode level, or if you only have one input device though.
Just for anyone who cares, the reason for the stuffy audio is that Xcode starts a phone call, and I suppose my headphones don't like to output clean sound with the mic taking inputs.
I know that Xcode is starting a call because my headphones have bluetooth multipoint, as well as giving me verbal feedback about whats going on with them.
When bluetooth multipoint is active my audio will switch cleanly between my iMac and Ipad pro, unless one of them is taking a phone call then the phone call will get priority.
When I get this muffled audio, my headphones won't switch to my Ipad to play audio, which suggests that a phone call is in progress.
What really says that a call is in progress, is that when I change the input source in system preferences away from my headphones, the audio clears up but my headphones also say "call ended".
All this means that Xcode must be starting a phone call for some reason, and my headphones don't like that.
Why my iMac speakers are happy to play music while "taking a phone call" but my headphones aren't may mean that it isn't a macOS issue but a limitation with the headphones, but this is just guess work.