83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
require("dotenv").config();
|
|
const axios = require("axios");
|
|
|
|
const baseUrl = (process.env.CAPTION_TEST_BASE_URL || process.env.BASE_URL || "http://localhost:3000").replace(/\/+$/, "");
|
|
const ingestUrl = `${baseUrl}/live-captions/ingest`;
|
|
const intervalMs = 5000;
|
|
|
|
const samples = [
|
|
{
|
|
original: "Bienvenidos a nuestro servicio de adoracion.",
|
|
sourceLang: "es",
|
|
translations: {
|
|
en: "Welcome to our worship service.",
|
|
fr: "Bienvenue a notre service de louange.",
|
|
},
|
|
},
|
|
{
|
|
original: "Leamos juntos en el Salmo 23.",
|
|
sourceLang: "es",
|
|
translations: {
|
|
en: "Let us read together in Psalm 23.",
|
|
fr: "Lisons ensemble le Psaume 23.",
|
|
},
|
|
},
|
|
{
|
|
original: "Dios es fiel en todo tiempo.",
|
|
sourceLang: "es",
|
|
translations: {
|
|
en: "God is faithful at all times.",
|
|
fr: "Dieu est fidele en tout temps.",
|
|
},
|
|
},
|
|
{
|
|
original: "Tomemos un momento para orar.",
|
|
sourceLang: "es",
|
|
translations: {
|
|
en: "Let us take a moment to pray.",
|
|
fr: "Prenons un moment pour prier.",
|
|
},
|
|
},
|
|
];
|
|
|
|
let sampleIndex = 0;
|
|
let timer = null;
|
|
|
|
const sendNextSample = async () => {
|
|
const payload = samples[sampleIndex];
|
|
sampleIndex = (sampleIndex + 1) % samples.length;
|
|
|
|
try {
|
|
const response = await axios.post(ingestUrl, payload, {
|
|
headers: { "Content-Type": "application/json" },
|
|
timeout: 10000,
|
|
});
|
|
const seq = response?.data?.caption?.sequence || response?.data?.latestSequence || "?";
|
|
console.log(`[live-captions:test-sender] sent sequence=${seq} original="${payload.original}"`);
|
|
} catch (error) {
|
|
const status = error?.response?.status;
|
|
const body = error?.response?.data;
|
|
const message = error?.message || "request failed";
|
|
console.error("[live-captions:test-sender] send failed", { status, body, message });
|
|
}
|
|
};
|
|
|
|
const start = async () => {
|
|
console.log(`[live-captions:test-sender] posting to ${ingestUrl} every ${intervalMs / 1000}s`);
|
|
await sendNextSample();
|
|
timer = setInterval(sendNextSample, intervalMs);
|
|
};
|
|
|
|
const shutdown = () => {
|
|
if (timer) clearInterval(timer);
|
|
console.log("[live-captions:test-sender] stopped");
|
|
process.exit(0);
|
|
};
|
|
|
|
process.on("SIGINT", shutdown);
|
|
process.on("SIGTERM", shutdown);
|
|
|
|
start();
|