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

# Make api request sonic2 bytes python steps

<>
  <Step title="API を呼び出す">
    ```python lines theme={null}
    import os
    import subprocess
    from cartesia import Cartesia

    if os.environ.get("CARTESIA_API_KEY") is None:
        raise ValueError("CARTESIA_API_KEY is not set")

    client = Cartesia(api_key=os.environ.get("CARTESIA_API_KEY"))

    data = client.tts.bytes(
        model_id="sonic-2",
        transcript="Hello, world! I'm generating audio on Cartesia.",
        voice_id="a0e99841-438c-4a64-b679-ae501e7d6091",
        # You can find the supported `output_format`s at https://docs.cartesia.ai/api-reference/tts/bytes
        output_format={
            "container": "wav",
            "encoding": "pcm_f32le",
            "sample_rate": 44100,
        },
    )

    with open("sonic-2.wav", "wb") as f:
        f.write(data)

    # Play the file
    subprocess.run(["ffplay", "-autoexit", "-nodisp", "sonic-2.wav"])
    ```
  </Step>

  <Step title="スクリプトを実行する">
    ```sh lines theme={null}
    env CARTESIA_API_KEY=YOUR_API_KEY python cartesia.py

    # Or, if you're using uv
    env CARTESIA_API_KEY=YOUR_API_KEY uv run cartesia.py
    ```
  </Step>
</>
