Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

test: cover spoken-text verification at the service and route boundaries (#10250)

[._.]/ Adam Eivyb57545311421
diff --git a/server/lib/speechMatch.js b/server/lib/speechMatch.js
index a751348993..b54f8188d9 100644
--- a/server/lib/speechMatch.js
+++ b/server/lib/speechMatch.js
@@ -31,7 +31,7 @@ function below1000(n) {
}
/** Spell a non-negative integer as English cardinal words ("12" -> "twelve"). */
-export function numberToWords(n) {
+function numberToWords(n) {
if (!Number.isInteger(n) || n < 0 || n > MAX_NUMBER) return String(n);
if (n === 0) return 'zero';
const words = [];
@@ -74,11 +74,6 @@ function tokenize(normalized) {
return normalized.split(/\s+/).filter(Boolean);
}
-/** Normalized token list for a line (digits spelled out, punctuation dropped). */
-export function normalizeSpeech(text) {
- return tokenize(normalizeBase(text, cardinal));
-}
-
function editDistance(a, b) {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
diff --git a/server/lib/speechMatch.test.js b/server/lib/speechMatch.test.js
index c71aa1a04d..59867d2a60 100644
--- a/server/lib/speechMatch.test.js
+++ b/server/lib/speechMatch.test.js
@@ -1,14 +1,7 @@
import { describe, it, expect } from 'vitest';
-import { compareSpeech, normalizeSpeech, numberToWords } from './speechMatch.js';
+import { compareSpeech } from './speechMatch.js';
describe('speechMatch', () => {
- it('spells numbers', () => {
- expect(numberToWords(12)).toBe('twelve');
- expect(numberToWords(0)).toBe('zero');
- expect(numberToWords(2024)).toBe('two thousand twenty four');
- expect(numberToWords(1_250_300)).toBe('one million two hundred fifty thousand three hundred');
- });
-
it.each([
['I have 12 apples.', 'I have twelve apples'],
['Hello, World!', 'hello world'],
@@ -16,6 +9,7 @@ describe('speechMatch', () => {
['It cost 1,200 dollars', 'it cost one thousand two hundred dollars'],
['In 1999 we left', 'In nineteen ninety nine we left'],
['3.5 miles', 'three point five miles'],
+ ['1,250,300 people', 'one million two hundred fifty thousand three hundred people'],
['你好,世界!', '你好 世界'],
])('matches %j against %j', (script, heard) => {
expect(compareSpeech(script, heard).status).toBe('matched');
@@ -30,8 +24,4 @@ describe('speechMatch', () => {
expect(compareSpeech(script, heard).status).toBe('mismatch');
});
- it('tokenizes CJK per character and Latin per word', () => {
- expect(normalizeSpeech('你好 世界')).toEqual(['你', '好', '世', '界']);
- expect(normalizeSpeech('Hi, there')).toEqual(['hi', 'there']);
- });
});
diff --git a/server/routes/pipeline.test.js b/server/routes/pipeline.test.js
index 006cc8c1d3..11f7d915ff 100644
--- a/server/routes/pipeline.test.js
+++ b/server/routes/pipeline.test.js
@@ -317,6 +317,7 @@ vi.mock('../services/voice/tts.js', () => ({
normalizeVoiceEngine: (engine) => engine === 'qwen3' ? 'qwen3-tts' : engine,
VALID_ENGINES: new Set(['kokoro', 'piper', 'qwen3-tts']),
}));
+import { compareSpeech } from '../lib/speechMatch.js';
const transcribeMock = vi.fn();
vi.mock('../services/voice/stt.js', () => ({ transcribe: (...a) => transcribeMock(...a) }));
vi.mock('../services/voice/profiles.js', () => ({
@@ -2808,14 +2809,20 @@ describe('pipeline routes', () => {
describe('spoken-text verification (#10250)', () => {
- // Run the real verifyRenderedLine behind the mocked synthesizeToFile so the
- // route's expectedSpeech hand-off and verification persistence are exercised.
+ // The mocked synthesizeToFile mirrors the real verify step (stubbed transcribe
+ // + compareSpeech) so the route's expectedSpeech hand-off and verification
+ // persistence are exercised; the real service path is covered in audio.test.js.
const renderWithVerification = async (app, iss) => {
const audio = await import('../services/pipeline/audio.js');
- audio.synthesizeToFile.mockImplementationOnce(async ({ text, expectedSpeech }) => ({
- filename: `vo-mock-${++uuidCounter}.wav`, latencyMs: 1, engine: 'kokoro',
- verification: await audio.verifyRenderedLine({ wav: Buffer.from('w'), text, expectedSpeech }),
- }));
+ audio.synthesizeToFile.mockImplementationOnce(async ({ text, expectedSpeech }) => {
+ const heard = await transcribeMock(Buffer.from('w'), { prompt: '' }).catch(() => null);
+ return {
+ filename: `vo-mock-${++uuidCounter}.wav`, latencyMs: 1, engine: 'kokoro',
+ verification: heard
+ ? { ...compareSpeech(expectedSpeech || text, heard.text), heard: heard.text }
+ : { status: 'unverified', similarity: null, heard: '' },
+ };
+ });
return request(app).post(`/api/pipeline/issues/${iss.id}/stages/audio/lines/0/render`).send({});
};
const seed = async (app) => {
diff --git a/server/services/pipeline/audio.js b/server/services/pipeline/audio.js
index 9b61d236cc..c0beba8393 100644
--- a/server/services/pipeline/audio.js
+++ b/server/services/pipeline/audio.js
@@ -218,7 +218,7 @@ export { wavDurationMs };
* down or slow yields `unverified` — never an error, never blocks a render.
* @returns {Promise<{ status: 'matched'|'mismatch'|'unverified', similarity: number|null, heard: string }>}
*/
-export async function verifyRenderedLine({ wav, text, expectedSpeech, signal } = {}) {
+async function verifyRenderedLine({ wav, text, expectedSpeech, signal } = {}) {
const heardResult = await transcribe(wav, { prompt: '', signal }).catch((err) => {
console.warn(`⚠️ voice-over verification skipped: ${err?.message || err}`);
return null;
diff --git a/server/services/pipeline/audio.test.js b/server/services/pipeline/audio.test.js
index df8e2493f0..a45ae4466f 100644
--- a/server/services/pipeline/audio.test.js
+++ b/server/services/pipeline/audio.test.js
@@ -25,7 +25,8 @@ vi.mock('../voice/tts.js', () => ({
VALID_ENGINES: new Set(['kokoro', 'piper', 'qwen3-tts']),
}));
-vi.mock('../voice/stt.js', () => ({ transcribe: vi.fn().mockRejectedValue(new Error('stt down')) }));
+const transcribeMock = vi.fn();
+vi.mock('../voice/stt.js', () => ({ transcribe: (...a) => transcribeMock(...a) }));
const { parseVoiceId, listAllVoices, synthesizeToFile, extractDialogueLines, resolveVoiceForLine, wavDurationMs } = await import('./audio.js');
@@ -144,6 +145,8 @@ describe('listAllVoices', () => {
});
describe('synthesizeToFile', () => {
+ beforeEach(() => { transcribeMock.mockReset().mockRejectedValue(new Error('stt down')); });
+
it('rejects empty text with 400', async () => {
await expect(synthesizeToFile({ text: ' ', voiceId: 'kokoro:af_heart' }))
.rejects.toMatchObject({ status: 400 });
@@ -200,6 +203,39 @@ describe('synthesizeToFile', () => {
});
});
+describe('synthesizeToFile spoken-text verification (#10250)', () => {
+ beforeEach(() => {
+ synthesizeMock.mockResolvedValue({ wav: Buffer.from('w'), latencyMs: 1, engine: 'kokoro' });
+ });
+
+ it('is matched when the transcription agrees, and bypasses the vocabulary prompt', async () => {
+ transcribeMock.mockReset().mockResolvedValue({ text: 'I have twelve apples.' });
+ const r = await synthesizeToFile({ text: 'I have 12 apples', voiceId: 'kokoro:af_heart' });
+ expect(r.verification).toEqual({ status: 'matched', similarity: 1, heard: 'I have twelve apples.' });
+ expect(transcribeMock).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({ prompt: '' }));
+ });
+
+ it('is a mismatch carrying what was heard when the number differs', async () => {
+ transcribeMock.mockReset().mockResolvedValue({ text: 'I have fifteen apples' });
+ const r = await synthesizeToFile({ text: 'I have 12 apples', voiceId: 'kokoro:af_heart' });
+ expect(r.verification.status).toBe('mismatch');
+ expect(r.verification.heard).toBe('I have fifteen apples');
+ });
+
+ it('honors expectedSpeech as the comparison target', async () => {
+ transcribeMock.mockReset().mockResolvedValue({ text: 'Ay Ai' });
+ const r = await synthesizeToFile({ text: 'AI', expectedSpeech: 'Ay-Ai' });
+ expect(r.verification.status).toBe('matched');
+ });
+
+ it('is unverified, and still renders, when speech-to-text is unavailable', async () => {
+ transcribeMock.mockReset().mockRejectedValue(new Error('ECONNREFUSED'));
+ const r = await synthesizeToFile({ text: 'hello there' });
+ expect(r.filename).toMatch(/^vo-/);
+ expect(r.verification).toEqual({ status: 'unverified', similarity: null, heard: '' });
+ });
+});
+
describe('wavDurationMs', () => {
it('computes duration from the data chunk and byte rate', () => {
expect(wavDurationMs(makeWav({ sampleRate: 24000, dataBytes: 24000 * 2 }))).toBe(1000);