dsh-line-bot 0.9.6 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env python3
2
+ """One-shot MLX CosyVoice3 synthesis helper for dsh-line-bot.
3
+
4
+ Reads a JSON job file, synthesizes one WAV, and prints a single
5
+ `RESULT:{...}` line on stdout so the Node side can parse it.
6
+ """
7
+ import glob
8
+ import json
9
+ import os
10
+ import sys
11
+ import traceback
12
+
13
+
14
+ def emit(payload):
15
+ sys.stdout.write("RESULT:" + json.dumps(payload, ensure_ascii=False) + "\n")
16
+ sys.stdout.flush()
17
+
18
+
19
+ def main():
20
+ if len(sys.argv) < 2:
21
+ emit({"ok": False, "error": "missing job file"})
22
+ return 2
23
+ with open(sys.argv[1], "r", encoding="utf-8") as handle:
24
+ job = json.load(handle)
25
+
26
+ prefix = job.get("prefix") or "tts"
27
+ os.makedirs(os.path.dirname(prefix) or ".", exist_ok=True)
28
+
29
+ try:
30
+ from mlx_audio.tts.generate import generate_audio
31
+
32
+ kwargs = {
33
+ "text": job["text"],
34
+ "model": job.get("model") or "mlx-community/Fun-CosyVoice3-0.5B-2512-8bit",
35
+ "ref_audio": job.get("refAudio"),
36
+ "file_prefix": prefix,
37
+ "audio_format": "wav",
38
+ "verbose": False,
39
+ "join_audio": True,
40
+ }
41
+ if job.get("instructText"):
42
+ kwargs["instruct_text"] = job["instructText"]
43
+ elif job.get("refText"):
44
+ kwargs["ref_text"] = job["refText"]
45
+ generate_audio(**kwargs)
46
+
47
+ candidates = sorted(glob.glob(prefix + "*.wav"), key=os.path.getmtime)
48
+ if not candidates:
49
+ emit({"ok": False, "error": "no output wav produced"})
50
+ return 1
51
+ emit({"ok": True, "file": candidates[-1]})
52
+ return 0
53
+ except Exception as exc: # noqa: BLE001
54
+ traceback.print_exc(file=sys.stderr)
55
+ emit({"ok": False, "error": str(exc)})
56
+ return 1
57
+
58
+
59
+ if __name__ == "__main__":
60
+ raise SystemExit(main())