A whistling toilet is caused when the fill valve does not shut completely. If there is a gap, water leaks into the tank, causing the valve to vibrate. This is often caused by a dry or deteriorated ballcock valve.
To fix a whistling toilet, the fill valve can be replaced or a new ballcock can be installed. Either option can be done without professional help, but a new ballcock is easier for a DIY project.
The concept of a whistling toilet is similar to when a person whistles. The air pushed through their lips only causes a vibration when the space is small. In the toilet, when the fill valve is fully open, vibrations don't occur.