feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s

The agent's ears and voice: a server on the home server transcribes
a clip (sox, whisper.cpp) and speaks text (piper), one job at a time.
A gate hands the capability to whoever presents its key; the key comes
from systemd's credentials, not argv.

make test runs the unit tests in Nix's sandbox; make smoke starts a
real server on localhost, speaks a phrase, and hears it back.

Generated-by: Claude Opus 5.5
This commit is contained in:
dckc committed 2026-12-02 15:52:23 -06:00
1 parent 646dfee4c6
commit 429bafe9c0
20 files changed
+621

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
/**
* @file Helpers for the servers: run one command, and time and log a job.
* They reach only what they're given: spawn, and a clock.
*/
/**
* A command bound to one program and its arguments: run(input) feeds it stdin and
* resolves to its stdout bytes, or rejects with its stderr.
*
* @param {typeof import('node:child_process').spawn} spawn
* @param {string} cmd
* @param {string[]} args
*/
export const makeCommand = (spawn, cmd, args) => (input) => new Promise((resolve, reject) => {
const child = spawn(cmd, args, { stdio: ['pipe', 'pipe', 'pipe'] });
const out = [], err = [];
child.stdout.on('data', (d) => out.push(d));
child.stderr.on('data', (d) => err.push(d));
child.on('error', reject);
child.on('close', (code) => code === 0
? resolve(Buffer.concat(out))
: reject(new Error(`${cmd} exit ${code}: ${Buffer.concat(err).toString().trim().slice(-500)}`)));
child.stdin.end(input);
});
/**
* Time a job and log how it went; failures are logged and rethrown.
*
* @template T
* @param {() => number} now milliseconds
* @param {string} what
* @param {() => Promise<T>} job
* @param {(result: T) => string} describe
*/
export const timed = async (now, what, job, describe) => {
const t0 = now();
try {
const result = await job();
console.log(`${what} in ${now() - t0} ms: ${describe(result)}`);
return result;
} catch (err) {
console.error(`${what} failed after ${now() - t0} ms: ${err.message}`);
throw err;
}
};