I have this issue regularly where the OSX audio stopped working on my Macbook. I am using High Sierra right now, but had the same problem with Sierra. Not sure what is causing the problem, and not sure how to prevent it from happening. I have figured out though how to solve it, and as occasionally I find myself searching for the solution I figured I would quickly document it on my own blog. If your audio has stopped working you can simply stop the service responsible for it.
For me the following works solving the problem:
sudo killall coreaudiod
For me audio comes back again automatically almost instantly, some actually have reported they need to start the service again
sudo launchctl start com.apple.audio.coreaudiod
I hope this helps others as well running in to the same problem. If you have and you solved the problem in a different way please leave a comment.