Send and receive small audio
- Ask for
opusfrom/v1/speech: about 40 KB for ten seconds, against 480 KB as WAV. Usemp3where Opus does not play. - Upload voice notes as they are. A WhatsApp OGG is already small; converting it to WAV first makes it about ten times larger.
- Record in mono, at the phone’s normal speech settings. Stereo and high sample rates add bytes, not accuracy.
Make fewer round trips
- Speech in, speech out in one call.
/v1/translatewithinclude_audioreturns the translation and its audio together. - Generate shared audio once. A daily announcement played to thousands of people should be one
/v1/speechcall, stored on your server or a CDN, not one call per listener. - Read
/v1/voicesonce when your app starts, not before each request.
Handle the line dropping
- Keep the recording until the answer arrives. If the upload fails, retry from the saved file instead of asking the person to speak again.
- Retry with a pause. On a network error,
502or504, wait a second, then two, then four, and stop after a few tries. A request that fails counts nothing against your allowance. - Use a generous timeout. The first request after a quiet spell can take a minute or more while the model wakes up. Set timeouts in minutes, not seconds, and show the person that something is happening.
Python
Do not retry
429 quota_exceeded: the month’s allowance is used, and only next month (or a higher allowance) changes that.Show progress people can trust
Speech takes a moment to make and to download. Say so: a short sound or a “listening…” state when recording ends, and play the answer as soon as the file arrives. On slow lines, a text version of the answer shown first (thetext, reply or source_text field) lets people start reading while the audio loads.