How to play audio on arduino mega 2560

Hi there is there any code referencea for making my arduino mega 2560 talk thanks

there is no speaker on a Mega... so no.

"talk" can mean a number of things. full Speech synthesis (Text To Speech - TTS) is not within reach due to limited memory space and compute power.

there is the Talkie library from Peter Knight and Armin Joachimsmeyer with a recorded vocabulary of about 1000 words in English and voice output is at 8 kHz so it sounds very computer like (if you ever knew Texas Instruments speech chips of the '80s)

if you want to have extra hardware, perform TTS in the cloud, etc then it depends what hardware you add...