Developers / SDKs / Python

在 Python 裡做 stem 分離。

用 12 行程式碼從你的 Python service 發布 stem separation——不需 GPU、不需下載模型、不需 FFmpeg。PyPI 上的型別化 client,本頁提供 FastAPI 和 Flask webhook handlers,並使用你已經信任的同一個 htdemucs_ft 模型。

$pip install aistemsplitter
v0.1.0GitHubPyPI
取得 API 金鑰閱讀 API 文件

本頁內容

  1. 01安裝
  2. 02驗證
  3. 03Hello world
  4. 04Methods
  5. 05Webhooks
  6. 06下一步
/ 安裝

安裝

$pip install aistemsplitter
/ 驗證

驗證

在 developer settings 頁面建立一把 key,然後 export 為 AISTEMSPLITTER_API_KEY,讓 client 自動讀取。只有當你需要每次 request 使用不同 key 時,才在 constructor 傳 api_key=——預設建議使用 env var。

txt
import os
from aistemsplitter import AiStemSplitter

client = AiStemSplitter(api_key=os.environ["AISTEMSPLITTER_API_KEY"])
/ hello world

Hello world

從 imports 到磁碟上的 4 條 stem,只要 12 行。提交一個 job 到 htdemucs_ft,輪詢到完成,然後把 vocals.wav、drums.wav、bass.wav 和 other.wav 寫到腳本旁邊。複製、貼上、執行。

txt
import os
import requests
from aistemsplitter import AiStemSplitter

client = AiStemSplitter(api_key=os.environ["AISTEMSPLITTER_API_KEY"])

# 1. Submit a split job
job = client.create_split(
    input={"type": "direct_url", "url": "https://example.com/song.mp3"},
    stem_model="htdemucs_ft",
)

# 2. Wait until completion (polls under the hood)
result = client.wait_for_split(job.id)

# 3. Download all six stems to disk
for name, url in result.stems.items():
    with requests.get(url, stream=True) as r:
        with open(f"./{name}.wav", "wb") as f:
            for chunk in r.iter_content(chunk_size=8192):
                f.write(chunk)
/ methods

Methods

完整 SDK surface 只有 4 個型別化 methods,1 分鐘內就能看完——submit、get、wait、download。每個 method 都映射一個 REST endpoint,所以當 typed wrapper 不夠用時,可以隨時切到 /developers/api 的 raw HTTP。暴露的模型:htdemucs_ft、htdemucs、htdemucs_6s。依輸入分鐘從永不到期的分鐘包扣費,每分鐘 $0.08–$0.14。

createSplit(input)
README

提交新的 split job;回傳 job id 和 queued status。

getSplit(id)
README

取得某個 split job 的目前狀態。

waitForSplit(id, timeout_s=600)
README

持續輪詢,直到 job 成功、失敗或超時。

listSplits(query=None)
README

依頁列出這把 API 金鑰最近的 split jobs。

presignUpload(filename)
README

取得 pre-signed PUT URL,用於瀏覽器/伺服器直接上傳。

verifyWebhook(headers, raw_body)
README

驗證傳入 webhook payload 上的 HMAC-SHA256 signature。

/ webhooks

Webhooks

在 production 跳過輪詢迴圈。submit 時設定 webhook_url,然後驗證傳入 POST 的 HMAC signature,並直接從 body 讀取 presigned stem URLs。同一頁提供 FastAPI 和 Flask handlers。

txt
import os
from fastapi import FastAPI, Request, HTTPException
from aistemsplitter import AiStemSplitter

app = FastAPI()
client = AiStemSplitter(api_key=os.environ["AISTEMSPLITTER_API_KEY"])

@app.post("/webhooks/aistemsplitter")
async def handle_webhook(request: Request):
    raw = await request.body()
    try:
        event = client.verify_webhook(request.headers, raw)
    except Exception:
        raise HTTPException(status_code=400, detail="invalid signature")

    if event.type == "split.succeeded":
        # event.data["stems"] -> six URLs
        pass
    elif event.type == "split.failed":
        # event.data["error"] -> { code, message }
        pass
    return {"ok": True}
/ 常見問題

