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
25 lines
888 B
JavaScript
25 lines
888 B
JavaScript
/**
|
|
* @file speak-client: have the speech capability speak text; write the WAV to stdout.
|
|
* usage: node speak-client.js URL < text > speech.wav
|
|
* The key is in $CREDENTIALS_DIRECTORY/speech-key (systemd LoadCredential), not argv.
|
|
*/
|
|
import { newWebSocketRpcSession } from 'capnweb';
|
|
import { readFile } from 'node:fs/promises';
|
|
import { text } from 'node:stream/consumers';
|
|
|
|
const main = async ([url], env, stdin, stdout) => {
|
|
const key = (await readFile(`${env.CREDENTIALS_DIRECTORY}/speech-key`, 'utf8')).trim();
|
|
const words = (await text(stdin)).trim();
|
|
const gate = newWebSocketRpcSession(url);
|
|
try {
|
|
stdout.write(await gate.open(key).speak(words));
|
|
} finally {
|
|
gate[Symbol.dispose]();
|
|
}
|
|
};
|
|
|
|
main(process.argv.slice(2), process.env, process.stdin, process.stdout).catch((err) => {
|
|
console.error(`speak-client: ${err.message ?? err}`);
|
|
process.exit(1);
|
|
});
|