Workflow:Groq Groq python Text To Speech
| Knowledge Sources | |
|---|---|
| Domains | Audio, Text_to_Speech, Inference |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
End-to-end process for converting text into spoken audio using Groq-hosted TTS models.
Description
This workflow covers the procedure for generating speech audio from text input using Groq's text-to-speech API. It uses PlayAI TTS models to synthesize spoken audio from text strings, returning the audio as a binary response. The workflow supports multiple output formats (mp3, wav, flac, ogg, mulaw), configurable sample rates, voice selection, and playback speed adjustment.
Usage
Execute this workflow when you have text content that needs to be converted to spoken audio. This is appropriate for accessibility features, podcast generation, voice assistant responses, audiobook production, or any application that needs to produce speech from text.
Execution Steps
Step 1: Client Initialization
Instantiate the Groq client with authentication credentials. The TTS API shares the same client as other Groq endpoints.
Key considerations:
- Same Groq() or AsyncGroq() client used for all API endpoints
- Consider timeout settings for longer text inputs that produce larger audio files
Step 2: Speech Request Configuration
Configure the speech synthesis parameters: input text, model selection, voice identifier, and optional audio format settings. The input text is the content to be spoken. The model determines the TTS engine used. The voice parameter selects the speaking voice.
Key considerations:
- Input text is required and contains the content to synthesize
- Model options include playai-tts and playai-tts-arabic
- Voice parameter selects from available voice identifiers
- Optional: response_format (flac, mp3, mulaw, ogg, wav), sample_rate, speed
Step 3: Speech Generation Request
Call the audio speech create endpoint with the configured parameters. The API processes the text and returns a BinaryAPIResponse containing the generated audio data. The response is binary content in the requested audio format.
Key considerations:
- The response is a BinaryAPIResponse, not a parsed Pydantic model
- Audio data must be read from the response (e.g., response.content for bytes)
- For large outputs, use with_streaming_response to avoid loading the entire audio into memory
Step 4: Audio Output Handling
Extract the binary audio data from the response and write it to a file or stream it to an output device. The binary content is in the format specified by the response_format parameter (defaulting to the model's native format).
Key considerations:
- Use response.content to get the full audio as bytes
- Write bytes to a file with the appropriate extension for the chosen format
- For streaming output, use with_streaming_response and iter_bytes()