fixup! feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
This commit is contained in:
1 parent
372f6a2b96
commit
a97ba6c174
12 files changed
+245
-92
No files matched your search
Regular → Executable
+27
-6
@@ -1,16 +1,37 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @file speak-client: have the speech capability speak text; write the WAV to stdout.
|
||||
* usage: node speak-client.js URL < text > speech.wav
|
||||
* usage: 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 process from 'node:process';
|
||||
import { text } from 'node:stream/consumers';
|
||||
|
||||
const main = async ([url], env, stdin, stdout) => {
|
||||
const key = (await readFile(`${env.CREDENTIALS_DIRECTORY}/speech-key`, 'utf8')).trim();
|
||||
/**
|
||||
* Speak the text on stdin, by way of the speech capability at URL.
|
||||
*
|
||||
* @param {object} [io] what it reaches; the process's own, by default
|
||||
* @param {string[]} [io.argv] [URL]
|
||||
* @param {Record<string, string | undefined>} [io.env] for CREDENTIALS_DIRECTORY
|
||||
* @param {typeof readFile} [io.read] reads the key
|
||||
* @param {AsyncIterable<Uint8Array>} [io.stdin] the text
|
||||
* @param {{ write(b: Uint8Array): unknown }} [io.stdout] the WAV goes here
|
||||
* @param {typeof newWebSocketRpcSession} [io.connect] opens a session with the gate at URL
|
||||
*/
|
||||
const main = async ({
|
||||
argv = process.argv.slice(2),
|
||||
env = process.env,
|
||||
read = readFile,
|
||||
stdin = process.stdin,
|
||||
stdout = process.stdout,
|
||||
connect = newWebSocketRpcSession,
|
||||
} = {}) => {
|
||||
const [url] = argv;
|
||||
const key = (await read(`${env.CREDENTIALS_DIRECTORY}/speech-key`, 'utf8')).trim();
|
||||
const words = (await text(stdin)).trim();
|
||||
const gate = newWebSocketRpcSession(url);
|
||||
const gate = connect(url);
|
||||
try {
|
||||
stdout.write(await gate.open(key).speak(words));
|
||||
} finally {
|
||||
@@ -18,7 +39,7 @@ const main = async ([url], env, stdin, stdout) => {
|
||||
}
|
||||
};
|
||||
|
||||
main(process.argv.slice(2), process.env, process.stdin, process.stdout).catch((err) => {
|
||||
main().catch((err) => {
|
||||
console.error(`speak-client: ${err.message ?? err}`);
|
||||
process.exit(1);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
Reference in new issue
Block a user