Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(build): ship sherpa-onnx without the GPL espeak-ng library (#2340)

Chad Pihabcd9f1a8f74f
diff --git a/CLAUDE.md b/CLAUDE.md
index 51898a6f8..2700793be 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -233,6 +233,7 @@ OpenWhispr is an Electron-based desktop dictation application that uses whisper.
- Uses sherpa-onnx runtime for cross-platform ONNX inference
- Bundled binaries in `resources/bin/sherpa-onnx-{platform}-{arch}`
- Windows: the bundled ONNX Runtime ships as `ow-onnxrt.dll`, not `onnxruntime.dll`. `scripts/download-sherpa-onnx.js` renames it and rewrites the import tables of every sherpa image (`scripts/lib/pe-imports.js`) because Windows 11 ships an older `onnxruntime.dll` in System32 and some loader configurations resolve the bare name to that copy (#2054). `afterPack.js` fails the Windows build if `onnxruntime.dll` is present or `ow-onnxrt.dll` is missing
+ - Uses the upstream `-no-tts` archives and bundles only the three executables plus ONNX Runtime. The TTS builds statically link espeak-ng (GPL-3.0) into `sherpa-onnx-c-api`, and nothing in the app loads the sherpa C/C++ API libraries, so they are not shipped
- INT8 quantized models for efficient CPU inference
- Models stored in `~/.cache/openwhispr/parakeet-models/`
- Server pre-warming on startup when `LOCAL_TRANSCRIPTION_PROVIDER=nvidia` is set
diff --git a/scripts/download-sherpa-onnx.js b/scripts/download-sherpa-onnx.js
index a3dc81ce8..d29091621 100644
--- a/scripts/download-sherpa-onnx.js
+++ b/scripts/download-sherpa-onnx.js
@@ -44,10 +44,13 @@ const MACOS_ARM64_ONNXRUNTIME = {
};
// Binary configurations for each platform
-// Note: macOS uses universal2 builds that work on both arm64 and x64
+// Note: macOS uses universal2 builds that work on both arm64 and x64.
+// The -no-tts archives are built with SHERPA_ONNX_ENABLE_TTS=OFF, so nothing in
+// them links espeak-ng (GPL-3.0), which the TTS builds compile into the C API
+// library. The ASR and diarization executables are the same in both builds.
const BINARIES = {
"darwin-arm64": {
- archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-osx-universal2-shared.tar.bz2`,
+ archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-osx-universal2-shared-no-tts.tar.bz2`,
binaryPath: "sherpa-onnx-offline-websocket-server",
outputName: "sherpa-onnx-ws-darwin-arm64",
onlineBinaryPath: "sherpa-onnx-online-websocket-server",
@@ -57,7 +60,7 @@ const BINARIES = {
libPattern: "*.dylib",
},
"darwin-x64": {
- archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-osx-universal2-shared.tar.bz2`,
+ archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-osx-universal2-shared-no-tts.tar.bz2`,
binaryPath: "sherpa-onnx-offline-websocket-server",
outputName: "sherpa-onnx-ws-darwin-x64",
onlineBinaryPath: "sherpa-onnx-online-websocket-server",
@@ -68,7 +71,7 @@ const BINARIES = {
},
"win32-x64": {
// Since 1.13.4 the Windows assets carry an MSVC runtime/build-type suffix
- archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-win-x64-shared-MD-Release.tar.bz2`,
+ archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-win-x64-shared-MD-Release-no-tts.tar.bz2`,
binaryPath: "sherpa-onnx-offline-websocket-server.exe",
outputName: "sherpa-onnx-ws-win32-x64.exe",
onlineBinaryPath: "sherpa-onnx-online-websocket-server.exe",
@@ -78,7 +81,7 @@ const BINARIES = {
libPattern: "*.dll",
},
"linux-x64": {
- archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-linux-x64-shared.tar.bz2`,
+ archiveName: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-linux-x64-shared-no-tts.tar.bz2`,
binaryPath: "sherpa-onnx-offline-websocket-server",
outputName: "sherpa-onnx-ws-linux-x64",
onlineBinaryPath: "sherpa-onnx-online-websocket-server",
@@ -92,6 +95,9 @@ const BINARIES = {
const BIN_DIR = path.join(__dirname, "..", "resources", "bin");
const VERSIONED_LIB_PATTERN = /^(lib.+?)\.(\d+\.\d+\.\d+)\.(dylib|so|dll)$/;
+// The executables link only ONNX Runtime; the archive's sherpa-onnx C/C++ API
+// libraries are for embedding sherpa-onnx and nothing in the app loads them.
+const SHIPPED_LIBRARY_PATTERN = /^(lib)?onnxruntime/;
const REQUIRED_MACOS_ARCHITECTURES = ["x86_64", "arm64"];
// Both macOS targets install the same libonnxruntime file; lipo needs a macOS host.
@@ -302,6 +308,9 @@ function isCompleteInstall(markerPath, binaryPaths, { platformArch, binDir = BIN
const marker = readInstallMarker(markerPath);
if (marker?.version !== SHERPA_ONNX_VERSION || !Array.isArray(marker?.libraries)) return false;
+ // Same version from a different archive (e.g. the TTS build) must re-extract
+ // so the libraries it left behind get cleaned up.
+ if (marker.archive !== BINARIES[platformArch]?.archiveName) return false;
if (
marker.libraries.some(
(library) => typeof library !== "string" || !fs.existsSync(path.join(binDir, library))
@@ -368,9 +377,23 @@ async function downloadBinary(platformArch, config, isForce = false) {
// Copy shared libraries
const copiedLibraries = [];
if (config.libPattern) {
- const libraries = findLibrariesInDir(extractDir, config.libPattern, {
+ const archiveLibraries = findLibrariesInDir(extractDir, config.libPattern, {
ignoreReadErrors: true,
});
+ const libraries = archiveLibraries.filter((libPath) =>
+ SHIPPED_LIBRARY_PATTERN.test(path.basename(libPath))
+ );
+
+ // Installs before v1.7.6 wrote no marker yet copied every library, so
+ // ownership alone would leave their C API library (espeak-ng) behind.
+ const unshippedNames = new Set(archiveLibraries.map((libPath) => path.basename(libPath)));
+ for (const libPath of libraries) unshippedNames.delete(path.basename(libPath));
+ for (const libName of unshippedNames) {
+ const stalePath = path.join(BIN_DIR, libName);
+ if (!fs.existsSync(stalePath)) continue;
+ fs.rmSync(stalePath, { force: true });
+ console.log(` ${platformArch}: Removed unshipped ${libName}`);
+ }
// Separate versioned and unversioned libraries to create symlinks where possible
// e.g. libonnxruntime.dylib -> libonnxruntime.1.23.2.dylib (saves ~71MB)
@@ -438,6 +461,7 @@ async function downloadBinary(platformArch, config, isForce = false) {
installMarkerPath,
JSON.stringify({
version: SHERPA_ONNX_VERSION,
+ archive: config.archiveName,
libraries: shippedLibraries,
...(isWindowsTarget ? { onnxRuntime: WINDOWS_ONNXRUNTIME_PRIVATE_NAME } : {}),
...(isMacosHostTarget(platformArch) ? { onnxRuntime: MACOS_ARM64_ONNXRUNTIME.marker } : {}),
diff --git a/test/scripts/downloadSherpaOnnx.test.js b/test/scripts/downloadSherpaOnnx.test.js
index b4fe1c2ad..70e037172 100644
--- a/test/scripts/downloadSherpaOnnx.test.js
+++ b/test/scripts/downloadSherpaOnnx.test.js
@@ -178,7 +178,11 @@ test("a win32 marker written before the rename is not a complete install", (t) =
fs.writeFileSync(
marker,
- JSON.stringify({ version: SHERPA_ONNX_VERSION, libraries: [WINDOWS_ONNXRUNTIME_PRIVATE_NAME] })
+ JSON.stringify({
+ version: SHERPA_ONNX_VERSION,
+ archive: BINARIES["win32-x64"].archiveName,
+ libraries: [WINDOWS_ONNXRUNTIME_PRIVATE_NAME],
+ })
);
assert.equal(isCompleteInstall(marker, [exe], options), false);
@@ -186,6 +190,7 @@ test("a win32 marker written before the rename is not a complete install", (t) =
marker,
JSON.stringify({
version: SHERPA_ONNX_VERSION,
+ archive: BINARIES["win32-x64"].archiveName,
libraries: [WINDOWS_ONNXRUNTIME_PRIVATE_NAME],
onnxRuntime: WINDOWS_ONNXRUNTIME_PRIVATE_NAME,
})
@@ -198,19 +203,60 @@ test("Linux markers do not need the onnxRuntime field", (t) => {
const binary = path.join(dir, "sherpa-onnx-ws-linux-x64");
fs.writeFileSync(binary, "");
const marker = path.join(dir, ".sherpa-onnx-linux-x64.json");
- fs.writeFileSync(marker, JSON.stringify({ version: SHERPA_ONNX_VERSION, libraries: [] }));
+ fs.writeFileSync(
+ marker,
+ JSON.stringify({
+ version: SHERPA_ONNX_VERSION,
+ archive: BINARIES["linux-x64"].archiveName,
+ libraries: [],
+ })
+ );
assert.equal(
isCompleteInstall(marker, [binary], { platformArch: "linux-x64", binDir: dir }),
true
);
});
+// Installs from the TTS archive of the same version carry the GPL espeak-ng
+// C API library; they must re-extract so that library is removed.
+test("a marker from a different archive of the same version is not a complete install", (t) => {
+ const dir = makeBinDir(t);
+ const binary = path.join(dir, "sherpa-onnx-ws-linux-x64");
+ fs.writeFileSync(binary, "");
+ const marker = path.join(dir, ".sherpa-onnx-linux-x64.json");
+ fs.writeFileSync(
+ marker,
+ JSON.stringify({
+ version: SHERPA_ONNX_VERSION,
+ archive: `sherpa-onnx-v${SHERPA_ONNX_VERSION}-linux-x64-shared.tar.bz2`,
+ libraries: [],
+ })
+ );
+ assert.equal(
+ isCompleteInstall(marker, [binary], { platformArch: "linux-x64", binDir: dir }),
+ false
+ );
+});
+
+test("every platform downloads the TTS-free sherpa-onnx archive", () => {
+ for (const [platformArch, config] of Object.entries(BINARIES)) {
+ assert.match(config.archiveName, /-no-tts\.tar\.bz2$/, platformArch);
+ }
+});
+
test("a malformed marker is not a complete install", (t) => {
const dir = makeBinDir(t);
const binary = path.join(dir, "sherpa-onnx-ws-linux-x64");
const marker = path.join(dir, ".sherpa-onnx-linux-x64.json");
fs.writeFileSync(binary, "");
- fs.writeFileSync(marker, JSON.stringify({ version: SHERPA_ONNX_VERSION, libraries: [null] }));
+ fs.writeFileSync(
+ marker,
+ JSON.stringify({
+ version: SHERPA_ONNX_VERSION,
+ archive: BINARIES["linux-x64"].archiveName,
+ libraries: [null],
+ })
+ );
assert.equal(
isCompleteInstall(marker, [binary], { platformArch: "linux-x64", binDir: dir }),
@@ -228,13 +274,18 @@ test(
const marker = path.join(dir, ".sherpa-onnx-darwin-arm64.json");
const options = { platformArch: "darwin-arm64", binDir: dir };
- fs.writeFileSync(marker, JSON.stringify({ version: SHERPA_ONNX_VERSION, libraries: [] }));
+ const archive = BINARIES["darwin-arm64"].archiveName;
+ fs.writeFileSync(
+ marker,
+ JSON.stringify({ version: SHERPA_ONNX_VERSION, archive, libraries: [] })
+ );
assert.equal(isCompleteInstall(marker, [binary], options), false);
fs.writeFileSync(
marker,
JSON.stringify({
version: SHERPA_ONNX_VERSION,
+ archive,
libraries: [],
onnxRuntime: MACOS_ARM64_ONNXRUNTIME.marker,
})
@@ -253,7 +304,12 @@ test("a failed macOS upgrade still removes obsolete libraries when retried", asy
);
const markerPath = path.join(binDir, ".sherpa-onnx-darwin-arm64.json");
const obsoleteLibrary = path.join(binDir, "libonnxruntime.1.27.0.dylib");
+ const cApiLibrary = path.join(binDir, "libsherpa-onnx-c-api.dylib");
+ // Installs before v1.7.6 wrote no marker, so the marker below never owned this one.
+ const unownedCxxApiLibrary = path.join(binDir, "libsherpa-onnx-cxx-api.dylib");
fs.writeFileSync(obsoleteLibrary, "old runtime");
+ fs.writeFileSync(cApiLibrary, "old C API with espeak-ng");
+ fs.writeFileSync(unownedCxxApiLibrary, "old C++ API");
fs.copyFileSync(obsoleteLibrary, path.join(binDir, "libonnxruntime.dylib"));
fs.writeFileSync(path.join(binDir, "libllama.dylib"), "unrelated runtime");
for (const binaryPath of binaryPaths) fs.writeFileSync(binaryPath, "old binary");
@@ -261,7 +317,11 @@ test("a failed macOS upgrade still removes obsolete libraries when retried", asy
markerPath,
JSON.stringify({
version: "1.13.4",
- libraries: ["libonnxruntime.1.27.0.dylib", "libonnxruntime.dylib"],
+ libraries: [
+ "libonnxruntime.1.27.0.dylib",
+ "libonnxruntime.dylib",
+ "libsherpa-onnx-c-api.dylib",
+ ],
onnxRuntime: "arm64-1.27.0",
})
);
@@ -300,6 +360,11 @@ test("a failed macOS upgrade still removes obsolete libraries when retried", asy
fs.writeFileSync(path.join(extractDir, name), "new binary");
}
fs.writeFileSync(path.join(extractDir, "libonnxruntime.dylib"), "new runtime");
+ fs.writeFileSync(path.join(extractDir, "libsherpa-onnx-c-api.dylib"), "new C API");
+ fs.writeFileSync(
+ path.join(extractDir, "libsherpa-onnx-cxx-api.dylib"),
+ "new C++ API"
+ );
},
};
}
@@ -319,6 +384,8 @@ test("a failed macOS upgrade still removes obsolete libraries when retried", asy
failDownload = false;
assert.equal(await downloadBinary("darwin-arm64", config), true);
assert.equal(fs.existsSync(obsoleteLibrary), false);
+ assert.equal(fs.existsSync(cApiLibrary), false);
+ assert.equal(fs.existsSync(unownedCxxApiLibrary), false);
assert.equal(fs.readFileSync(path.join(binDir, "libonnxruntime.dylib"), "utf8"), "new runtime");
assert.equal(fs.readFileSync(path.join(binDir, "libllama.dylib"), "utf8"), "unrelated runtime");
});
@@ -331,6 +398,8 @@ test("a failed automatic Windows repair stays incomplete and retries DLL patchin
const binaryPaths = EXE_NAMES.map((name) => path.join(binDir, name));
const markerPath = path.join(binDir, ".sherpa-onnx-win32-x64.json");
const options = { platformArch: "win32-x64", binDir };
+ // A pre-v1.7.6 install: the C API DLL is on disk but no marker owns it.
+ fs.writeFileSync(path.join(binDir, "sherpa-onnx-c-api.dll"), "old C API with espeak-ng");
const sourcePath = require.resolve("../../scripts/download-sherpa-onnx");
const requireFromDownloader = createRequire(sourcePath);
let downloads = 0;
@@ -408,9 +477,11 @@ test("a failed automatic Windows repair stays incomplete and retries DLL patchin
assert.equal(await downloadBinary("win32-x64", config), true);
assert.equal(downloads, 3);
assert.equal(isCompleteInstall(markerPath, binaryPaths, options), true);
- for (const imagePath of [...binaryPaths, path.join(binDir, "sherpa-onnx-c-api.dll")]) {
+ for (const imagePath of binaryPaths) {
const imports = listImportedModules(fs.readFileSync(imagePath));
assert.ok(imports.includes("ow-onnxrt.dll"), imagePath);
assert.ok(!imports.some((name) => name.toLowerCase() === "onnxruntime.dll"), imagePath);
}
+ assert.equal(fs.existsSync(path.join(binDir, "sherpa-onnx-c-api.dll")), false);
+ assert.equal(fs.existsSync(path.join(binDir, "onnxruntime_providers_shared.dll")), true);
});