I find that if you heartily agree with everything they say, they usually shut up.
Say stuff like, "Oh yeah, I know what you mean." or "Oh, I feel the same way." And smile the whole time. It gives them that little high of the affirmation and belonging they are looking for. Eventually they wear themselves out and stop.
When that doesn't work, I just say, "Man I'm busy, I gotta stop talking and get back to work." They usually get the hint then.
After all that, if none of that works, then you're screwed.
My wife is the opposite. She never talks. She's an introvert. I'm a talker. I'll ramble and ramble and get pissed because she tunes me out like I'm not there.
Although ... she did get my attention at Lowe's this weekend. I was gazing at the most perfectly shaped backside, in the tightest pair of gray nylon slacks, wearing high heals, that I have EVER seen in my ENTIRE life. Out of the blue I get a purse to the sack (from my wife). I let out this yelp and the chick in the tight pants turns around and starts laughing. My wife starts laughing and walks away leaving me there leaning up against a rack in pain.
I gotta go.
LOL!