Skip to content

Add xAI TTS service#4031

Open
niczy wants to merge 3 commits intopipecat-ai:mainfrom
niczy:xai-tts-service
Open

Add xAI TTS service#4031
niczy wants to merge 3 commits intopipecat-ai:mainfrom
niczy:xai-tts-service

Conversation

@niczy
Copy link

@niczy niczy commented Mar 13, 2026

Summary

  • Add XAIHttpTTSService backed by xAI's HTTP text-to-speech API
  • Support all 20 xAI-supported languages via explicit LANGUAGE_MAP using resolve_language()
  • Configurable output encoding (pcm, mp3, wav, mulaw, alaw) as a constructor parameter
  • Add 07e-interruptible-xai.py foundational example; update 14g-function-calling-grok.py to use xAI TTS
  • Register 07e in run-release-evals.py

Testing

  • uv run pytest tests/test_xai_tts.py
  • Test live with examples/foundational/07e-interruptible-xai.py using a valid GROK_API_KEY

markbackman added a commit that referenced this pull request Mar 24, 2026
Reworks the xAI TTS integration from #4031 with consistency fixes:
- Rename to XAIHttpTTSService (leaves room for future WebSocket service)
- Add proper language map with all 20 supported xAI languages
- Remove unnecessary deprecated InputParams/params (new service, nothing to deprecate)
- Add encoding as a constructor parameter
- Use Language.EN enum instead of string for default language
- Linting fixes
@markbackman markbackman mentioned this pull request Mar 24, 2026
3 tasks
@markbackman
Copy link
Contributor

Thanks for the contribution! Here are some changes needed before we can merge:

  1. Rename XAITTSService to XAIHttpTTSService — This is an HTTP-based service, and we want to leave room for a future WebSocket implementation. This follows the pattern of ElevenLabsHttpTTSService / CartesiaHttpTTSService. Update the settings class name to XAIHttpTTSSettings as well.
  2. Add language map — language_to_service_language currently does return str(language) which passes through any Language enum value verbatim. xAI only supports 20 specific language codes (some regional like ar-EG, pt-BR, es-MX). Please add a language_to_xai_language() function with an explicit LANGUAGE_MAP using resolve_language(), like other services do (see cartesia/tts.py or elevenlabs/tts.py for examples). Also needs from pipecat.transcriptions.language import Language, resolve_language.
  3. Remove deprecated InputParams, params, voice, language init params — Since this is a brand new service that has never shipped, there's nothing to be backward-compatible with.
  4. Remove class constants XAI_DEFAULT_SAMPLE_RATE and XAI_PCM_CODEC - instead, we want to include encoding as a constructor parameter and set sample_rate to None, so that it can be set either by default from the PipelineParams or by the user via a constructor parameter.
  5. Use Language.EN instead of string "en" for default language.
  6. README link was missing; docs will be automatically generated after this is merged. Location will be https://docs.pipecat.ai/server/services/tts/xai
  7. Linting fixes.
  8. Examples: Added 07e foundational example; updated 14g foundational example.

I made a branch while I was reviewing these changes. I've pushed these to origin for you to use as a starting point:
#4121

Also, once this change is in, I think we'll move the GrokLLMService to the new xai module, so that services are consolidate. We can do that in a separate PR though.

markbackman added a commit that referenced this pull request Mar 24, 2026
Reworks the xAI TTS integration from #4031 with consistency fixes:
- Rename to XAIHttpTTSService (leaves room for future WebSocket service)
- Add proper language map with all 20 supported xAI languages
- Remove unnecessary deprecated InputParams/params (new service, nothing to deprecate)
- Add encoding as a constructor parameter
- Use Language.EN enum instead of string for default language
- Linting fixes
…an up API

- Rename XAITTSService → XAIHttpTTSService and XAITTSSettings → XAIHttpTTSSettings
- Add language_to_xai_language() with explicit LANGUAGE_MAP using resolve_language()
- Remove deprecated InputParams, params, voice, language init params
- Remove XAI_DEFAULT_SAMPLE_RATE and XAI_PCM_CODEC constants; add encoding param
- Set sample_rate=None default (picked up from PipelineParams or user)
- Use Language.EN enum instead of string "en" for default language
- Add changelog/4031.added.md
- Add 07e-interruptible-xai.py foundational example
- Update 14g-function-calling-grok.py to use XAIHttpTTSService
- Register 07e in run-release-evals.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants