How to mute piezo buzzer?

I am able to play a sound from the buzzer, but when I try to stop the sound, it has a constant buzzing sound, how do I fix it? Here's my code, thanks in advance
if (cm >= 30)tone(speaker, 1000);
else (speaker, 0);

What is this all about? :o
(speaker, 0);
Look at noTone()

Your buzzer might be the wrong type.

Show us a good schematic of your circuit.
Show us a good image of your wiring.

Always show us your ‘current’ compete sketch.
Use CTRL T to format the sketch.
Please use code tags.
Use the </> icon in the posting menu.

[code] Paste sketch here. [/code]

Since your code snippet does not tell us how or where cm is set, the bug could well be there but how to know?

If there was only. some. way....