Exactly which Mac, year and model, are you using?
What version macOS are you running?
Find that info by clicking the (Apple) menu at the top-left of your screen and then select About This Mac.
(Note- for privacy and security please don’t post your serial number.)
Meanwhile have you given a Safe Boot a try? See if the problem still happens in Safe mode (press and hold the shift key down at startup). It can take much longer to safe boot (10 min) so be patient.
How to use safe mode on your Mac - Apple Support
Safe mode is non-destructive to user data. It’s not a cure-all, but very often corrects weird software behavior. When you're in safe boot, the machine will not be at its best performance, especially with graphics, but that's expected.
Does the problem persist while in Safe mode?
Exit safe mode by restarting your Mac normally and re-evaluate the issue again.
Also, in System Information (Option-click the Apple logo and select System Information), select Audio in the left panel under Hardware and tell us what is reported for Built-in Input and Built-in Output. There should be an Apple device listed for each.