I had this problem and fixed it by re-seating the connectors and readjusting the routing of the audio cable inside the machine. I'm certain this was the cause of the problem in my cause.
After I opened the Mac and moved the battery aside, I could see that the audio board is attached to the motherboard via a flat cable that's routed under the battery, with two serious right angle folds in it. I wiggled and re-seated the connectors and fiddled with the routing of the cable until the audio was consistently working. I tested with the Mac apart by powering the Mac on just long enough to get the screen lit, listening for the tone, and then powering it off by pressing and holding the power button. This took a few tries -- I'd screw down the audio board and test it, then screw down the battery and test it, then reattach the back and test it.
Eventually I'll get around to replacing the cable, as this sort of flakiness is definitely due to either a broken wire within the cable or a loose connector on the cable ends. While I was in there I also tightened the screws on the hinges, they were definitely loose and making my screen flop around like a newborn's head.
I removed the battery (nine screws) and the audio board on the left (two screws). The screws are different sizes so I saved myself future sorrow by laying them out on a piece of paper, map-like, as I removed them.
The bad boy. I pulled the cable away from the case and temporarily straightened it out, relaxing the bends in the folds and giving it a healing massage (candles, Enya). After I did this my audio came back to me.
For good measure I re-seated the connectors on the cable ends. I wasn't able to take the top connector all the way off because there's a plastic tab from the hard drive mounting above it. I wiggled the connector as much as I could, then I made sure it was firmly seated.
I flipped the audio board over and re-seated the connector there, too. Initially I thought the problem was with the audio board components touching the bare metal of the case, so I shoved a piece of iPod Shuffle packaging in there before I screwed it back down (how it got there will be a mystery to future generations).
I hope this helps.