Speech API

The GET https://llmfoundry.straive.com/openai/v1/audio/speech API converts text to speech. It accepts the same parameters as the OpenAI API.

  • model: string, required. One of the available TTS models: tts-1 or tts-1-hd.
  • input: string, required. The text to generate audio for. The maximum length is 4096 characters.
  • voice: string, required. The voice to use when generating the audio. Supported voices are alloy, echo, fable, onyx, nova, and shimmer. Previews of the voices are available in the Text to speech guide.
  • response_format: string, optional. Defaults to mp3. The format to audio in. Supported formats are mp3, opus, aac, flac, wav, and pcm.
  • speed: number, optional. Defaults to 1. The speed of the generated audio. Select a value from 0.25 to 4.0.

Example:

?model=tts-1&voice=echo&input=Hello%2C%20world

It returns an MP3 file (or the requested format).

HTML

You can use the src attribute to embed the audio in an HTML page:

<audio src="https://llmfoundry.straive.com/openai/v1/audio/speech?model=tts-1&voice=echo&input=Hello%20world" controls></audio>

You can also dynamically set the parameters:

<audio src="" controls></audio>

<script>
  const audio = document.querySelector("audio");
  const params = { model: "tts-1", voice: "echo", input: "Hello world" };
  audio.src = `https://llmfoundry.straive.com/openai/v1/audio/speech?${new URLSearchParams(params).toString()}`;
</script>