FAQ

  • Should I use the sync client or the async one?

    Default to sync (StemSplitter) — that's what the 12-line hello world uses, and it's what fits naturally inside a Django view or a Celery task. Switch to AsyncStemSplitter when you're already on FastAPI, Starlette, or asyncio in a notebook: the method names match (await client.submit, await client.wait, await client.download), so swapping costs one import + one await per call.

  • Does it work with FastAPI and Flask?

    Yes — both are first-class. The Webhooks section above ships runnable handlers for each: FastAPI uses async def webhook(request: Request) with verify_signature; Flask uses a sync @app.post route. Both verify HMAC-SHA256 with one import (from aistemsplitter import verify_signature) and unpack presigned stem URLs from the JSON body without extra parsing.

  • How do I install in a virtualenv or Poetry project?

    Standard tooling: `python -m venv .venv && source .venv/bin/activate && pip install aistemsplitter` for venv; `poetry add aistemsplitter` for Poetry; `uv add aistemsplitter` for uv. The package is pure-Python wheels (no native compilation), so installation completes in seconds on every platform — no pyenv shim, no FFmpeg pre-step, no GPU driver.

  • Will hosted output match my local htdemucs_ft quality?

    Yes. We expose the same model file the open-source community trusts — htdemucs_ft, plus htdemucs and htdemucs_6s — so output is bit-comparable to a local Demucs run with the same model + same input, modulo our managed inference settings (batch size, precision). Pass model='htdemucs_6s' on submit when you need guitar and piano stems.

  • What if I outgrow the typed SDK and need raw HTTP?

    Drop straight to /developers/api. The SDK is a thin typed wrapper over the same REST endpoints the curl quickstart calls, so the auth header (Authorization: Bearer ast_live_…), the webhook signature scheme (HMAC-SHA256 in aistemsplitter-signature), and the response shapes are identical. You can mix-and-match — call submit via the SDK, fetch status via raw httpx for a custom retry policy.

  • How do I handle very long audio without timing out?

    Two strategies. (1) Use webhooks — set webhook_url on submit and skip the polling loop entirely; the API posts results when the job finishes regardless of duration. (2) For files larger than 50 MB, call client.presign_upload() to get a direct-to-storage URL, upload via httpx multipart, then submit with the returned audio_url instead of streaming through our gateway.

  • 我應該使用 sync client 還是 async client?

    預設使用 sync(StemSplitter)——12 行 hello world 用的就是它,也自然適合 Django view 或 Celery task。當你已經在 FastAPI、Starlette 或 notebook 裡的 asyncio 環境中時,再切換到 AsyncStemSplitter:method names 保持一致(await client.submit、await client.wait、await client.download),所以替換成本只有一個 import 加每次呼叫一個 await。

  • 它能搭配 FastAPI 和 Flask 使用嗎?

    可以——兩者都是 first-class。上方 Webhooks 區塊為每個框架提供可執行 handler:FastAPI 使用 async def webhook(request: Request) 搭配 verify_signature;Flask 使用 sync @app.post route。兩者都透過一個 import(from aistemsplitter import verify_signature)驗證 HMAC-SHA256,並從 JSON body 解出 presigned stem URLs,不需額外解析。

  • 如何安裝到 virtualenv 或 Poetry project?

    使用標準工具即可:venv 用 `python -m venv .venv && source .venv/bin/activate && pip install aistemsplitter`;Poetry 用 `poetry add aistemsplitter`;uv 用 `uv add aistemsplitter`。這個 package 是 pure-Python wheels(不需 native compilation),所以每個平台上都能幾秒完成安裝——不需要 pyenv shim、不需要 FFmpeg 預步驟,也不需要 GPU driver。

  • 託管輸出會和我本機 htdemucs_ft 的品質一致嗎?

    會。我們暴露的是開源社群信任的同一個模型檔——htdemucs_ft,以及 htdemucs 和 htdemucs_6s——所以在相同模型和相同輸入下,輸出可以與本機 Demucs 執行結果做 bit-comparable 對比,差異只來自我們的 managed inference settings(batch size、precision)。當你需要 guitar 和 piano stems 時,在 submit 傳 model='htdemucs_6s'。

  • 如果 typed SDK 不夠用、需要 raw HTTP 怎麼辦?

    直接切到 /developers/api。SDK 只是同一套 REST endpoints 上的 thin typed wrapper,也就是 curl quickstart 呼叫的同一套介面,所以 auth header(Authorization: Bearer ast_live_…)、webhook signature scheme(aistemsplitter-signature 中的 HMAC-SHA256)和 response shapes 都完全一致。你可以混用——用 SDK submit,用 raw httpx fetch status 來實作自訂 retry policy。

  • 如何處理很長的音訊,避免 timeout?

    兩種策略。1)使用 webhooks——submit 時設定 webhook_url,完全跳過輪詢迴圈;不論時長多久,API 都會在 job 完成後 POST 結果。2)對於大於 50 MB 的檔案,呼叫 client.presign_upload() 取得 direct-to-storage URL,透過 httpx multipart 上傳,然後用回傳的 audio_url submit,而不是把檔案串流經過我們的 gateway。

