import { CartesiaClient } from "@cartesia/cartesia-js";
import process from "node:process"
import fs from "node:fs"
// Set up the client.
const client = new CartesiaClient({ apiKey: process.env.CARTESIA_API_KEY });
// Call the TTS API's bytes endpoint, which returns binary audio data as an ArrayBuffer.
const response = await client.tts.bytes({
modelId: "sonic-2",
transcript: "Hello, world!",
voice: {
mode: "id",
id: "694f9389-aac1-45b6-b726-9d9369183238",
},
language: "en",
outputFormat: {
container: "wav",
sampleRate: 44100,
encoding: "pcm_f32le",
},
});
// Write the response to a file.
fs.writeFileSync("sonic.wav", new Uint8Array(response));