> ## Documentation Index
> Fetch the complete documentation index at: https://docs.slng.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Text-to-speech HTTP examples

> Generate speech audio with the SLNG TTS HTTP API. Code samples in curl, Python, and Node.js for basic requests, voice selection, and streaming responses.

export const AudioPlayer = ({src, title = "Audio", description, autoPlay = false, loop = false, variant = "default"}) => {
  const audioId = useId();
  const isCompact = variant === "compact";
  const audioRef = useRef(null);
  const [isPlaying, setIsPlaying] = useState(false);
  const togglePlayback = () => {
    const audio = audioRef.current;
    if (!audio) return;
    if (audio.paused) {
      void audio.play();
      setIsPlaying(true);
      return;
    }
    audio.pause();
    setIsPlaying(false);
  };
  return <div className={`audio-player ${isCompact ? "compact" : ""}`}>
      {!isCompact && <div className="meta">
          <div className="titles">
            <div className="title">{title}</div>
            {description && <div className="description">{description}</div>}
          </div>

          <a className="download" href={src} download>
            Download
          </a>
        </div>}

      {isCompact ? <>
          <button type="button" className="compact-button" onClick={togglePlayback} aria-label={isPlaying ? "Pause audio sample" : "Play audio sample"}>
            <span className="compact-icon" aria-hidden="true">
              {isPlaying ? "❚❚" : "▶"}
            </span>
          </button>
          <audio id={audioId} ref={audioRef} preload="metadata" loop={loop} autoPlay={autoPlay} aria-label={title} src={src} onEnded={() => setIsPlaying(false)}>
            Your browser does not support the audio element.
          </audio>
        </> : <audio id={audioId} className="audio-control" controls preload="metadata" loop={loop} autoPlay={autoPlay} aria-label={title} src={src}>
          Your browser does not support the audio element.
        </audio>}
    </div>;
};

<Tip>
  Want to try TTS without setting up code? [Open the live demo](https://examples-gbcy.onrender.com) and test different models and voices in your browser.
</Tip>

These examples use the Deepgram Aura model; swap the endpoint path to use a different provider.

## Placeholders

The snippets below use these placeholders. Replace them before running the code.

| Placeholder    | Replace with                                                          |
| -------------- | --------------------------------------------------------------------- |
| `SLNG_API_KEY` | An SLNG key from [app.slng.ai/api-keys](https://app.slng.ai/api-keys) |

## Basic Request

Send text and receive a complete audio file in WAV format:

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.slng.ai/v1/tts/slng/deepgram/aura:2-en \
    -H "Authorization: Bearer SLNG_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "aura-2-thalia-en",
      "text": "Hello from sunny Barcelona!"
    }' \
    --output hello.wav
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    "https://api.slng.ai/v1/tts/slng/deepgram/aura:2-en",
    {
      method: "POST",
      headers: {
        Authorization: "Bearer SLNG_API_KEY",
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        model: "aura-2-thalia-en",
        text: "Hello from sunny Barcelona!",
      }),
    },
  );

  const audioData = await response.arrayBuffer();
  // Play or save audioData
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.slng.ai/v1/tts/slng/deepgram/aura:2-en"
  headers = {
      "Authorization": "Bearer SLNG_API_KEY",
      "Content-Type": "application/json"
  }
  data = {
      "model": "aura-2-thalia-en",
      "text": "Hello from sunny Barcelona!",
  }

  response = requests.post(url, headers=headers, json=data)
  audio_data = response.content

  # Save to file
  with open("output.wav", "wb") as f:
      f.write(audio_data)
  ```
</CodeGroup>

It will sound like this:

<AudioPlayer src="/audio/hello.wav" title="Hello from sunny Barcelona!" />

***

## More Examples

### With Voice Selection (Deepgram Aura)

Beyond the audio generation, each model supports different parameters.

For example, to specify a voice in Deepgram Aura:

```bash highlight={6} theme={null}
curl https://api.slng.ai/v1/tts/slng/deepgram/aura:2-en \
  -H "Authorization: Bearer SLNG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello from sunny Barcelona!",
    "model": "aura-2-theia-en"
  }' \
  --output hello-theia.wav
```

For the complete parameter reference, see the [Text-to-Speech](/api-reference/tts/deepgram-aura-2/aura-2-english-ws) API reference.

### With a Different Model

Each model has its own endpoint and may use different parameters. For example, Rime Arcana uses `speaker` instead of `model`:

```bash highlight={1} theme={null}
curl https://api.slng.ai/v1/tts/slng/rime/arcana:3-en \
  -H "Authorization: Bearer SLNG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello from Rime Arcana!",
    "speaker": "astra"
  }' \
  --output hello-arcana.wav
```

For all available models, endpoints, and their parameters, see the [TTS models page](/models/tts).

To control how brand names, acronyms, and domain-specific terms are spoken, add a [pronunciation dictionary](/pronunciation-dictionaries) to your TTS request.

For voice catalogs with audio samples, browse the [Voices](/voices/deepgram-aura) section in the sidebar.

***

## Next Steps

<CardGroup cols={2}>
  <Card title="Live TTS demo" icon="play" href="https://examples-gbcy.onrender.com">
    Try TTS in your browser, no setup needed
  </Card>

  <Card title="TTS WebSocket examples" icon="bolt" href="/examples/tts-websocket">
    Stream audio in real time for voice agents
  </Card>

  <Card title="Text-to-Speech models" icon="audio-lines" href="/models/tts">
    Browse all TTS models and endpoints
  </Card>

  <Card title="Pronunciation dictionaries" icon="book-open-text" href="/pronunciation-dictionaries">
    Reuse pronunciation rules across TTS requests
  </Card>

  <Card title="TTS API reference" icon="code-xml" href="/api-reference/tts/deepgram-aura-2/aura-2-english-ws">
    Endpoint-specific parameters
  </Card>
</CardGroup>
