Conversation
Introduce first-class client.tts support for the public REST Voice/TTS APIs: POST /v1/tts (synthesize) and GET /v1/tts/voices (list_voices / get_voice). Includes typed models, client-side validation, raw audio vs with_timestamps JSON envelope handling, mocked unit tests, and sync/async examples. Fixes xai-org#126
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a first-class TTS client for the public documented Voice/TTS REST APIs, addressing #126.
client.tts.synthesize(...)→POST /v1/tts(sync + async)client.tts.list_voices()/client.tts.get_voice(voice_id)→GET /v1/tts/voices[/{id}]TtsResponse,Voice,AudioTimestamps,OutputFormat, …)with_timestampsJSON envelopes (supports both[start, end]and{start, end}graph_times shapes)examples/sync/tts.pyandexamples/aio/tts.pyAPI surface
Deferred (intentionally out of scope for this PR)
wss://api.x.ai/v1/tts)/v1/custom-voices)Happy to iterate if maintainers prefer different method names or want streaming in a follow-up.
Test plan
uv run ruff format --check/uv run ruff checkon changed filesuv run pyrighton TTS modules + clientsuv run pytest tests/tts_test.py tests/sync/tts_test.py tests/aio/tts_test.py -v(35 passed)uv run pytest tests/sync/client_test.py tests/aio/client_test.py tests/tts_test.py tests/sync/tts_test.py tests/aio/tts_test.py -q(62 passed)Fixes #126