OpenAI | Speech
Generate spoken audio from text using the Text-to-Speech (TTS) API. Supports multiple voices and output formats.
Simple Example
Generate speech from text and save to a file stream.
OpenAI := TsgcHTTP_API_OpenAI.Create(nil);
OpenAI.OpenAIOptions.ApiKey := 'API_KEY';
oStream := TFileStream.Create('output.mp3', fmCreate);
Try
OpenAI._CreateSpeech('tts-1', 'Hello, how are you?', 'alloy', oStream);
Finally
oStream.Free;
End;
Methods
- CreateSpeech: Generates audio from the input text.
- Model: ID of the model to use (tts-1 or tts-1-hd).
- Input: The text to generate audio for. Maximum 4096 characters.
- Voice: The voice to use (alloy, echo, fable, onyx, nova, shimmer).
- ResponseStream: The stream where the audio data will be written.
- ResponseFormat: (optional) The audio format: mp3 (default), opus, aac, or flac.
- Speed: (optional) The speed of the generated audio (0.25 to 4.0, default 1.0).