@acpfx/tts-pocket 0.2.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.
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@acpfx/tts-pocket",
3
+ "version": "0.2.0",
4
+ "description": "Local TTS via Pocket TTS (on-device, Rust/Candle, CPU-capable)",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/thisnick/acpfx",
8
+ "directory": "packages/node-tts-pocket"
9
+ },
10
+ "license": "ISC",
11
+ "bin": {
12
+ "acpfx-tts-pocket": "./bin/tts-pocket"
13
+ },
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "files": [
18
+ "bin/",
19
+ "scripts/"
20
+ ],
21
+ "scripts": {
22
+ "build:native": "cargo build --release -p node-tts-pocket && mkdir -p bin && cp target/release/tts-pocket bin/",
23
+ "postinstall": "node scripts/postinstall.js"
24
+ }
25
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+
3
+ const https = require("https");
4
+ const http = require("http");
5
+ const fs = require("fs");
6
+ const path = require("path");
7
+
8
+ const SUPPORTED_PLATFORMS = {
9
+ "darwin arm64": "tts-pocket-darwin-arm64",
10
+ "darwin x64": "tts-pocket-darwin-x64",
11
+ "linux x64": "tts-pocket-linux-x64",
12
+ "win32 x64": "tts-pocket-win32-x64.exe",
13
+ };
14
+
15
+ function hasNvidiaGpu() {
16
+ try {
17
+ require("child_process").execSync("nvidia-smi", { stdio: "ignore" });
18
+ return true;
19
+ } catch {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ function getBinaryName() {
25
+ const key = `${process.platform} ${process.arch}`;
26
+ const base = SUPPORTED_PLATFORMS[key];
27
+ if (!base) {
28
+ throw new Error(
29
+ `Unsupported platform: ${process.platform} ${process.arch}.\n` +
30
+ `Supported: ${Object.keys(SUPPORTED_PLATFORMS).join(", ")}`
31
+ );
32
+ }
33
+
34
+ // Try CUDA variant on Linux/Windows when an NVIDIA GPU is present
35
+ if ((process.platform === "linux" || process.platform === "win32") && hasNvidiaGpu()) {
36
+ return base.replace(/(\.\w+)?$/, "-cuda$1");
37
+ }
38
+ return base;
39
+ }
40
+
41
+ function fetch(url) {
42
+ return new Promise((resolve, reject) => {
43
+ const lib = url.startsWith("https") ? https : http;
44
+ lib
45
+ .get(url, { headers: { "User-Agent": "tts-pocket-postinstall" } }, (res) => {
46
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
47
+ return fetch(res.headers.location).then(resolve, reject);
48
+ }
49
+ if (res.statusCode !== 200) {
50
+ reject(new Error(`HTTP ${res.statusCode} for ${url}`));
51
+ res.resume();
52
+ return;
53
+ }
54
+ const chunks = [];
55
+ res.on("data", (chunk) => chunks.push(chunk));
56
+ res.on("end", () => resolve(Buffer.concat(chunks)));
57
+ res.on("error", reject);
58
+ })
59
+ .on("error", reject);
60
+ });
61
+ }
62
+
63
+ async function main() {
64
+ const pkg = require("../package.json");
65
+ const version = pkg.version;
66
+ const binaryName = getBinaryName();
67
+ const binDir = path.join(__dirname, "..", "bin");
68
+ const destPath = path.join(binDir, binaryName);
69
+
70
+ if (fs.existsSync(destPath)) {
71
+ console.log(`tts-pocket: binary already exists at ${destPath}, skipping download.`);
72
+ return;
73
+ }
74
+
75
+ const url = `https://github.com/thisnick/acpfx/releases/download/%40acpfx/tts-pocket%40${version}/${binaryName}`;
76
+ console.log(`tts-pocket: downloading ${binaryName} from GitHub Releases...`);
77
+ console.log(` ${url}`);
78
+
79
+ let data;
80
+ try {
81
+ data = await fetch(url);
82
+ } catch (err) {
83
+ // If CUDA variant failed, fall back to CPU binary
84
+ const cpuName = SUPPORTED_PLATFORMS[`${process.platform} ${process.arch}`];
85
+ if (binaryName !== cpuName) {
86
+ console.log(`tts-pocket: CUDA binary not available, falling back to CPU variant...`);
87
+ const cpuUrl = `https://github.com/thisnick/acpfx/releases/download/%40acpfx/tts-pocket%40${version}/${cpuName}`;
88
+ console.log(` ${cpuUrl}`);
89
+ data = await fetch(cpuUrl);
90
+ } else {
91
+ throw err;
92
+ }
93
+ }
94
+ fs.mkdirSync(binDir, { recursive: true });
95
+ fs.writeFileSync(destPath, data);
96
+ fs.chmodSync(destPath, 0o755);
97
+ console.log(`tts-pocket: installed ${binaryName} (${(data.length / 1024 / 1024).toFixed(1)} MB)`);
98
+ }
99
+
100
+ main().catch((err) => {
101
+ console.warn(`tts-pocket: postinstall failed — ${err.message}`);
102
+ console.warn(
103
+ "tts-pocket: the native binary could not be downloaded. " +
104
+ "You can build locally with: cargo build --release -p node-tts-pocket"
105
+ );
106
+ });