Skip to content

AI 0.16.0: Character timings for xAI text-to-speech

AI 0.16.0 adds one option for apps that use xAI text-to-speech: the audio can come back with the timing of each character, so an app can sync captions or highlight text as it is spoken.

Timings with the audio

PhoenixKitAI.speak/3 and Completion.text_to_speech/3 accept with_timestamps: true. On an xAI endpoint the result then carries timestamps, a list of %{char:, start:, end:} entries, one per character. xAI gives no word boundaries, so an app that needs words splits the text on spaces itself.

The option is xAI only. Mistral and OpenAI ignore it, and their results always have timestamps: nil, so the result has the same shape whatever the provider. Without the option, xAI results also carry timestamps: nil.

Each speech request in the usage log records has_timestamps in its metadata.

Upgrading

No migration. Update the dependency. Nothing changes until a call passes the new option. Asking for timings makes the xAI request take longer.

Full release notes: AI 0.16.0

0.16.0 · 16 July 2026

Added

  • :with_timestamps option for PhoenixKitAI.speak/3 / Completion.text_to_speech/3, xAI only. xAI’s POST /v1/tts accepts with_timestamps: true and returns character-level timing (audio_timestamps.graph_chars/graph_times, parallel arrays) alongside the audio — useful for caption sync, karaoke-style highlighting, or word-level playback in host apps. decode_xai_audio/3 now parses that into a flat timestamps: [%{char:, start:, end:}] list (word boundaries aren’t given directly — split on whitespace to derive them); nil when not requested or the response doesn’t include it. Ignored by Mistral/OpenAI (timestamps is always nil there too, for a uniform return shape regardless of provider) — neither offers anything equivalent on their TTS APIs (only on their separate speech-to-text models, the wrong direction). No price difference confirmed against xAI’s pricing page; adds latency for xAI’s post-synthesis alignment pass. Verified against the live API, not just documented shape — the response genuinely does switch from the usual raw-binary body to the documented JSON envelope when this flag is set (unlike the base default-shape assumption fixed in 0.14.1, this one held up).
  • phoenix_kit_ai_requests TTS metadata gains has_timestamps: boolean for observability.

AI 0.16.0. Install or update: {:phoenix_kit_ai, "~> 0.16"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.