As soon as you see your dog perk up as if he is going to bark the correction needs to be made. You need to try and catch him a second before he goes into a heightened state; timing is critical. You need to watch for signs of interest in whatever your dog is going to bark at and catch him right before he starts. Once a dog starts barking it is harder to make him stop because he is at a high level of excitement. The way you are feeling at the time has a lot to do with your success. If you are upset or anxious in any way your dog will feed from that emotion and it will intensify the dog's reaction to what he is about to bark at. You want to remain calm but very enthusiastic/serious.
The correction can be a tug on the lead, a touch to the neck, a backwards bop with the side of your foot to the butt of the dog, a verbal correction such as "No," "Hey," "Aaatttt"—whatever works for that particular dog. You may also walk in front of your dog to block his view, lean forward and say, "No" and touch him in the neck if he continues to want to bark. Your intensity needs to match his without going too much over or you could intensify the dog’s reaction, but on the other hand if your intensity is less than his you will not be effective and the dog will not listen. Each and every time you hear your dog growl or bark you need to correct it. The intensity of the correction will vary from dog to dog, situation to situation. For example, a little Chihuahua may only need a two-finger touch to the neck, whereas a big Rottweiler may need a backwards boot to the butt with the side of your foot; where other dogs may only need a verbal command, others may need a combination. Keep your dog moving forward, keep walking