> ## 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.

# Stems

> Kích hoạt tác vụ tách stem trên một dự án hiện có

Stem là các track giọng hát và nhạc cụ được trích xuất từ audio nguồn. Youka tự động tách stem khi bạn tạo dự án, nhưng bạn có thể chạy lại quá trình tách với một model khác bất cứ khi nào cần.

## `client.projects.separateStems(projectId, body, options?)`

Bắt đầu một thao tác tách stem mới cho một dự án.

```ts theme={null}
const operation = await client.projects.separateStems("prj_abc123", {
  splitModel: "audioshakeai",
});

const { project } = await client.projects.wait(operation);
console.log(project.stems);
```

### Parameters

<ParamField path="projectId" type="string" required>
  Dự án cần xử lý lại.
</ParamField>

<ParamField path="splitModel" type="SplitModel">
  Model tách stem. Xem [Split model reference](/vi/desktop/split-model)
  để được hướng dẫn.
</ParamField>

### Available models

| Value                                         | Description                                   |
| --------------------------------------------- | --------------------------------------------- |
| `mdx23c`                                      | Mặc định. Cân bằng giữa chất lượng và tốc độ. |
| `audioshakeai`                                | Tách AudioShake chất lượng cao.               |
| `audioshake_vocals_lead`                      | Chỉ giọng hát và giọng lead.                  |
| `musicai_instrumental_only`                   | Chỉ xuất nhạc nền (instrumental).             |
| `musicai_lead_backing_other`                  | Lead, backing vocals và các stem khác.        |
| `musicai_with_backing_vocals`                 | Giọng hát bao gồm cả backing.                 |
| `musicai_without_backing_vocals`              | Chỉ giọng lead.                               |
| `uvr_mdxnet_kara_2`                           | Model UVR tinh chỉnh cho karaoke.             |
| `bs_roformer`                                 | Model BS-Roformer.                            |
| `mel_band_roformer_instrumental_becruily`     | Mel-band Roformer instrumental.               |
| `mel_band_roformer_instrumental_instv7_gabox` | Instrumental mel-band thay thế.               |
| `demucs`                                      | Facebook Demucs.                              |

## End-to-end example

```ts theme={null}
import { YoukaClient, YoukaTaskError } from "@youka/vi/sdk";

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

async function reRunStems(projectId: string) {
  const operation = await client.projects.separateStems(projectId, {
    splitModel: "audioshakeai",
  });

  try {
    const { project } = await client.projects.wait(operation);
    console.log("New stems:", project.stems);
  } catch (error) {
    if (error instanceof YoukaTaskError) {
      console.error("Stem separation failed:", error.code, error.message);
      throw error;
    }
    throw error;
  }
}
```

<Tip>
  Chỉ dùng `client.tasks.get(taskId)` hoặc `client.tasks.wait(taskId)` khi bạn
  thực sự cần truy cập tác vụ cấp thấp. Phần lớn trường hợp nên dùng
  `client.projects.wait(operation)`.
</Tip>

## `client.projects.downloadStem(projectId, selector, options?)`

Tải xuống một stem mà không chuyển đổi sang định dạng khác. Chọn chính xác một
stem theo ID hoặc theo type:

```ts theme={null}
await client.projects.downloadStem(
  "prj_abc123",
  { type: "instrumental" },
  { output: "./stems" },
);

await client.projects.downloadStem(
  "prj_abc123",
  { stemId: "stm_abc123" },
  { output: "./stems/original.wav" },
);
```

Các type được hỗ trợ là `original`, `instrumental`, `vocals`, và
`backing_vocals`.

## `client.projects.downloadStems(projectId, selector?, options?)`

Tải xuống nhiều stem. Truyền `types`, truyền `stemIds`, hoặc bỏ qua selector để
tải xuống mọi stem hiện có:

```ts theme={null}
await client.projects.downloadStems(
  "prj_abc123",
  { types: ["original", "instrumental", "vocals"] },
  { output: "./stems" },
);

await client.projects.downloadStems("prj_abc123", undefined, {
  output: "./stems",
});
```

Với tải xuống nhiều stem, hãy dùng một thư mục output. SDK ghi các tệp stem gốc
đã được lưu trữ và không thực hiện chuyển mã.

## What's next

* [Lyrics sync](/vi/sdk/lyrics-sync) — đồng bộ lại lời bài hát sau khi thay stem
* [Tasks](/vi/sdk/tasks) — operation handle và cơ chế polling tác vụ nâng cao
* [Split model reference](/vi/desktop/split-model) — chọn model phù hợp
