Skip to main content
For the endpoint contract see Audio API. This guide covers practical recipes.

Text-to-speech

Pick a voice and model

Voice character is fixed per voice — you can’t fine-tune them. To pick, render the same line in 3–4 voices and listen.

Save to file

python

Sample output

“Welcome to Infery — one API for every AI model.” Generated with gemini-2.5-flash-preview-tts, voice Kore.

Stream to a player

For long passages, stream the bytes directly to the user’s audio element instead of downloading then playing:
python

Format choice

Pacing

speed is 0.25 → 4.0. Most listeners are comfortable at 0.95–1.15 . Speeding past 1.5 is intelligible but tiring; slowing below 0.85 gets robotic.

Speech-to-text

Quick transcription

python

Long-form audio (>25 MB)

Whisper-1 caps at 25 MB. For longer recordings, split first:
python
Use 64 kbps mono MP3 — Whisper doesn’t benefit from higher bitrate, and you stay well under the size cap.

Subtitle export

response_format="srt" or "vtt" returns ready-to-use subtitle files:
python

Word-level timestamps

python
Useful for click-to-seek transcripts and aligning with diarisation.

Translation

Use client.audio.translations.create(...) to transcribe and translate to English in one call. Source language is auto-detected.

Round-trip: voice agent

Combining STT → chat → TTS gives you a basic voice agent:
python
End-to-end latency is dominated by the chat call. Realtime (WebSocket bidirectional voice) is on the roadmap.

Costs at a glance

  • TTS: ~15per1Mcharactersontts1, 15 per 1 M characters on `tts-1`, ~30 on tts-1-hd
  • Whisper STT: ~$6 per hour of audio
  • Long meetings (1 h) typically cost less than the chat completion that follows them

Pitfalls

  • Wrong language hint drops STT accuracy. Auto-detect is good but a language= hint is better when known.
  • Quiet/clipped recordings — Whisper handles noise well but not clipping. Normalise levels before transcribing.
  • TTS swallowing punctuation — write naturally; “Hi—how are you?” reads better than “Hi how are you”.
  • Long base64 audio over JSON wastes 33% bandwidth vs. multipart. Use multipart unless you have a JSON-only client.