My Mac is a MacBook M1Max, and I have encountered a sporadic problem in the past few months. The headphone volume is expected, but the built-in speaker volume is very low, and it is entirely inaudible. After restarting the Mac, it will be completely back to normal.
Later, I found that when encountering this problem, I can find the coreaudiod process in the CPU task list of the Activity Monitor, then double-click to get the detail page, select exit, and then select force exit.
Usually after this operation, the speaker volume will be normal.