Is it possible to force macOS to play audio only on the active app?
I just came across an answer that mentions an app called Sound Control ($19) that should do what you want, but I haven't tried it yet.