/** * @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); });