When we hear hate speech or racism we are sometimes so shocked and surprised that we don't know how to react. An effective response is to simply say, "That is inappropriate."
For example, you hear someone respond to "Black Lives Matter", with, "All Lives Matter". You might say, "That is inappropriate and you are missing the point. If I said, we should give food to starving children, would you say that we should give food to all children? You would be missing the point which is to help starving children. Or suppose your house is burning and when you call the Fire Department they say that they can't help because all houses matter. They would be missing the point that your house is the one burning. The Black Lives Matter movement is making the point that a large number of Blacks have been and continue to be killed and that Blacks also face systemic injustice which destroys their lives."
In other cases an attack may be more agressive and it may be better to defuse the situation. One way to do this is suggested by the illustration on the right by artist Maeril. See: Defuse harassment
Another way to have your voice heard is to attend rallies, marches, and protests. The more we participate in democracy the louder our voice.
Straight for Equality Campaign
How to be visible allies.