Skip to content

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.

Write sidecars as UTF-8 so non-ASCII text works on any Windows locale

Kana8d172369e71a
diff --git a/scripts/download_weights.py b/scripts/download_weights.py
index 05c4512..44bff21 100644
--- a/scripts/download_weights.py
+++ b/scripts/download_weights.py
@@ -73,6 +73,8 @@ def download_torch(names: list[str]) -> int:
def main(argv: list[str]) -> int:
+ # Windows consoles and pipes may use a legacy code page; never crash on ✓ / →.
+ sys.stdout.reconfigure(errors="replace")
names = argv or ["medium"]
if "all" in names:
names = list(MODELS)
diff --git a/scripts/smoke_test.py b/scripts/smoke_test.py
index d960757..917f25e 100644
--- a/scripts/smoke_test.py
+++ b/scripts/smoke_test.py
@@ -82,6 +82,8 @@ async def run(out_dir: Path) -> None:
def main() -> None:
+ # Windows consoles and pipes may use a legacy code page; never crash on ✓ / →.
+ sys.stdout.reconfigure(errors="replace")
ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
ap.add_argument("--out", type=Path, help="keep outputs in this folder")
args = ap.parse_args()
diff --git a/src/audio_studio_mcp/post.py b/src/audio_studio_mcp/post.py
index 4a4a943..2214f25 100644
--- a/src/audio_studio_mcp/post.py
+++ b/src/audio_studio_mcp/post.py
@@ -74,7 +74,7 @@ def write(path: Path, audio: np.ndarray, sr: int, fmt: str, ogg_quality: float =
def write_sidecar(audio_path: Path, meta: dict) -> Path:
p = audio_path.with_suffix(audio_path.suffix + ".json")
- p.write_text(json.dumps(meta, ensure_ascii=False, indent=2))
+ p.write_text(json.dumps(meta, ensure_ascii=False, indent=2), encoding="utf-8")
return p
diff --git a/src/audio_studio_mcp/server.py b/src/audio_studio_mcp/server.py
index a300e53..98ef101 100644
--- a/src/audio_studio_mcp/server.py
+++ b/src/audio_studio_mcp/server.py
@@ -125,7 +125,7 @@ def _audio_seconds(path: Path) -> float:
def _load_sidecar(path: Path) -> dict | None:
p = path.with_suffix(path.suffix + ".json")
try:
- return json.loads(p.read_text())
+ return json.loads(p.read_text(encoding="utf-8"))
except Exception:
return None
diff --git a/tests/test_server.py b/tests/test_server.py
index 8ff718c..b6b3d77 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -41,7 +41,7 @@ async def test_generate_writes_wav_and_sidecar(fake):
audio, sr = post.read(path)
assert sr == 44100 and audio.shape == (2, 44100)
assert c["raw_peak_dbfs"] > 0 and c["peak_dbfs"] == pytest.approx(-1.0, abs=0.01)
- meta = json.loads(Path(c["metadata"]).read_text())
+ meta = json.loads(Path(c["metadata"]).read_text(encoding="utf-8"))
assert meta["original_idea"] == "ドアがバタンと閉まる"
assert meta["backend"] == "fake" and meta["model"] == "fake-model"
@@ -101,7 +101,7 @@ async def test_process_keeps_source_metadata(fake, tmp_path):
"format": "flac", "sample_rate": 44100})
assert r["channels"] == 1 and r["format"] == "flac" and r["seconds"] == pytest.approx(1.9, abs=0.01)
assert r["peak_dbfs"] == pytest.approx(-1.0, abs=0.01)
- meta = json.loads(Path(r["metadata"]).read_text())
+ meta = json.loads(Path(r["metadata"]).read_text(encoding="utf-8"))
assert meta["source"]["seed"] == 3
@@ -205,3 +205,16 @@ async def test_continue_skips_trailing_silence(fake, tmp_path):
start = fake.requests[-1][1].inpaint_range[0]
assert 3.4 < start < 3.6, start # 4 s of sound - 0.5 s overlap, not the 5 s file end
assert r["region"][0] == round(start, 2)
+
+
+async def test_sidecars_are_utf8_whatever_the_locale(fake):
+ # Windows defaults to a legacy code page (cp1252, cp932, ...) that can't
+ # encode every character a prompt or a processing step may contain.
+ idea = "café ☕ ドアが閉まる — 100 %"
+ r = await call("generate_audio", {"prompt": "door", "duration_seconds": 1, "seed": 1,
+ "title": "utf8", "original_idea": idea})
+ gen = Path(r["candidates"][0]["metadata"])
+ assert json.loads(gen.read_bytes().decode("utf-8"))["original_idea"] == idea
+ p = await call("process_audio", {"input_audio": r["candidates"][0]["path"], "sample_rate": 48000})
+ meta = json.loads(Path(p["metadata"]).read_bytes().decode("utf-8"))
+ assert meta["source"]["original_idea"] == idea and any("→" in s for s in meta["steps"])