Skip to main content

Supported Providers

  • OpenAI
  • Azure OpenAI
The Speech API converts text into high-quality audio using advanced text-to-speech (TTS) models. You can provide any text input up to 4,096 characters, and the API will generate natural-sounding speech. You can customize the output by selecting:
  • Models: tts-1, tts-1-hd, or gpt-4o-mini-tts
  • Voices: alloy, echo, fable, onyx, nova, or shimmer
  • Formats: mp3, opus, aac, flac, wav, or pcm

Code Snippet

from pathlib import Path
from openai import OpenAI

BASE_URL = "https://{controlPlaneUrl}/api/llm"
API_KEY = "your-truefoundry-api-key"

client = OpenAI(
    api_key=API_KEY,
    base_url=BASE_URL,
)

speech_file_path = Path(__file__).parent / "generated-audio.mp3"

with client.audio.speech.with_streaming_response.create(
  model="openai-main/gpt-4o-mini-tts",
  voice="alloy",
  input="hello how are you?"
) as response:
  response.stream_to_file(speech_file_path)
The API generates audio files in the specified format (defaults to MP3) with the selected voice characteristics.
I