Eee Haaa, rolling up the sleeves here. My favorite subject.
Y'all know by now, after a year of me kicking around here, that I was staff writer for an professional audio drama company for 12 years and I cut my writing teeth writing plays in theatre (kinda like @cherrystark and her theatrical background) so dialogue is my thing also. I'm totally agreeing with what she's written, all of that is very important. I'm going to add a little bit to her points.
1. Modification of speech for environment.
You can have fun here. Say Clerk A is speaking with two people at opposite ends of the jewelry counter. Character B is a long time customer, so long they have one of those "friendships" you develop with clerks you see a lot. Character C is new, standoffish and looks like she could be a potential "Karen."
A speaks to B: "Hey, we got some great bracelets in yesterday but they won't be out until Saturday. Are you still trying to find a Gothy type black one 'cuz there's one in there you'll die for. Want me to put it aside for you?
A turns to C: Are you looking for anything specific, Ma'am? We have some very pretty necklaces that would look lovely with your blouse. They look a little understated on the display but the moonstone would be beautiful with your skin tone.
The fun thing about this (and it's been used in a lot of comedy TV and movies) is the almost split personality of the character dealing with two different people. A little like watching someone having an argument and answering the phone as if everything is beautiful.
(a side note, I'm a antique/vintage jewelry collector and modern styles too, a clerk that can identify which stones go best with a person's skin tone is GOLD at the sales counter.)
Second part: taking into account the character's personal background
I have a friend who had very humble beginnings, but a family that revered education. His family is from a different country but he was born in Britain. He has two PhD's and speaks around 13 languages (they're a hobby for him). He out - Brits the Brits. And it's due to his background. He loves his family and is not ashamed of them, but, he makes the people in Downton Abbey look like they don't know what it is to be British.
Group Slang and References
I'd like to add Dialects/Accents to this. With writing audio drama most of the time we wouldn't write the actual accents but simply state what they were and the actor would take it from there. Depending on the skill of the actor direction might be: "Southeaster Wisconsin flat" or "south Los Angeles" or "New Hampshire" If the actor was less steeped in accents we'd translate to: "midwest flat" or "LA plastic" or "East coast but more inland"
Accents are tough to write and usually you don't want to go heavy on them because they can be hard to read, especially if you have a reader that's not got the ear for them. Level of the characters education makes a difference too.
Example:
Street smart/war weary Sergeant: Well, this ain't gonna be fun.
Educated Lieutenant: I concur.
I'd like to add a few extra tips that I've gotten through audio drama but work in prose also.
Most people don't speak correctly when it comes to grammar. Even well educated ones. They will use slang and regionalism. In a more formal setting they will modify their speech, like what @cherrystark pointed out in her first point. The problem with perfect grammar is that it tends to sound (and read) stilted. There is an exception (isn't there always) Actually there are a few exceptions. 1. someone trying to impose their intellect on everyone. 2. someone who has had perfect grammar drilled into them. 3. someone who's just being a twit. 4. Someone deathly afraid of being called out by his "betters." Perfect grammar in a character can say a lot about what's going on in their brain. You can use this for subtle "tells" to the reader.
If you listen to people around you they rarely, if ever, go into long dissertations about something. They do sometimes and sometimes it can be funny or just tragic as they try to weasel out of being blamed for something, but for the most part conversations between people tend to be short exchanges, back-and-forth even over a page or two, unless in-depth explanations are required.
I mentioned "tells" in a person's speech. These can add so much to a character. A slight, rarely used stutter, a pause before speaking, difficulty with saying certain words... I have a friend who is, literally, "tongue tied (it's a medical condition than doesn't allow the tongue to move properly) and there are certain words he simply cannot say because of it. Certain words can give away a person's age.
Well, this is getting too long.
I hope I've added a little help to the original post. And I second the last line in it: Trust yourself!
Write hard, write true.