> ## 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 javascript steps

<>
  <Step title="API を呼び出す">
    ```js lines theme={null}
    // hello.js
    import { CartesiaClient } from "@cartesia/cartesia-js";
    import fs from "node:fs";
    import { spawn } from "node:child_process";
    import process from "node:process";

    if (!process.env.CARTESIA_API_KEY) {
      throw new Error("CARTESIA_API_KEY is not set");
    }

    // Set up the client.
    const client = new CartesiaClient({
      apiKey: process.env.CARTESIA_API_KEY,
    });

    // Make the API call.
    const response = await client.tts.bytes({
      modelId: "sonic-2",
      voice: {
        mode: "id",
        id: "a0e99841-438c-4a64-b679-ae501e7d6091",
      },
      outputFormat: {
        container: "wav",
        encoding: "pcm_f32le",
        sampleRate: 44100,
      },
      transcript: "Welcome to Cartesia Sonic!",
    });

    // Write `response` (of type ArrayBuffer) to a file.
    fs.writeFileSync("sonic-2.wav", new Uint8Array(response));

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

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

    Cartesia API クライアントは、Bun や Deno などの他のランタイムにも対応しています。
  </Step>
</>
