Files
pdtv26/speech/hear-client.js
T
dckc 65e38c23cf feat(speech): the speech capability over Cap'n Web, behind a gate
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
2026-12-02 15:27:50 -06:00

26 lines
979 B
JavaScript

/**
* @file hear-client: send one clip to the speech capability and print the transcript.
* usage: node hear-client.js URL < clip.wav
* The key is in $CREDENTIALS_DIRECTORY/speech-key (systemd LoadCredential), not argv, where ps would show it.
*/
import { newWebSocketRpcSession } from 'capnweb';
import { readFile } from 'node:fs/promises';
import { buffer } from 'node:stream/consumers';
const main = async ([url], env, stdin, stdout) => {
const key = (await readFile(`${env.CREDENTIALS_DIRECTORY}/speech-key`, 'utf8')).trim();
const clip = new Uint8Array(await buffer(stdin));
const gate = newWebSocketRpcSession(url);
try {
// Pipelined: open and transcribe in one round trip.
stdout.write(`${await gate.open(key).transcribe(clip)}\n`);
} finally {
gate[Symbol.dispose]();
}
};
main(process.argv.slice(2), process.env, process.stdin, process.stdout).catch((err) => {
console.error(`hear-client: ${err.message ?? err}`);
process.exit(1);
});