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

# Play Audio in Browser

> Generate a wav and play it using an <audio> element.

```typescript theme={null}
async function ttsPlayAudio(client: Cartesia): Promise<void> {
  /** Generate a wav and play it using an <audio> element. */
  const response = await client.tts.generate({
    model_id: 'sonic-3.5',
    transcript: 'Hello from the browser!',
    voice: { mode: 'id', id: '6ccbfb76-1fc6-48f7-b71d-91ac6298247b' },
    output_format: { container: 'wav', encoding: 'pcm_s16le', sample_rate: 44100 },
  });

  const blob = await response.blob();
  const url = URL.createObjectURL(blob);

  const audio = new Audio(url);
  audio.onended = () => URL.revokeObjectURL(url);
  await audio.play();
}
```

From [cartesia-js/examples/browser\_examples.ts:33](https://github.com/cartesia-ai/cartesia-js/blob/main/examples/browser_examples.ts#L33)

## Run this example

This example runs in the browser. See the [Next.js example](/examples/nextjs) for a working setup.
