fixup! feat(speech): the speech capability over Cap'n Web, behind a gate
check / check (push) Canceled after 0s

This commit is contained in:
dckc committed 2026-12-02 15:41:18 -06:00
1 parent 372f6a2b96
commit a97ba6c174
12 files changed
+245 -92

No files matched your search

+5 -5
View File
@@ -1,12 +1,12 @@
// Tests for the speech capability, in process: no network, no whisper, no piper.
import { test } from 'node:test';
import assert from 'node:assert/strict';
import { makeSpeech, MAX_CLIP_BYTES, MAX_SPEAK_CHARS } from './speech.js';
import { Speech, MAX_CLIP_BYTES, MAX_SPEAK_CHARS } from './speech.js';
const clip = new Uint8Array([82, 73, 70, 70]); // "RIFF"
test('transcribe takes bytes, and not too many', async () => {
const speech = makeSpeech(async (c) => `${c.length} bytes`);
const speech = new Speech(async (c) => `${c.length} bytes`);
assert.equal(await speech.transcribe(clip), '4 bytes');
assert.throws(() => speech.transcribe('UklGRg=='), /must be bytes/);
assert.throws(() => speech.transcribe(new Uint8Array(MAX_CLIP_BYTES + 1)), /over/);
@@ -15,7 +15,7 @@ test('transcribe takes bytes, and not too many', async () => {
test('one clip at a time, and a failure does not stall the next', async () => {
const log = [];
let n = 0;
const speech = makeSpeech(async () => {
const speech = new Speech(async () => {
const i = ++n;
log.push(`start ${i}`);
await new Promise((r) => setTimeout(r, 10));
@@ -31,7 +31,7 @@ test('one clip at a time, and a failure does not stall the next', async () => {
test('speak takes text, not too much, and shares the one-at-a-time turn', async () => {
const log = [];
const speech = makeSpeech(
const speech = new Speech(
async () => { log.push('transcribe'); return 'hi'; },
async (text) => { log.push(`speak ${text}`); return new Uint8Array([82, 73, 70, 70]); },
);
@@ -41,5 +41,5 @@ test('speak takes text, not too much, and shares the one-at-a-time turn', async
assert.deepEqual(log, ['transcribe', 'speak Hello.']);
assert.throws(() => speech.speak(''), /needs text/);
assert.throws(() => speech.speak('x'.repeat(MAX_SPEAK_CHARS + 1)), /over/);
assert.throws(() => makeSpeech(async () => '').speak('hi'), /no voice/);
assert.throws(() => new Speech(async () => '').speak('hi'), /no voice/);
});