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

# SSE Streaming

> Basic SSE streaming.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    def tts_sse_basic(client: Cartesia) -> None:
        """Basic SSE streaming."""
        stream = client.tts.generate_sse(
            model_id="sonic-3.5",
            transcript="Hello, world!",
            voice={"mode": "id", "id": "6ccbfb76-1fc6-48f7-b71d-91ac6298247b"},
            output_format={"container": "raw", "encoding": "pcm_f32le", "sample_rate": 44100},
        )

        import datetime
        filename = f"tts_sse_basic_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.pcm"

        with open(filename, "wb") as f:
            for event in stream:
                if event.type == "chunk":
                    # v3.x returns raw bytes in event.audio
                    if event.audio:
                        f.write(event.audio)
                elif event.type == "done":
                    break
                elif event.type == "error":
                    raise Exception(f"Error: {event.error}")

        print(f"Saved audio to {filename}")
        print(f"Play with: ffplay -f f32le -ar 44100 {filename}")
    ```

    From [cartesia-python/examples/examples.py:62](https://github.com/cartesia-ai/cartesia-python/blob/main/examples/examples.py#L62)
  </Tab>

  <Tab title="Python (Async)">
    ```python theme={null}
    async def tts_sse_basic_async(client: AsyncCartesia) -> None:
        """Basic SSE streaming."""
        stream = await client.tts.generate_sse(
            model_id="sonic-3.5",
            transcript="Hello, world!",
            voice={"mode": "id", "id": "6ccbfb76-1fc6-48f7-b71d-91ac6298247b"},
            output_format={"container": "raw", "encoding": "pcm_f32le", "sample_rate": 44100},
        )

        filename = f"tts_sse_async_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}.pcm"

        with open(filename, "wb") as f:
            async for event in stream:
                if event.type == "chunk":
                    if event.audio:
                        f.write(event.audio)
                elif event.type == "done":
                    break
                elif event.type == "error":
                    raise Exception(f"Error: {event.error}")

        print(f"Saved audio to {filename}")
        print(f"Play with: ffplay -f f32le -ar 44100 {filename}")
    ```

    From [cartesia-python/examples/async\_examples.py:52](https://github.com/cartesia-ai/cartesia-python/blob/main/examples/async_examples.py#L52)
  </Tab>
</Tabs>

## Run this example

<Tabs>
  <Tab title="Python">
    ```sh theme={null}
    cd cartesia-python
    CARTESIA_API_KEY=YOUR_KEY python3 examples/examples.py tts_sse_basic
    ```
  </Tab>

  <Tab title="Python (Async)">
    ```sh theme={null}
    cd cartesia-python
    CARTESIA_API_KEY=YOUR_KEY python3 examples/async_examples.py tts_sse_basic_async
    ```
  </Tab>
</Tabs>
