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