Implementation:Groq Groq python Speech Create
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Audio, Text_To_Speech |
| Last Updated | 2026-02-15 16:00 GMT |
Overview
Concrete tool for generating speech audio from text provided by the Groq Python SDK.
Description
The Speech.create() method POSTs to /openai/v1/audio/speech with the text, model, and voice parameters. It returns a BinaryAPIResponse containing raw audio bytes. The request includes an Accept: audio/wav header by default.
Usage
Access via client.audio.speech.create(). The three required parameters are input, model, and voice. The returned BinaryAPIResponse provides .content (bytes), .write_to_file(), and .stream_to_file() methods.
Code Reference
Source Location
- Repository: groq-python
- File: src/groq/resources/audio/speech.py
- Lines: L50-110 (sync), L133-193 (async)
Signature
class Speech(SyncAPIResource):
def create(
self,
*,
input: str,
model: Union[str, Literal["playai-tts", "playai-tts-arabic"]],
voice: str,
response_format: Literal["flac", "mp3", "mulaw", "ogg", "wav"] | Omit = omit,
sample_rate: Literal[8000, 16000, 22050, 24000, 32000, 44100, 48000] | Omit = omit,
speed: float | Omit = omit,
) -> BinaryAPIResponse:
Import
from groq import Groq
# Access via: client.audio.speech.create(...)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| input | str | Yes | Text to generate audio for |
| model | str or Literal["playai-tts", "playai-tts-arabic"] | Yes | TTS model ID |
| voice | str | Yes | Voice ID |
| response_format | Literal["flac", "mp3", "mulaw", "ogg", "wav"] | No | Audio output format |
| sample_rate | Literal[8000, ..., 48000] | No | Audio sample rate |
| speed | float | No | Speech speed |
Outputs
| Name | Type | Description |
|---|---|---|
| (return) | BinaryAPIResponse | Contains raw audio bytes; access via .content, .write_to_file(), or .stream_to_file() |
Usage Examples
from groq import Groq
from pathlib import Path
client = Groq()
response = client.audio.speech.create(
input="The quick brown fox jumps over the lazy dog.",
model="playai-tts",
voice="Arista-PlayAI",
response_format="wav",
)
# Save to file
Path("output.wav").write_bytes(response.content)
# Or use the convenience method
response.write_to_file("output.wav")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment