From ff8b42735314cc507f12dac8a94da175fbb478ac Mon Sep 17 00:00:00 2001
From: sakasegawa
Date: Sat, 21 Nov 2026 01:23:26 +0900
Subject: [PATCH] Build the WebAssembly archive in CI and publish it with each
release
A wasm job builds both WebAssembly modules with the Emscripten of emsdk's
tag 7.0.0, pinned by its commit, and packs them with speech.mjs, wav.mjs, the
page, serve.py and speech.h into speech--wasm.zip, which the release
job now waits for and publishes beside the other archives, summed in
SHA256SUMS. The job checks the archive as a page serves it: in a headless
Chrome the page opens cross-origin isolated, and both modules start in a
Worker and give the release. CI runs no check that needs a model, so this is
the smoke's new --started, which takes no model and needs no native speech.
The installers choose their archive by name and are unchanged.
docs/install.md lists the archive and what it holds, docs/browser.md says
where to get it, README.md and README.ja.md point to it and have a badge, and
the release skill checks the published archive with Silero VAD, with threads
and without.
Checked: wasm_browser_smoke.mjs --started on a folder laid out as the
archive, which fails when it is given another release; the full smoke on the
same folder with and without --threads 4. The workflow parses as YAML; the
job runs in this pull request's CI.
Co-Authored-By: Claude Opus 5.5
---
.github/workflows/build.yml | 60 ++++++++-
AGENTS.md | 3 +-
README.ja.md | 3 +-
README.md | 4 +-
checks/smoke/wasm_browser_smoke.mjs | 200 +++++++++++++++-------------
docs/browser.md | 7 +-
docs/install.md | 5 +
skills/release/SKILL.md | 6 +-
8 files changed, 187 insertions(+), 101 deletions(-)
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index e6b9bcdd..e01ddf9e 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -16,10 +16,10 @@ on:
type: boolean
default: false
-# Each platform's job builds speech, the one executable, and libspeech, and packs them with speech.h into the archive
-# a release publishes, speech--.zip, on every run: a pull request shows the archive a tag would
-# release, and the release job publishes the same files. The checks are built to keep them compiling, and released in
-# no archive.
+# Each platform's job builds speech, the one executable, and libspeech, or for browsers the library in WebAssembly, and
+# packs them with speech.h into the archive a release publishes, speech--.zip, on every run: a pull
+# request shows the archive a tag would release, and the release job publishes the same files. The checks are built to
+# keep them compiling, and released in no archive.
jobs:
macos-metal:
runs-on: macos-15
@@ -279,6 +279,54 @@ jobs:
name: speech-linux-x64-${{ matrix.backend }}
path: ${{ env.ARCHIVE }}
+ # The WebAssembly build for browsers, on one thread and with threads, packed with the module, the page and the server
+ # that go beside it and speech.h into speech--wasm.zip. emsdk at the commit of its tag pins the Emscripten it
+ # downloads, and its node runs the check.
+ wasm:
+ runs-on: ubuntu-22.04
+ env:
+ EMSDK_VERSION: 7.0.0
+ EMSDK_COMMIT: 1693ce7359fc9694f198694f902a2cc061239b86
+ steps:
+ - uses: actions/checkout@v6
+ with:
+ submodules: recursive
+ - name: Install Emscripten
+ run: |
+ git clone --quiet https://github.com/emscripten-core/emsdk.git "$RUNNER_TEMP/emsdk"
+ git -C "$RUNNER_TEMP/emsdk" checkout --quiet "$EMSDK_COMMIT"
+ "$RUNNER_TEMP/emsdk/emsdk" install "$EMSDK_VERSION"
+ "$RUNNER_TEMP/emsdk/emsdk" activate "$EMSDK_VERSION"
+ - name: Build
+ run: |
+ source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
+ emcmake cmake -B build-wasm -DCMAKE_BUILD_TYPE=Release
+ cmake --build build-wasm -j 4
+ emcmake cmake -B build-wasm-threads -DCMAKE_BUILD_TYPE=Release -DSPEECH_WASM_THREADS=ON
+ cmake --build build-wasm-threads -j 4
+ - name: Package
+ run: |
+ archive="speech-$(cat VERSION)-wasm.zip"
+ mkdir package
+ cp build-wasm/libspeech.js build-wasm/libspeech.wasm build-wasm-threads/libspeech-threads.js \
+ build-wasm-threads/libspeech-threads.wasm build-wasm/speech.mjs build-wasm/wav.mjs build-wasm/worker.mjs \
+ build-wasm/page.mjs build-wasm/index.html build-wasm/serve.py include/speech.h package/
+ (cd package && zip -q "../$archive" *)
+ echo "ARCHIVE=$archive" >> "$GITHUB_ENV"
+ # The archive as a page serves it: in a headless Chrome the page opens cross-origin isolated, and both modules
+ # start and give the release.
+ - name: Check the archive
+ run: |
+ source "$RUNNER_TEMP/emsdk/emsdk_env.sh"
+ mkdir unpacked
+ unzip -q "$ARCHIVE" -d unpacked
+ ls -l unpacked
+ CHROME=$(command -v google-chrome) node checks/smoke/wasm_browser_smoke.mjs --started unpacked "$(cat VERSION)"
+ - uses: actions/upload-artifact@v4
+ with:
+ name: speech-wasm
+ path: ${{ env.ARCHIVE }}
+
# install.sh as a user runs it, against the published releases, in home folders of the job's own: a first install of
# an earlier release, an update to the latest that removes it, a run that finds it installed, a build of another
# archive of the same version replaced, the line it adds to PATH once however often it runs, and an archive whose
@@ -360,7 +408,7 @@ jobs:
release:
if: startsWith(github.ref, 'refs/tags/v')
- needs: [macos-metal, windows-vulkan, linux]
+ needs: [macos-metal, windows-vulkan, linux, wasm]
runs-on: ubuntu-latest
permissions:
contents: write
@@ -390,4 +438,4 @@ jobs:
run: |
gh release create "$GITHUB_REF_NAME" dist/*.zip dist/SHA256SUMS --repo "$GITHUB_REPOSITORY" \
--title "$GITHUB_REF_NAME" --generate-notes \
- --notes "speech, speech.cpp's one executable (tts, asr, vad, diarize, enhance, talk, serve, worker, models, pull, rm, info, voice, quantize, devices and update), and the shared library libspeech with its C API, speech.h, in one archive for each of macOS arm64 (Metal), Windows x64 (Vulkan) and Linux x64 (Vulkan, and the CPU alone; glibc 2.34 or later). The README lists the model families and where their converted weights are on Hugging Face."
+ --notes "speech, speech.cpp's one executable (tts, asr, vad, diarize, enhance, talk, serve, worker, models, pull, rm, info, voice, quantize, devices and update), and the shared library libspeech with its C API, speech.h, in one archive for each of macOS arm64 (Metal), Windows x64 (Vulkan) and Linux x64 (Vulkan, and the CPU alone; glibc 2.34 or later), and the library in WebAssembly for web pages, with Silero VAD, in speech--wasm.zip. The README lists the model families and where their converted weights are on Hugging Face."
diff --git a/AGENTS.md b/AGENTS.md
index 955e17ba..c2922f2f 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -117,7 +117,8 @@ README.md and `docs/` are the documentation for users; what a developer needs is
it, `server_openai_smoke.py` the server through the official openai-python client,
`speech_cli_smoke.py` the command line against the worker, `models_smoke.py` the naming, fetching and removing of
models against a temporary model folder, and `wasm_browser_smoke.mjs` the WebAssembly build through its page in a
- headless Chrome against `speech vad`. A script that needs packages outside the standard library is a uv script
+ headless Chrome against `speech vad`, or with `--started`, as CI checks the archive without a model, that its modules
+ start. A script that needs packages outside the standard library is a uv script
with its dependencies pinned in the script and in a lock file beside it.
- `reference//` holds, per model, a uv environment that pins the official code, PyTorch and the rest,
`pins.py`, which pins the checkpoints by revision, the conversion of the official weights to one GGUF file per
diff --git a/README.ja.md b/README.ja.md
index bff1fb86..bd39e925 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -22,6 +22,7 @@
+
@@ -85,7 +86,7 @@ x64 の Windows では、PowerShell で次のコマンドを実行します。
irm https://raw.githubusercontent.com/nyosegawa/speech.cpp/main/install.ps1 | iex
```
-インストーラはリリースのアーカイブを SHA-256 で確かめ、`speech` をホームフォルダの下に置き、`PATH` に加えます。`speech update` を実行するか、インストーラをもう一度実行すると更新されます。Linux では、Vulkan のローダーが入っていれば Vulkan 版を、入っていなければ CPU 版をインストールします。Linux 版には glibc 2.34 以降が必要です。オプション、アンインストールの方法、各プラットフォームで必要なものは [docs/install.md](docs/install.md) にあります。Intel Mac やその他のシステムでは、[ソースからビルド](docs/install.md#build-from-source)してください。
+インストーラはリリースのアーカイブを SHA-256 で確かめ、`speech` をホームフォルダの下に置き、`PATH` に加えます。`speech update` を実行するか、インストーラをもう一度実行すると更新されます。Linux では、Vulkan のローダーが入っていれば Vulkan 版を、入っていなければ CPU 版をインストールします。Linux 版には glibc 2.34 以降が必要です。オプション、アンインストールの方法、各プラットフォームで必要なものは [docs/install.md](docs/install.md) にあります。Intel Mac やその他のシステムでは、[ソースからビルド](docs/install.md#build-from-source)してください。ウェブページで使うために、各リリースには WebAssembly にしたライブラリーの `speech--wasm.zip` があり、ブラウザの中で Silero VAD を動かせます([docs/browser.md](docs/browser.md))。
## クイックスタート
diff --git a/README.md b/README.md
index b01a5878..61af7992 100644
--- a/README.md
+++ b/README.md
@@ -22,6 +22,7 @@
+
@@ -102,7 +103,8 @@ The installer checks the release's archive against its SHA-256, puts `speech` un
`PATH`. `speech update`, or running it again, updates it. On Linux it installs the Vulkan build when the Vulkan loader
is installed, and the CPU build otherwise; the Linux builds need glibc 2.34 or later. [docs/install.md](docs/install.md)
has the options, how to uninstall, and what each platform needs. On an Intel Mac or another system, [build from
-source](docs/install.md#build-from-source).
+source](docs/install.md#build-from-source). For a web page, each release has the library in WebAssembly,
+`speech--wasm.zip`, which runs Silero VAD inside the browser ([docs/browser.md](docs/browser.md)).
## Quick start
diff --git a/checks/smoke/wasm_browser_smoke.mjs b/checks/smoke/wasm_browser_smoke.mjs
index b4a6936a..8e8a9e06 100644
--- a/checks/smoke/wasm_browser_smoke.mjs
+++ b/checks/smoke/wasm_browser_smoke.mjs
@@ -6,22 +6,27 @@
// the model, the RTFx of each file and the most memory the module held. The page is served from 127.0.0.1 with COOP and
// COEP, which the build with threads needs, and the files given at /files/. With --threads N the page runs the build
// with threads on N threads, and audio of more than its 1 GB must be refused as out_of_memory before the module writes
-// it, after which the module still answers. Chrome is the one at $CHROME, or macOS's; the server and Chrome are stopped
-// however the script ends.
+// it, after which the module still answers. With --started, which needs no model, as CI checks a release's archive, the
+// page must open cross-origin isolated and both modules start in a Worker and give the release named. Chrome is the one
+// at $CHROME, or macOS's; the server and Chrome are stopped however the script ends.
// usage: node checks/smoke/wasm_browser_smoke.mjs ... [--threads N]
+// node checks/smoke/wasm_browser_smoke.mjs --started
import { spawn, execFileSync } from 'node:child_process';
import fs from 'node:fs';
import http from 'node:http';
import os from 'node:os';
import path from 'node:path';
+const usage = 'usage: node checks/smoke/wasm_browser_smoke.mjs ... [--threads N, 2 or more]\n'
+ + ' node checks/smoke/wasm_browser_smoke.mjs --started ';
const argv = process.argv.slice(2);
+const started = argv[0] === '--started' ? { build: argv[1], release: argv[2] } : null;
const threadsAt = argv.indexOf('--threads');
const threads = threadsAt >= 0 ? Number(argv[threadsAt + 1]) : null;
if (threadsAt >= 0) argv.splice(threadsAt, 2);
-const [speech, build, model, ...audio] = argv;
-if (!audio.length || (threadsAt >= 0 && !(threads > 1))) {
- console.error('usage: node checks/smoke/wasm_browser_smoke.mjs ... [--threads N, 2 or more]');
+const [speech, build, model, ...audio] = started ? [null, started.build, null] : argv;
+if (started ? argv.length !== 3 || threadsAt >= 0 : !audio.length || (threadsAt >= 0 && !(threads > 1))) {
+ console.error(usage);
process.exit(2);
}
const library = threads ? 'libspeech-threads' : 'libspeech';
@@ -89,15 +94,16 @@ const running = [];
let ws = null;
let server = null;
try {
- for (const file of [`${library}.js`, `${library}.wasm`, 'speech.mjs', 'index.html']) {
+ const libraries = started ? ['libspeech', 'libspeech-threads'] : [library];
+ for (const file of [...libraries.flatMap((l) => [`${l}.js`, `${l}.wasm`]), 'speech.mjs', 'index.html']) {
if (!fs.existsSync(path.join(build, file))) {
throw new Error(`${build} has no ${file}; build it with emcmake cmake${threads ? ' -DSPEECH_WASM_THREADS=ON' : ''} and cmake --build`);
}
}
- const lines = execFileSync(speech, ['vad', model, '--format', 'json', ...audio], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] });
- const native = lines.trim().split('\n').map((line) => JSON.parse(line).regions);
+ const native = started ? null : execFileSync(speech, ['vad', model, '--format', 'json', ...audio], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'inherit'] })
+ .trim().split('\n').map((line) => JSON.parse(line).regions);
- const files = [model, ...audio].map((f) => path.resolve(f));
+ const files = started ? [] : [model, ...audio].map((f) => path.resolve(f));
server = serve(files);
await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve));
const origin = `http://127.0.0.1:${server.address().port}`;
@@ -155,92 +161,106 @@ try {
const isolated = await page('return crossOriginIsolated;');
if (!isolated) throw new Error('the page is not cross-origin isolated, though the server sends COOP and COEP');
- const run = (args) => page(`return await speechPage.run(${args}).catch(failure);`);
- const on = threads ? `, threads: ${threads}` : '';
- const all = `{ model: ${JSON.stringify(urls[0])}, audio: ${JSON.stringify(urls.slice(1))}${on} }`;
- const first = await run(all);
- if (first.error) throw new Error(`the page failed: ${JSON.stringify(first.error)}`);
- const differs = departure(first.detections, native);
- if (differs) throw new Error(differs);
- if (first.info.threads !== (threads ?? 1)) throw new Error(`the model computes with ${first.info.threads} threads, where ${threads ?? 1} were asked for`);
- console.log(`speech.cpp ${first.version}, ${library}: the module started in ${first.open.toFixed(1)} ms, and ${first.info.name} `
- + `${first.info.weight_type} loaded in ${first.load.toFixed(1)} ms on ${first.info.threads} threads`);
- first.detections.forEach((d, f) => {
- console.log(`${path.basename(audio[f])}: ${d.regions.length} regions as speech vad finds them, ${d.seconds.toFixed(2)} s of audio in `
- + `${d.ms.toFixed(1)} ms, RTFx ${(d.seconds / (d.ms / 1000)).toFixed(0)}`);
- });
- console.log(`the module's memory: ${(first.memory / 2 ** 20).toFixed(1)} MiB at most`);
-
- const one = `audio: ${JSON.stringify(urls.slice(1, 2))}${on}`;
- // One thread more than the build starts: 2 without threads, or one past the browser's logical processors with them.
- const most = threads ? await page('return navigator.hardwareConcurrency;') : 1;
- const many = await run(`{ model: ${JSON.stringify(urls[0])}, audio: ${JSON.stringify(urls.slice(1, 2))}, threads: ${most + 1}, threaded: ${!!threads} }`);
- if (many.error?.status !== 'invalid_argument' || many.error.option !== 'threads') {
- throw new Error(`${most + 1} threads in ${library}: ${JSON.stringify(many)}, where invalid_argument naming threads was due`);
- }
- console.log(`${most + 1} threads refused: ${many.error.status} (${many.error.option}): ${many.error.message}`);
- // The model cut in half is loaded while a run of the whole one is under way, which must keep its own model. Both are
- // Blobs at hand, so that the second load reaches the Worker before the first run's detection.
- const [whole, cut] = await page(`
- const whole = await (await fetch(${JSON.stringify(urls[0])})).blob();
- const model = new File([whole.slice(0, Math.floor(whole.size / 2))], 'cut.gguf');
- return await Promise.all([
- speechPage.run({ model: new File([whole], 'whole.gguf'), ${one} }).catch(failure),
- speechPage.run({ model, ${one} }).catch(failure),
- ]);
+ /**
+ * The first message of a module Worker made in the page from `body`, which follows an import of openSpeech from the
+ * page's speech.mjs, after it is given `message`, an expression evaluated in the page.
+ */
+ const inWorker = (body, message) => page(`
+ const source = 'import { openSpeech } from ' + JSON.stringify(location.origin + '/speech.mjs') + ';' + ${JSON.stringify(body)};
+ const worker = new Worker(URL.createObjectURL(new Blob([source], { type: 'text/javascript' })), { type: 'module' });
+ const answer = new Promise((resolve, reject) => {
+ worker.onmessage = ({ data }) => resolve(data);
+ worker.onerror = (e) => reject(new Error(e.message));
+ });
+ worker.postMessage(await (${message}));
+ try {
+ return await answer;
+ } finally {
+ worker.terminate();
+ }
`);
- if (cut.error?.status !== 'model_file') throw new Error(`a model cut in half: ${JSON.stringify(cut)}, where model_file was due`);
- if (whole.error) throw new Error(`a run with a model cut in half after it failed: ${JSON.stringify(whole.error)}`);
- const differsBeside = departure(whole.detections, native.slice(0, 1));
- if (differsBeside) throw new Error(`a run with a model cut in half after it: ${differsBeside}`);
- console.log(`a model cut in half refused: ${cut.error.status}: ${cut.error.message}; the run before it kept its own model`);
- // A BigInt past 64 bits would reach the library modulo 2^64, as 0, and a Number past 2^53 as another integer.
- for (const [value, status] of [['-(2n ** 64n)', 'out_of_range'], ['2 ** 60', 'invalid_argument']]) {
- const wide = await run(`{ model: ${JSON.stringify(urls[0])}, ${one}, options: { min_speech_duration_ms: ${value} } }`);
- if (wide.error?.status !== status || wide.error.option !== 'min_speech_duration_ms') {
- throw new Error(`min_speech_duration_ms of ${value}: ${JSON.stringify(wide)}, where ${status} naming it was due`);
+
+ if (started) {
+ for (const l of libraries) {
+ const got = await inWorker(`onmessage = async () => {
+ try { postMessage({ version: (await openSpeech({ threads: ${l === 'libspeech-threads'} })).version }); }
+ catch (e) { postMessage({ error: e.message }); }
+ };`, '{}');
+ if (got.version !== started.release) throw new Error(`${l}: ${JSON.stringify(got)}, where speech.cpp ${started.release} was due`);
+ console.log(`${l} started: speech.cpp ${got.version}`);
}
- console.log(`min_speech_duration_ms of ${value} refused: ${wide.error.status}: ${wide.error.message}`);
- }
- if (threads) {
- // Audio past the 1 GB of the build with threads, in a Worker of its own, since the page reads audio from WAVE files:
- // malloc() gives 0 for it, and the module must refuse it before it writes there, then answer the next request.
- const big = await page(`
- const source = 'import { openSpeech } from ' + JSON.stringify(location.origin + '/speech.mjs') + ';'
- + 'onmessage = async ({ data: { blob, threads } }) => {'
- + ' const speech = await openSpeech({ threads: true });'
- + ' const model = speech.load(blob, { threads });'
- + ' const failed = (e) => ({ status: e.status ?? null, message: e.message });'
- + ' let big;'
- + ' try { big = { regions: model.detect(new Float32Array(2 ** 28 + 2 ** 20), 16000) }; } catch (e) { big = failed(e); }'
- + ' let after;'
- + ' try { after = { regions: model.detect(new Float32Array(16000), 16000) }; } catch (e) { after = failed(e); }'
- + ' postMessage({ big, after, memory: speech.memory });'
- + '};';
- const worker = new Worker(URL.createObjectURL(new Blob([source], { type: 'text/javascript' })), { type: 'module' });
- const blob = await (await fetch(${JSON.stringify(urls[0])})).blob();
- const answer = new Promise((resolve, reject) => {
- worker.onmessage = ({ data }) => resolve(data);
- worker.onerror = (e) => reject(new Error(e.message));
- });
- worker.postMessage({ blob, threads: ${threads} });
- try {
- return await answer;
- } finally {
- worker.terminate();
- }
+ } else {
+ const run = (args) => page(`return await speechPage.run(${args}).catch(failure);`);
+ const on = threads ? `, threads: ${threads}` : '';
+ const all = `{ model: ${JSON.stringify(urls[0])}, audio: ${JSON.stringify(urls.slice(1))}${on} }`;
+ const first = await run(all);
+ if (first.error) throw new Error(`the page failed: ${JSON.stringify(first.error)}`);
+ const differs = departure(first.detections, native);
+ if (differs) throw new Error(differs);
+ if (first.info.threads !== (threads ?? 1)) throw new Error(`the model computes with ${first.info.threads} threads, where ${threads ?? 1} were asked for`);
+ console.log(`speech.cpp ${first.version}, ${library}: the module started in ${first.open.toFixed(1)} ms, and ${first.info.name} `
+ + `${first.info.weight_type} loaded in ${first.load.toFixed(1)} ms on ${first.info.threads} threads`);
+ first.detections.forEach((d, f) => {
+ console.log(`${path.basename(audio[f])}: ${d.regions.length} regions as speech vad finds them, ${d.seconds.toFixed(2)} s of audio in `
+ + `${d.ms.toFixed(1)} ms, RTFx ${(d.seconds / (d.ms / 1000)).toFixed(0)}`);
+ });
+ console.log(`the module's memory: ${(first.memory / 2 ** 20).toFixed(1)} MiB at most`);
+
+ const one = `audio: ${JSON.stringify(urls.slice(1, 2))}${on}`;
+ // One thread more than the build starts: 2 without threads, or one past the browser's logical processors with them.
+ const most = threads ? await page('return navigator.hardwareConcurrency;') : 1;
+ const many = await run(`{ model: ${JSON.stringify(urls[0])}, audio: ${JSON.stringify(urls.slice(1, 2))}, threads: ${most + 1}, threaded: ${!!threads} }`);
+ if (many.error?.status !== 'invalid_argument' || many.error.option !== 'threads') {
+ throw new Error(`${most + 1} threads in ${library}: ${JSON.stringify(many)}, where invalid_argument naming threads was due`);
+ }
+ console.log(`${most + 1} threads refused: ${many.error.status} (${many.error.option}): ${many.error.message}`);
+ // The model cut in half is loaded while a run of the whole one is under way, which must keep its own model. Both are
+ // Blobs at hand, so that the second load reaches the Worker before the first run's detection.
+ const [whole, cut] = await page(`
+ const whole = await (await fetch(${JSON.stringify(urls[0])})).blob();
+ const model = new File([whole.slice(0, Math.floor(whole.size / 2))], 'cut.gguf');
+ return await Promise.all([
+ speechPage.run({ model: new File([whole], 'whole.gguf'), ${one} }).catch(failure),
+ speechPage.run({ model, ${one} }).catch(failure),
+ ]);
`);
- if (big.big.status !== 'out_of_memory' || !big.after.regions || big.after.regions.length) {
- throw new Error(`audio past 1 GB: ${JSON.stringify(big)}, where out_of_memory and then a second of silence without regions were due`);
+ if (cut.error?.status !== 'model_file') throw new Error(`a model cut in half: ${JSON.stringify(cut)}, where model_file was due`);
+ if (whole.error) throw new Error(`a run with a model cut in half after it failed: ${JSON.stringify(whole.error)}`);
+ const differsBeside = departure(whole.detections, native.slice(0, 1));
+ if (differsBeside) throw new Error(`a run with a model cut in half after it: ${differsBeside}`);
+ console.log(`a model cut in half refused: ${cut.error.status}: ${cut.error.message}; the run before it kept its own model`);
+ // A BigInt past 64 bits would reach the library modulo 2^64, as 0, and a Number past 2^53 as another integer.
+ for (const [value, status] of [['-(2n ** 64n)', 'out_of_range'], ['2 ** 60', 'invalid_argument']]) {
+ const wide = await run(`{ model: ${JSON.stringify(urls[0])}, ${one}, options: { min_speech_duration_ms: ${value} } }`);
+ if (wide.error?.status !== status || wide.error.option !== 'min_speech_duration_ms') {
+ throw new Error(`min_speech_duration_ms of ${value}: ${JSON.stringify(wide)}, where ${status} naming it was due`);
+ }
+ console.log(`min_speech_duration_ms of ${value} refused: ${wide.error.status}: ${wide.error.message}`);
+ }
+ if (threads) {
+ // Audio past the 1 GB of the build with threads, in a Worker of its own, since the page reads audio from WAVE files:
+ // malloc() gives 0 for it, and the module must refuse it before it writes there, then answer the next request.
+ const big = await inWorker(`onmessage = async ({ data: { blob, threads } }) => {
+ const speech = await openSpeech({ threads: true });
+ const model = speech.load(blob, { threads });
+ const failed = (e) => ({ status: e.status ?? null, message: e.message });
+ let big;
+ try { big = { regions: model.detect(new Float32Array(2 ** 28 + 2 ** 20), 16000) }; } catch (e) { big = failed(e); }
+ let after;
+ try { after = { regions: model.detect(new Float32Array(16000), 16000) }; } catch (e) { after = failed(e); }
+ postMessage({ big, after, memory: speech.memory });
+ };`, `fetch(${JSON.stringify(urls[0])}).then((r) => r.blob()).then((blob) => ({ blob, threads: ${threads} }))`);
+ if (big.big.status !== 'out_of_memory' || !big.after.regions || big.after.regions.length) {
+ throw new Error(`audio past 1 GB: ${JSON.stringify(big)}, where out_of_memory and then a second of silence without regions were due`);
+ }
+ console.log(`audio past 1 GB refused: ${big.big.status}: ${big.big.message}; a second of silence after it: no regions`);
}
- console.log(`audio past 1 GB refused: ${big.big.status}: ${big.big.message}; a second of silence after it: no regions`);
+ const again = await run(`{ model: ${JSON.stringify(urls[0])}, ${one} }`);
+ if (again.error) throw new Error(`the page failed after the errors: ${JSON.stringify(again.error)}`);
+ const differsAgain = departure(again.detections, native.slice(0, 1));
+ if (differsAgain) throw new Error(`after the errors, ${differsAgain}`);
+ console.log('the next request after them: the same regions');
}
- const again = await run(`{ model: ${JSON.stringify(urls[0])}, ${one} }`);
- if (again.error) throw new Error(`the page failed after the errors: ${JSON.stringify(again.error)}`);
- const differsAgain = departure(again.detections, native.slice(0, 1));
- if (differsAgain) throw new Error(`after the errors, ${differsAgain}`);
- console.log('the next request after them: the same regions');
-
if (errors.length) throw new Error(`the page threw: ${errors.join('; ')}`);
console.log('ok');
} finally {
diff --git a/docs/browser.md b/docs/browser.md
index 86b49209..ddac9931 100644
--- a/docs/browser.md
+++ b/docs/browser.md
@@ -5,6 +5,9 @@ leaves the browser. It holds Silero VAD, which finds where someone speaks in a r
## What it is
+Each [release](https://github.com/nyosegawa/speech.cpp/releases) has it in `speech--wasm.zip`, whose SHA-256
+is in the release's `SHA256SUMS`, or you [build it](#build-it):
+
| File | What it is |
|---|---|
| `libspeech.js`, `libspeech.wasm` | the library: the C API compiled to WebAssembly, an ES module for a Worker, on one thread |
@@ -13,6 +16,7 @@ leaves the browser. It holds Silero VAD, which finds where someone speaks in a r
| `wav.mjs` | reads a WAVE file into samples as `speech` reads it |
| `index.html`, `page.mjs`, `worker.mjs` | a page that finds the regions of speech in a WAVE file you choose |
| `serve.py` | serves the folder on 127.0.0.1 with the headers the build with threads needs |
+| `speech.h` | the C API, which the library exports function for function |
It runs on the CPU in Chrome and Edge 95, Firefox 114 and Safari 16.4 and later, on phones too.
@@ -21,7 +25,8 @@ It runs on the CPU in Chrome and Edge 95, Firefox 114 and Safari 16.4 and later,
Serve the folder over HTTP, since a page opened from a file cannot load modules, and open it:
```sh
-cd build-wasm
+unzip speech-*-wasm.zip -d speech-wasm
+cd speech-wasm
python3 serve.py
```
diff --git a/docs/install.md b/docs/install.md
index 42dadae7..ac8c2464 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -113,6 +113,7 @@ links the library takes them by hand.
| `windows-x64-vulkan` | Windows x64, with Vulkan |
| `linux-x64-vulkan` | Linux x86-64, with Vulkan |
| `linux-x64-cpu` | Linux x86-64, on the CPU alone |
+| `wasm` | web pages, as WebAssembly on the CPU ([browser.md](browser.md)); the installer does not install it |
| File in the archive | What it is |
|---|---|
@@ -120,6 +121,10 @@ links the library takes them by hand.
| `libspeech.4.dylib` and the link `libspeech.dylib`, `libspeech.so.4` and the link `libspeech.so`, or `speech.dll` and its import library `speech.lib` | the shared library, which exports the C API and nothing else; 4 is the C API's major version |
| `speech.h` | the C API ([c-api.md](c-api.md)) |
+`speech--wasm.zip` holds the library in WebAssembly in place of `speech` and the shared library: `libspeech.js`
+and `libspeech.wasm`, the same with threads in `libspeech-threads.js` and `libspeech-threads.wasm`, `speech.mjs`,
+`wav.mjs`, the page (`index.html`, `page.mjs`, `worker.mjs`), `serve.py` and `speech.h`.
+
## Build from source
The build needs CMake 3.20 or later and a C++17 compiler.
diff --git a/skills/release/SKILL.md b/skills/release/SKILL.md
index 84302f2f..ae32214c 100644
--- a/skills/release/SKILL.md
+++ b/skills/release/SKILL.md
@@ -117,10 +117,14 @@ the packaging steps of `.github/workflows/build.yml` and docs/install.md's Relea
## 7. Check what was published
-- `gh release view v` lists the four archives and `SHA256SUMS`.
+- `gh release view v` lists the five archives and `SHA256SUMS`.
- The installer installs it: `curl -fsSL …/install.sh | sh` in a temporary `HOME` on macOS, and `install.ps1` on
Windows with `LOCALAPPDATA` pointed at a temporary folder and `-NoModifyPath`; `speech --version` names the release.
- `speech pull ` and one synthesis and one recognition by name work from the installed `speech`.
+- The browser's archive, `speech--wasm.zip`, downloaded and unpacked into a folder of its own, runs Silero
+ VAD as the installed `speech vad` does, without threads and with them:
+ `node checks/smoke/wasm_browser_smoke.mjs ...`, and again
+ with `--threads 4`.
## 8. After it