Whistling fireworks require two components: an explosive mixture that makes a sound when it burns and an empty portion of the rocket tube to act as a resonance chamber. The gas released creates the noise, while the chamber allows the sound waves to build on each other to earsplitting volume.
One common recipe for a whistling firework uses potassium benzoate and an oxidizer packed in layers. As the mixture burns, it produces sharp bursts of gas that create a high-pitched whistling noise. The mixture must be packed carefully so that it will burn in stages; any gaps in the mixture may allow pressure to build and prematurely detonate the firework.