/ 下一步

下一步

API reference

完整 REST endpoints、error codes、OpenAPI 3.1 規格。

n8n integration

把一個 node 放進 workflow——不用寫程式碼。

GitHub repo

aistemsplitter 在 PyPI 上的 source、issues、releases。

在 sprint 結束前交付 stem separation。

建立 key 不需信用卡。免費額度涵蓋前 3 分鐘;之後使用永不到期的分鐘包——依購買量不同,每分鐘 $0.08–$0.14。

取得 API 金鑰聯絡團隊
LogoAI Stem Splitter

使用這個模板,更快上線你的下一個 AI 產品。

GitHubDiscordEmail
產品
  • 功能
  • 價格
  • 常見問題
免費工具
  • 調性識別
  • Nightcore Maker
  • Pitch Changer 變調工具
  • Slowed Reverb 製作器
  • TikTok Voice 生成器
AI 工具
  • AI Vocal Removal
  • Acapella 人聲提取器
  • 吉他移除器
  • YouTube 與 SoundCloud 人聲移除器
  • Karaoke Maker
  • AI 鼓聲去除器
  • Voice Isolator
替代方案
  • Lalal.ai 替代方案
  • Splitter.ai alternative
  • VocalRemover 替代方案
資源
  • 博客
  • API
開發者
  • API 參考文件
  • SDKs
  • 取得 API 金鑰
整合
  • n8n 整合
信任背書
  • Stripe Climate
  • Product Hunt
法律
  • Cookie政策
  • 隱私政策
  • 服務條款
BadgeBadge
BadgeBadge
BadgeBadge
BadgeBadge
© 2026 AI Stem Splitter All Rights Reserved.
LogoAI Stem Splitter
首頁價格
API 參考文件

REST endpoints、驗證、callbacks、OpenAPI 3.1 規格。

SDKs

7 個第一方 SDK(Node、Python、Java、Go、PHP、Swift、Lua)。

取得 API 金鑰

在 Settings → Developer 中產生金鑰。

調性識別

識別速度與音樂調性 — 無需註冊

Nightcore Maker

Nightcore, daycore, or sped-up versions from a YouTube link or upload.

Pitch Changer 變調工具

上下調整音高,不影響速度。

Slowed Reverb 製作器

為 TikTok、Reels 和 slowed 播放清單製作慢速 + 殘響版本。

TikTok Voice 生成器

免費生成短影音 AI 旁白。

AI Vocal Removal

Remove vocals for karaoke tracks, quick acapellas, and six-stem previews from files or supported links

Acapella 人聲提取器

從任何一首歌拉出乾淨的 acapella,做 remix、mashup 或 DJ 剪輯都能用。

吉他移除器

把吉他抽掉,跟真實的樂團一起練 — 人聲、鼓和貝斯都還在。

YouTube 與 SoundCloud 人聲移除器

貼上 YouTube 或 SoundCloud 連結,拆分出人聲、鼓、貝斯、鋼琴、吉他和其他分軌

Karaoke Maker

Remove vocals from a song to make a clean instrumental backing track for sing-alongs, rehearsals, and karaoke nights

AI 鼓聲去除器

上傳一首歌,下載一條無鼓音軌——人聲、貝斯,以及除了鼓以外的所有聲部。

Voice Isolator

從嘈雜訪談、通話、現場錄音和語音備忘中提取 spoken voice。

博客
任務中心