At some point, almost everyone has been awakened in the middle of the night by a stranger in bed.

Sure, the body looks familiar — why, that’s your boyfriend Mark, isn’t it? — but what’s coming out of his mouth?

“Have you checked the lightsaber battery?” Mark says. "Something-something ... yes, that will be fine. Can I get a side of purple haze with that?"

Other times, the noise that emanates from that side of the bed is just a series of beeps, as if the man you know so well by day moonlights as an alien communications beacon.

Maybe it's some kind of communication. Or guilt that creeps out when consciousness can’t keep it in check.

"What’s her name, Mark?" you might say.

But you might as well be sleeping with the sphinx. Mark is a mystery wrapped in gibberish.

What's happening here?

The truth is, scientists can’t fully account for sleep talking, or, as they like to call it, somniloquy. What they do know is that it’s technically not supposed to happen. Somewhere inside the marvelously elaborate machine that is the human body, there’s been a malfunction.

Basically, the brain forgets to unplug the voluntary muscles to the body for the night. You see, when we dream, neurons fire in the brain and bark out orders to the body, much as if we were awake. The difference is that our voluntary muscles get shut down sometime around the onset of REM sleep. We’re effectively paralyzed — an important safeguard against us acting out our dreams.

But when the voluntary muscles are not shut down, a body is only partly paralyzed. The result? Twitching, walking and talking. (Not to worry. It isn’t likely a system-wide failure.)

People who talk a lot in their sleep don’t seem to descend into madness any more rapidly than the rest of us. In fact, the most extensive sleep talker ever recorded was the successful songwriter Dion McGregor. Even McGregor’s nocturnal ramblings seemed to be touched by genius. His roommate made more than 500 recordings, ultimately releasing them as an album entitled, "The Dream World of Dion McGregor (He Talks in His Sleep)."

Did any of it make sense? Well, in keeping with the somniloquist’s code, not really. One critic described McGregor’s music “as if he were channeling Truman Capote on acid: flirtatious, slushy, disconnected from reality ... ”

The key takeaway here is disconnected from reality. A sleep talker may be speaking in the voice of a character in a dream, crossing gender and even species lines.

illustrated dream sequence features ships and fish and animals When you talk in your sleep, you could be describing the weirdness going on in your dreams. (Photo: Helea/Shutterstock)

A few factors lead to sleep talking

Keep one thing in mind: There's a good chance that you experience similar technical difficulties on occasion. Men and children are most prone to somniloquy. Stress, depression, lack of sleep and excessive alcohol can be factors in sleep talking.

So judge not, late-night eavesdropper, lest you be judged. On some nights, you might be the one claiming to have a mistress named Yoda. Or you might be gurgling like a goldfish.

Luckily, confessions from people talking in their sleep — even if they blurt out the most obscene crimes — aren’t admissible in most courts. That’s because, as the National Sleep Foundation notes, it’s widely understood that “sleep talking is not a product of a conscious or rational mind.”

Indeed, while the organization points out that some sleep talking could involve events and experiences from a person’s life, it’s just as likely to be nocturnal nonsense. Sleep talking can be so divorced from consciousness, voices and style of speaking may be completely unrecognizable.

Which means we’ll just have to make peace with the occasional stranger in our bed. Even he keeps us up all night with that wretched barking.