mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 15:50:46 +00:00
refactor(stt): share transcription helpers
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { isLiveTestEnabled } from "../../src/agents/live-test-helpers.js";
|
||||
import {
|
||||
normalizeTranscriptForMatch,
|
||||
streamAudioForLiveTest,
|
||||
runRealtimeSttLiveTest,
|
||||
synthesizeElevenLabsLiveSpeech,
|
||||
waitForLiveExpectation,
|
||||
} from "../../test/helpers/stt-live-audio.js";
|
||||
import { transcribeDeepgramAudio } from "./audio.js";
|
||||
import { buildDeepgramRealtimeTranscriptionProvider } from "./realtime-transcription-provider.js";
|
||||
@@ -62,37 +60,15 @@ describeLive("deepgram live", () => {
|
||||
outputFormat: "ulaw_8000",
|
||||
timeoutMs: 30_000,
|
||||
});
|
||||
const transcripts: string[] = [];
|
||||
const partials: string[] = [];
|
||||
const errors: Error[] = [];
|
||||
const session = provider.createSession({
|
||||
|
||||
await runRealtimeSttLiveTest({
|
||||
provider,
|
||||
providerConfig: {
|
||||
apiKey: DEEPGRAM_KEY,
|
||||
language: "en-US",
|
||||
endpointingMs: 500,
|
||||
},
|
||||
onPartial: (partial) => partials.push(partial),
|
||||
onTranscript: (transcript) => transcripts.push(transcript),
|
||||
onError: (error) => errors.push(error),
|
||||
audio: Buffer.concat([Buffer.alloc(4000, 0xff), speech, Buffer.alloc(8000, 0xff)]),
|
||||
});
|
||||
|
||||
try {
|
||||
await session.connect();
|
||||
await streamAudioForLiveTest({
|
||||
audio: Buffer.concat([Buffer.alloc(4000, 0xff), speech, Buffer.alloc(8000, 0xff)]),
|
||||
sendAudio: (chunk) => session.sendAudio(chunk),
|
||||
});
|
||||
|
||||
await waitForLiveExpectation(() => {
|
||||
if (errors[0]) {
|
||||
throw errors[0];
|
||||
}
|
||||
expect(normalizeTranscriptForMatch(transcripts.join(" "))).toContain("openclaw");
|
||||
}, 60_000);
|
||||
} finally {
|
||||
session.close();
|
||||
}
|
||||
|
||||
expect(partials.length + transcripts.length).toBeGreaterThan(0);
|
||||
}, 90_000);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user