> ## 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.

# ブラウザで音声を再生

> wav を生成し、<audio> 要素を使って再生します。

```typescript theme={null}
async function ttsPlayAudio(client: Cartesia): Promise<void> {
  const response = await client.tts.generate({
    model_id: 'sonic-latest',
    transcript: 'Hello from the browser!',
    voice: { mode: 'id', id: '6ccbfb76-1fc6-48f7-b71d-91ac6298247b' },
    output_format: { container: 'wav', encoding: 'pcm_s16le', sample_rate: 44100 },
    language: 'en',
  });

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

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

出典: [cartesia-js/examples/browser\_examples.ts:73](https://github.com/cartesia-ai/cartesia-js/blob/v3.2.0/examples/browser_examples.ts#L73)

## このサンプルを実行する

このサンプルはブラウザ上で動作します。動作するセットアップ例については [Next.js サンプル](/examples/nextjs) を参照してください。
