This quotation is huge online. But, like most things that look big on the internet, its actual size leaves something to be desired. I started poking around (by which I mean googling) and found pretty quickly that this line has already been called into doubt. It seems to have entered the popular discourse through the usual route, a quote book from the 19th century (1891). The sentiment appears in different collections with some intensity a decade later in 1901, 1903, and 1904.
Proverbial wisdom that uses knowing when to speak as the distinction between wise people and fools is pretty common: check out quoteinvestigator’s overview of the ubiquitous “Better to remain silent and be thought a fool than to speak and to remove all doubt” attributed apocryphally to both Mark Twain and Abraham Lincoln.
Based on my own new rating system, this quotation is Peisistratos Fake: it draws on ancient ideas, but has no real antiquity to it.
Discerning when to be silent and when to speak is also a regular trope in ancient literature (which is alive and well in the Renaissance too, with entries on this from Piccolomini and Vergerio). Plutarch models Odysseus as the type of sage who shows his wisdom by selecting the right moments for speech (and Aulus Gellius says something similar and Macrobius too). It is also very common to use the figures of the fool and the wise person in antithesis
58 “When Aristotle was asked what the most burdensome thing in life is he said “staying silent.”
῾Ο αὐτὸς ἐρωτηθείς, τί δυσκολώτατόν ἐστιν ἐν βίῳ, εἶπε· „τὸ σιωπᾶν”.
[Psst: the quotation I just provided falls somewhere between Rhetorica ad Fictum and Cylon-Helen]