Skip to main content
Questa guida illustra il percorso più veloce da un file audio grezzo a un video karaoke renderizzato usando @youka/sdk.

Prima di iniziare

  • Node.js 20 o versioni successive
  • Una chiave API Youka in YOUKA_API_KEY (creane una su online.youka.io/account nella sezione API keys)
  • Un file audio locale (./song.mp3) oppure un URL remoto

Installazione

npm install @youka/sdk

Crea, attendi, esporta

import { YoukaClient, YoukaRequestError, YoukaTaskError } from "@youka/sdk";

const client = new YoukaClient({
  apiKey: process.env.YOUKA_API_KEY!,
});

async function main() {
  // 1. Crea un progetto da un file locale
  const projectOperation = await client.projects.create({
    source: { type: "path", path: "./song.mp3" },
    lyricsSource: { type: "transcribe" },
  });

  // 2. Attendi che la generazione degli stem e la sincronizzazione dei testi terminino
  const { project } = await client.projects.wait(projectOperation);
  console.log("Project ready:", project.id, project.title);

  // 3. Avvia un'esportazione
  const exportOperation = await client.exports.create(project.id, {
    resolution: "1080p",
    quality: "high",
  });

  // 4. Attendi che l'esportazione termini
  const finishedExport = await client.exports.wait(exportOperation);
  await client.exports.download(finishedExport, {
    output: "./exports",
  });
  console.log("Export ready:", finishedExport.url);
}

main().catch((error) => {
  if (error instanceof YoukaRequestError) {
    console.error("Request failed:", error.code, error.status, error.message);
    process.exit(1);
  }
  if (error instanceof YoukaTaskError) {
    console.error("Task failed:", error.code, error.status, error.message);
    process.exit(1);
  }
  throw error;
});
client.projects.create() gestisce i caricamenti per le sorgenti path, bytes e url. Per un controllo del caricamento a più basso livello, usa client.uploads.*.

Tre tipi di sorgente

const operation = await client.projects.create({
  source: { type: "path", path: "./song.mp3" },
});

Cosa fare dopo

  • Projects — API completa dei progetti
  • Exports — render locale e client.exports.prepareLocal
  • Errors — gestire YoukaRequestError e YoukaTaskError
  • AI agents — pattern consigliati per polling e retry