Documentation Index
Fetch the complete documentation index at: https://docs.youka.io/llms.txt
Use this file to discover all available pages before exploring further.
Hướng dẫn này trình bày lộ trình nhanh nhất từ một tệp âm thanh thô đến một video karaoke đã được render bằng @youka/sdk.
Trước khi bắt đầu
- Node.js 20 trở lên
- Một Youka API key trong
YOUKA_API_KEY (tạo tại online.youka.io/account trong mục API keys)
- Một tệp âm thanh cục bộ (
./song.mp3) hoặc một URL từ xa
Cài đặt
Tạo, chờ, xuất
import { YoukaClient, YoukaRequestError, YoukaTaskError } from "@youka/sdk";
const client = new YoukaClient({
apiKey: process.env.YOUKA_API_KEY!,
});
async function main() {
// 1. Tạo một dự án từ tệp cục bộ
const projectOperation = await client.projects.create({
source: { type: "path", path: "./song.mp3" },
lyricsSource: { type: "transcribe" },
});
// 2. Chờ tách stem và đồng bộ lời hoàn tất
const { project } = await client.projects.wait(projectOperation);
console.log("Project ready:", project.id, project.title);
// 3. Bắt đầu một lần xuất
const exportOperation = await client.exports.create(project.id, {
resolution: "1080p",
quality: "high",
});
// 4. Chờ quá trình xuất hoàn tất
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() xử lý upload cho các nguồn path, bytes, và url.
Để kiểm soát upload ở mức thấp hơn, hãy dùng client.uploads.*.
Ba loại nguồn
Tệp cục bộ
Bytes trong bộ nhớ
URL từ xa
const operation = await client.projects.create({
source: { type: "path", path: "./song.mp3" },
});
const fileBuffer = new Uint8Array([/* audio bytes */]);
const operation = await client.projects.create({
source: {
type: "bytes",
data: fileBuffer,
filename: "song.mp3",
},
});
const operation = await client.projects.create({
source: {
type: "url",
url: "https://example.com/song.mp4",
},
});
Tiếp theo là gì
- Projects — API dự án đầy đủ
- Exports — render cục bộ và
client.exports.prepareLocal
- Errors — xử lý
YoukaRequestError và YoukaTaskError
- AI agents — các mẫu polling và retry được khuyến nghị