How do Lock and Auto mute

I love the way my Mac rings when I get calls. What I don’t love (or rather my wife does not love) is when I am out of the house and I get phone calls and my Mac rings as well. Is there a way when I lock my Mac, that it can automatically mute? Then when I unlock it - it unmutes ? I think with focus you maybe could do it? But curious if anyone has solved this problem.

Thanks