A technical consideration or two...
To play a sound loudly, you need to move a lot of air. This requires power. Your speaker must either move a small cross-section of air a long distance, or a large cross-section of air a short distance. Which is to say, you'll need a special speaker construction.
A few D batteries could power an automobile horn. Maybe 8 or 9V. You would not necessarily need 12 V.
However...
I don't recommend you use anything but an old-fashioned jingle bell.
It can be heard amidst traffic, its sound is friendly, and anyone hearing it will identify it as a bicycle.
A bicyclist is often close to pedestrians. So, if I were standing at a curb, and I heard an automobile horn next to me, I'd jump out of my skin. My first thought would be 'Get out of the way, a car is coming at you.' It's the sort of thing that can give people a heart attack.
Furthermore if equipment on your bicycle looks valuable, you can expect it to disappear when you're not around.