JavaScript Client for Cartesia
Installation
npm install @cartesia/cartesia-js
yarn add @cartesia/cartesia-js
pnpm add @cartesia/cartesia-js
bun add @cartesia/cartesia-js
Usage
import Cartesia from "@cartesia/cartesia-js";
const cartesia = new Cartesia();
try {
await cartesia.audio.connect();
} catch (error) {
console.error(`Failed to connect to Cartesia: ${error}`);
}
const stream = await cartesia.audio.stream({
model: "upbeat-moon",
options: {
transcript: "Hello, world!",
chunk_time: 0.1,
},
});
console.log(`Created stream ${stream.id}.`);
stream.on("chunk", ({ chunk, chunks }) => {
console.log("Received chunk:", chunk);
console.log("All chunks:", chunks);
});
stream.on("message", ({ message }) => {
console.log("Received message:", message);
});
console.log("Playing stream...");
await stream.play();
console.log("Done playing.");