Our 3 1/2 month old has just learned how to make an ear-piercing screech, which appears to either mean "happy" or "tired and grumpy".
How can we dissuade her from making this noise, without "ignoring" her when she's upset?
I took a slightly different approach to the other answers.
I simply ignored the screeching, and exaggerated my reactions to everything else.
If he smiled, cooed, burped, or even simply made eye contact, I would put on a big smile and talk to him, tickle him, etc..
When he made loud, painful sounds, I made sure my expression didn't flicker, and I gave him absolutely no response.
I figured that rewarding positive behavior, and ignoring negative behavior rather than actively discouraging it, would be an effective means of communication at that age, since they are so focused on watching for responses and learning how to interact. It did seem to work, as the loud screeching phase was very short for us.
Screeching is unfortunately a common first means of communication, and I can wholly understand why you want to discourage that.
One way to teach it is to encourage her and interact with joy when the makes all other kinds of sounds, to let her know that these are sounds that please you. When she makes these ear-piercing shrieks, show her your discomfort - distort your face, cover your ears, wail or moan, and tell her in plain spoken language "that hurt." Even at her young age, she'll eventually understand that there is a difference.
One of the things kids don't like is a loss of interaction. My son started screeching really loudly, and our reacting with discomfort only made him do it more. Children like to control things, and it's natural for them to do what they can do to make people react. There's no point in getting angry and upset as they genuinely don't understand at their age, so I decided to try and provide feedback in the form of controlling interaction. Every time he screeched I looked away until he stopped, then I looked back. That worked for awhile, but then he did it again and looking away didn't stop him, he just did it louder, so every time he screeched I walked out of the room until he stopped, then I came back in. It did not take long for him to figure it out, and within 2-3 days he stopped and I never had to do anything like that ever again.
In order for interaction control to work you have to react quickly do an association forms: as soon as he starts screeching you leave the room and go where they can't see you, and as soon as they stop you come back in. If you do it promptly and consistently they learn to associate the behavior with something they don't like, leading to them stopping the behavior. If you don't do it consistently or wait until your child's been screeching (or whatever other behavior) for 10 minutes then you'll just confuse your child.
You can't convince a 4 month old to stop a behavior using words, they just don't get it. Interaction is a powerful way to communicate what you want, give more for positive behavior and less for negative behavior. It's much more constructive then getting angry, and it works.
At 4 months old, your baby is simply experimenting with their voice and sounds and trying to make different vocalizations. This is not permanent so I wouldn't worry about correcting any behaviors. Maybe if you are talking about a 2 year old screeching, then some of the answers provided here are relevant. Otherwise for an infant, it's just another developmental milestone and I would just let them learn and explore.
This will work for a bit older baby, but the earlier it is begun and the speed and consistency with which it is enforced will determine how long this behavior modification method takes to extinguish this irritating behavior. When the baby shrieks, IMMEDIATELY firmly squeeze his leg or his shoulder to get his attention. MAKE EYE CONTACT and with a very stern face and voice, use his name and say "NO, Aiden." Don't yell and absolutely don't smile. When he stops shrieking, let go of his shoulder or leg but maintain the stern face which shows him that you don't approve of the behavior. Every time he shrieks, promptly respond. When he has not shrieked for a "long time" (which depends on how often he's been doing it), reward him with smiles and tells him how proud you are that he's such a "big boy" (or some such simple language. If you're consistent, he'll get it and your household will be much more calm and peaceful and everyone's nerves will be less rattled!