Everything about voice AI in production: WhatsApp Media API, FFmpeg, OGG/OPUS, temp file lifecycle, and TTS text preparation.
The two-step upload β send flow, MIME type requirements (audio/ogg; codecs=opus), delivery status callbacks, and the silent success trap: API returns 200 but deβ¦
WAV β OGG/OPUS: the full annotated command. Bitrate choices for voice (48k VBR Opus). Detecting actual format with the file command vs trusting the extension. Cβ¦
Test each step independently: TTS, conversion, upload, send. Meta delivery status as ground truth. Decoding common error codes (131053 and others). Reading curlβ¦
Create in /tmp with random names, always unlink in finally blocks, PHP register_shutdown_function for emergency cleanup, and monitoring /tmp growth for leaks.
Stripping WhatsApp markdown (/u flag required), expanding legal abbreviations for natural pronunciation, converting bullet lists to spoken connectives, characteβ¦