Local AI BGM and sound effects for Claude Code and any MCP client. Stable Audio 3 on Apple Silicon (MLX) and Windows NVIDIA GPUs (PyTorch). No cloud, no API key.
Python apple-siliconaudio-generationclaude-codecudagame-audiomcpmcp-servermlxmusic-generationpytorchsound-effectsstable-audiowindows
Windows: guide users through the Hugging Face login when an agent installs
Kanab83a8b219219
diff --git a/README.ja.md b/README.ja.mdindex a601541..776bc26 100644--- a/README.ja.md+++ b/README.ja.md@@ -111,7 +111,7 @@ cd audio-studio-mcppowershell -ExecutionPolicy Bypass -File install.ps1```-インストーラーの流れは macOS と同じですが、CUDA 版の PyTorch を導入し、**medium** モデルの公式 PyTorch 版の重み(約 10.4 GB)をダウンロードします。Hugging Face にまだログインしていない場合は、read 権限のアクセストークンを貼り付けるよう求められます([ここで作成](https://huggingface.co/settings/tokens))。最後に登録用のコマンドが表示されます:+インストーラーの流れは macOS と同じですが、CUDA 版の PyTorch を導入し、**medium** モデルの公式 PyTorch 版の重み(約 10.4 GB)をダウンロードします。Hugging Face にまだログインしていない場合は、read 権限のアクセストークンを貼り付けるよう求められます([ここで作成](https://huggingface.co/settings/tokens))。コンソールのない環境(AI エージェントが実行した場合など)では入力を求めず、ログイン手順を表示して止まるので、ログインしてからもう一度実行してください。最後に登録用のコマンドが表示されます:```powershellclaude mcp add --scope user audio-studio -- "C:\path\to\audio-studio-mcp\.venv\Scripts\audio-studio-mcp.exe"@@ -151,7 +151,12 @@ macOS ではダウンロードにログインは不要で、`hf auth login` で> [!TIP]> **エージェントにインストールを任せる。** Claude Code に次の文を貼り付けてください:-> *「https://github.com/kanaworksai-hue/audio-studio-mcp の README に従ってインストールし、MCP サーバーとして登録して。」*+> *「https://github.com/kanaworksai-hue/audio-studio-mcp の README(AI エージェント向けの注意も含めて)に従ってインストールし、MCP サーバーとして登録して。」*+>+> **AI エージェント向けの注意(Windows のみ。macOS はログイン不要):** 重みは利用規約への同意が必要で、ユーザー本人の Hugging Face ログインが要ります。+> - 重みをダウンロードする前に `hf auth whoami` でログイン状態を確認してください(インストーラーを一度実行した後は `.venv\Scripts\hf.exe auth whoami`)。`install.ps1` も確認し、未ログインなら `ACTION NEEDED` を表示して止まります。+> - 未ログイン、またはダウンロードが 401/403 で失敗した(ライセンス未同意、または別のアカウントで同意した)場合は作業を止め、インストーラーが表示した手順をユーザーに伝えてください:無料アカウントを作る、各モデルのページでライセンスに同意する、ユーザー自身のターミナルで `hf auth login` を実行する。終わったと言われてから、インストーラーを再実行します。+> - トークンをチャットに貼るようユーザーに頼まないでください。`-SkipWeights` で回避するのも不可です(後で生成するときに同じエラーで失敗します)。あとは普通に頼むだけです:diff --git a/README.md b/README.mdindex 94bc0d8..6adfb05 100644--- a/README.md+++ b/README.md@@ -104,7 +104,7 @@ cd audio-studio-mcppowershell -ExecutionPolicy Bypass -File install.ps1```-The installer does the same steps as on macOS, but installs PyTorch with CUDA and downloads the official PyTorch checkpoint of the **medium** model (~10.4 GB). If you aren't logged in to Hugging Face yet, it asks for an access token with read permission ([create one here](https://huggingface.co/settings/tokens)). It finishes by printing the command to register the server:+The installer does the same steps as on macOS, but installs PyTorch with CUDA and downloads the official PyTorch checkpoint of the **medium** model (~10.4 GB). If you aren't logged in to Hugging Face yet, it asks for an access token with read permission ([create one here](https://huggingface.co/settings/tokens)). When it runs without a console (for example, started by an AI agent), it never asks: it prints the steps to log in and stops, and you re-run it after logging in. It finishes by printing the command to register the server:```powershellclaude mcp add --scope user audio-studio -- "C:\path\to\audio-studio-mcp\.venv\Scripts\audio-studio-mcp.exe"@@ -144,7 +144,12 @@ On macOS, downloads are anonymous; logging in with `hf auth login` raises Huggin> [!TIP]> **Let your agent install it.** Paste this into Claude Code:-> *"Install https://github.com/kanaworksai-hue/audio-studio-mcp by following its README, then register it as an MCP server."*+> *"Install https://github.com/kanaworksai-hue/audio-studio-mcp by following its README, including the notes for AI agents, then register it as an MCP server."*+>+> **Notes for AI agents (Windows only; macOS needs no login):** the weights are gated and need the user's own Hugging Face login.+> - Before downloading weights, check the login with `hf auth whoami` (after the first installer run: `.venv\Scripts\hf.exe auth whoami`). `install.ps1` checks it too and stops with `ACTION NEEDED` when nobody is logged in.+> - If the user is not logged in, or the download fails with 401/403 (license not accepted, or accepted with another account), stop and pass the steps the installer printed on to the user: create a free account, accept the license on each model page, then run `hf auth login` in their own terminal. Wait until they say they are done, then re-run the installer.+> - Never ask the user to paste their token into the chat, and don't use `-SkipWeights` to get past this: generation would fail later with the same error.Then just ask:diff --git a/README.zh-CN.md b/README.zh-CN.mdindex ed573cf..7600a9d 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -111,7 +111,7 @@ cd audio-studio-mcppowershell -ExecutionPolicy Bypass -File install.ps1```-安装脚本的步骤和 macOS 相同,区别是会安装带 CUDA 的 PyTorch,并下载 **medium** 模型的官方 PyTorch 权重(约 10.4 GB)。如果还没登录 Hugging Face,它会让你粘贴一个 read 权限的 access token([在这里创建](https://huggingface.co/settings/tokens))。最后同样会打印注册命令:+安装脚本的步骤和 macOS 相同,区别是会安装带 CUDA 的 PyTorch,并下载 **medium** 模型的官方 PyTorch 权重(约 10.4 GB)。如果还没登录 Hugging Face,它会让你粘贴一个 read 权限的 access token([在这里创建](https://huggingface.co/settings/tokens))。在没有控制台的环境里(例如由 AI agent 运行),它不会等待输入,而是打印登录步骤后停止;登录后重新运行即可。最后同样会打印注册命令:```powershellclaude mcp add --scope user audio-studio -- "C:\path\to\audio-studio-mcp\.venv\Scripts\audio-studio-mcp.exe"@@ -151,7 +151,12 @@ macOS 上下载不需要登录,用 `hf auth login` 登录后 Hugging Face 的> [!TIP]> **让 AI 帮你装。** 把这句话贴给 Claude Code:-> *“按照 https://github.com/kanaworksai-hue/audio-studio-mcp 的 README 安装它,并注册成 MCP 服务器。”*+> *“按照 https://github.com/kanaworksai-hue/audio-studio-mcp 的 README(包括写给 AI agent 的说明)安装它,并注册成 MCP 服务器。”*+>+> **写给 AI agent 的说明(仅 Windows;macOS 不需要登录):** 权重需要同意许可,必须用用户本人的 Hugging Face 账号登录。+> - 下载权重前先用 `hf auth whoami` 检查登录状态(安装脚本运行过一次后用 `.venv\Scripts\hf.exe auth whoami`)。`install.ps1` 也会检查,未登录时会打印 `ACTION NEEDED` 并停止。+> - 如果未登录,或下载因 401/403 失败(没同意许可,或用别的账号同意的),请停下来,把安装脚本打印的步骤转告用户:注册免费账号、在每个模型页面同意许可、在用户自己的终端里运行 `hf auth login`。等用户说完成后,再重新运行安装脚本。+> - 不要让用户把 token 贴到聊天里,也不要用 `-SkipWeights` 绕过去:之后生成时会因为同样的错误失败。然后直接提要求就行:diff --git a/install.ps1 b/install.ps1index 80d2384..2c2e30f 100644--- a/install.ps1+++ b/install.ps1@@ -6,6 +6,8 @@ Audio Studio MCP installer (Windows + NVIDIA GPU).3. creates .venv\ and installs dependencies (uv sync --extra cuda)4. downloads model weights from Hugging Face (medium: ~10.4 GB). The modelrepos are gated: accept the license on the model page and log in once.+ Without a console (e.g. run by an AI agent) it never asks for a token:+ it prints the steps for the user and stops until they have logged in.5. prints the command that registers the server with Claude CodeUsage (from the repo folder):@@ -13,12 +15,14 @@ Usage (from the repo folder):powershell -ExecutionPolicy Bypass -File install.ps1 -Model all # medium + sm-music + sm-sfxpowershell -ExecutionPolicy Bypass -File install.ps1 -SkipWeights # weights download on first use insteadpowershell -ExecutionPolicy Bypass -File install.ps1 -Yes # don't ask before installing uv+ powershell -ExecutionPolicy Bypass -File install.ps1 -NonInteractive # never prompt (or AUDIO_STUDIO_NONINTERACTIVE=1)#>[CmdletBinding()]param([string]$Model = "medium",[switch]$SkipWeights,[Alias("y")][switch]$Yes,+ [switch]$NonInteractive,[switch]$Help)@@ -47,6 +51,10 @@ function Have($cmd) { return [bool](Get-Command $cmd -ErrorAction SilentlyContin# Stop if the last native command failed.function Check($what) { if ($LASTEXITCODE -ne 0) { Die "$what failed (exit code $LASTEXITCODE)" } }+# Nobody can type a token when stdin is redirected (an AI agent's shell, CI, a pipe).+$Interactive = -not ($NonInteractive -or $env:AUDIO_STUDIO_NONINTERACTIVE -or+ [Console]::IsInputRedirected -or -not [Environment]::UserInteractive)+$Models = @($Model -split "[,\s]+" | Where-Object { $_ })foreach ($m in $Models) {if (@("medium", "sm-music", "sm-sfx", "all") -notcontains $m) {@@ -139,23 +147,61 @@ if ($cuda) { Ok ".venv ready (CUDA: $cuda)" } else { Ok ".venv ready"; Warn "PyT# -- weights ------------------------------------------------------------------$env:PYTHONIOENCODING = "utf-8"$Hf = Join-Path $RepoDir ".venv\Scripts\hf.exe"+$repos = @{ "medium" = "stable-audio-3-medium"; "sm-music" = "stable-audio-3-small-music"; "sm-sfx" = "stable-audio-3-small-sfx" }+if ($Models -contains "all") { $names = @("medium", "sm-music", "sm-sfx") } else { $names = $Models }++# The one-time Hugging Face setup, worded so an AI agent can pass it on as is.+function HfSteps {+ Write-Host " 1. Create a free Hugging Face account (skip if you have one):"+ Write-Host " https://huggingface.co/join"+ Write-Host " 2. Log in on huggingface.co, open each model page below and accept the"+ Write-Host " Stability AI Community License (fill in the short form and submit):"+ foreach ($n in $names) { Write-Host " https://huggingface.co/stabilityai/$($repos[$n])" }+ Write-Host " 3. Create an access token with Read permission:"+ Write-Host " https://huggingface.co/settings/tokens"+ Write-Host " Then, in your own PowerShell window (not in a chat), run this and paste the token:"+ Write-Host " & `"$Hf`" auth login"+ Write-Host " Use the same account as in step 2. Never paste the token into a chat."+ Write-Host " 4. Run the installer again; it picks up where it stopped:"+ Write-Host " powershell -ExecutionPolicy Bypass -File `"$PSCommandPath`""+}+if ($SkipWeights) {Step "Skipping weights"Warn "the first generation will download them (medium: ~10.4 GB) and can take a long time."- Warn "The model repos are gated: accept the license and run '$Hf auth login' first."+ Warn "The model repos are gated: generation fails with 401/403 until you have done this once:"+ HfSteps} else {- $repos = @{ "medium" = "stable-audio-3-medium"; "sm-music" = "stable-audio-3-small-music"; "sm-sfx" = "stable-audio-3-small-sfx" }- if ($Models -contains "all") { $names = @("medium", "sm-music", "sm-sfx") } else { $names = $Models }Step "Downloading model weights: $($names -join ', ')"Write-Host " The weights are licensed under the Stability AI Community License and the repos are"Write-Host " gated. If you have not yet, open each page, log in and accept the license:"foreach ($n in $names) { Write-Host " https://huggingface.co/stabilityai/$($repos[$n])" }& $Hf auth whoami *> $nullif ($LASTEXITCODE -ne 0) {+ if (-not $Interactive) {+ Write-Host ""+ Write-Host "ACTION NEEDED: log in to Hugging Face" -ForegroundColor Yellow+ Write-Host " The installer is running without a console (for example, an AI agent started it)"+ Write-Host " and this computer is not logged in to Hugging Face, so it cannot download the"+ Write-Host " model weights. Do this once:"+ Write-Host ""+ HfSteps+ Write-Host ""+ Write-Host " AI agents: stop here and pass these steps on to the user. Wait until they say"+ Write-Host " they have logged in, check with & `"$Hf`" auth whoami and re-run the installer."+ Write-Host " Do not ask for the token in the chat, and do not re-run with -SkipWeights to get"+ Write-Host " past this: generation would then fail with the same error."+ Write-Host ""+ Die "not logged in to Hugging Face (see the steps above)."+ }Write-Host " Then paste a Hugging Face access token (read) below:"Write-Host " https://huggingface.co/settings/tokens"& $Hf auth login- if ($LASTEXITCODE -ne 0) { Die "Hugging Face login failed; re-run the installer or use -SkipWeights." }+ if ($LASTEXITCODE -ne 0) {+ Write-Host ""+ HfSteps+ Die "Hugging Face login failed (see the steps above)."+ }}$env:AUDIO_STUDIO_SA3_DIR = $UpstreamDir& $Py (Join-Path $RepoDir "scripts\download_weights.py") @namesdiff --git a/scripts/download_weights.py b/scripts/download_weights.pyindex 44bff21..a6e9632 100644--- a/scripts/download_weights.py+++ b/scripts/download_weights.py@@ -53,20 +53,68 @@ def download_mlx(names: list[str]) -> int:return 0+def hf_account() -> str | None:+ """The Hugging Face user this machine is logged in as (like `hf auth whoami`)."""+ from huggingface_hub import whoami+ try:+ return whoami()["name"]+ except Exception:+ return None+++def gated_help(repos: list[str], account: str | None) -> str:+ """Why a gated download failed and what the user has to do, worded so an AI+ agent running the installer can pass it on as is."""+ hf = Path(sys.executable).with_name("hf.exe" if os.name == "nt" else "hf")+ pages = "".join(f"\n https://huggingface.co/{r}" for r in repos)+ if account:+ head = (f"error: the Hugging Face account '{account}' (hf auth whoami) has no access to\n"+ "these gated model repos yet. Either the license was not accepted on them, or it\n"+ "was accepted with a different account.\n\n"+ f" 1. Log in on huggingface.co as '{account}', open each page and accept the\n"+ f" Stability AI Community License (fill in the short form and submit):{pages}\n"+ " To use another account instead, log in with it in your own terminal:\n"+ f" \"{hf}\" auth login\n")+ else:+ head = ("error: not logged in to Hugging Face, so these gated model repos cannot be\n"+ "downloaded.\n\n"+ " 1. Create a free account (https://huggingface.co/join), log in on huggingface.co,\n"+ " open each page and accept the Stability AI Community License:"+ f"{pages}\n"+ " Then create a Read token (https://huggingface.co/settings/tokens) and, in your\n"+ " own terminal (not in a chat), run this and paste the token:\n"+ f" \"{hf}\" auth login\n")+ return (head ++ " 2. Run the installer again; finished downloads are kept.\n\n"+ "AI agents: pass these steps on to the user and wait until they are done. Do not ask\n"+ "for the token in the chat, and do not skip the weights to get past this.")++def download_torch(names: list[str]) -> int:- from huggingface_hub import snapshot_download+ from huggingface_hub import auth_check, snapshot_downloadfrom huggingface_hub.errors import GatedRepoError+ # Check every repo first, so the user can accept all the licenses in one go.+ gated = []+ for name in names:+ repo = TORCH_REPOS[name][0]+ try:+ auth_check(repo)+ except GatedRepoError:+ gated.append(repo)+ except Exception:+ pass # offline etc.: let snapshot_download decide+ if gated:+ print(gated_help(gated, hf_account()), file=sys.stderr)+ return 2+for name in names:repo, size = TORCH_REPOS[name]print(f"[{name}] {repo} ({size})")try:path = snapshot_download(repo, allow_patterns=TORCH_FILES)except GatedRepoError:- print(f"\nerror: {repo} is gated. Open this page, log in and accept the\n"- f"Stability AI Community License:\n https://huggingface.co/{repo}\n"- "then log in here once (hf auth login, with a read token) and re-run.",- file=sys.stderr)+ print(gated_help([repo], hf_account()), file=sys.stderr)return 2print(f" ✓ {path}")return 0