@mulingai-npm/redis 2.9.1 → 2.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -10,6 +10,7 @@ export type MulingstreamChunkData = {
|
|
|
10
10
|
shortCodeTargetLanguages: string[];
|
|
11
11
|
finalTranscription: string;
|
|
12
12
|
sttStatus: StepStatus;
|
|
13
|
+
createdAt: number;
|
|
13
14
|
audioChunk: {
|
|
14
15
|
start: number;
|
|
15
16
|
end: number;
|
|
@@ -123,4 +124,5 @@ export declare class MulingstreamChunkManager {
|
|
|
123
124
|
}): Promise<MulingstreamChunkData | null>;
|
|
124
125
|
increaseTotalCheck(roomId: string, chunkNumber: number, language: string): Promise<MulingstreamChunkData | null>;
|
|
125
126
|
areTranslationsProcessed(roomId: string, chunkNumber: number): Promise<boolean>;
|
|
127
|
+
getAllReadyTts(roomId: string, language: string, timeoutMs?: number): Promise<MulingstreamChunkData[]>;
|
|
126
128
|
}
|
|
@@ -53,6 +53,7 @@ class MulingstreamChunkManager {
|
|
|
53
53
|
async addMulingstreamChunk(params) {
|
|
54
54
|
var _a;
|
|
55
55
|
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, targetLanguages, shortCodeTargetLanguages } = params;
|
|
56
|
+
/* ---------- build chunk skeleton ---------- */
|
|
56
57
|
const audioChunk = {
|
|
57
58
|
start,
|
|
58
59
|
end,
|
|
@@ -63,25 +64,14 @@ class MulingstreamChunkManager {
|
|
|
63
64
|
processingStart: Date.now()
|
|
64
65
|
};
|
|
65
66
|
const stt = {};
|
|
66
|
-
for (const
|
|
67
|
-
stt[
|
|
68
|
-
transcription: '',
|
|
69
|
-
status: 'INIT'
|
|
70
|
-
};
|
|
67
|
+
for (const p of sttProviders) {
|
|
68
|
+
stt[p] = { transcription: '', status: 'INIT' };
|
|
71
69
|
}
|
|
72
70
|
const translation = {};
|
|
73
71
|
const tts = {};
|
|
74
72
|
for (const lang of shortCodeTargetLanguages) {
|
|
75
|
-
translation[lang] = {
|
|
76
|
-
|
|
77
|
-
status: 'INIT'
|
|
78
|
-
};
|
|
79
|
-
tts[lang] = {
|
|
80
|
-
ttsAudioPath: '',
|
|
81
|
-
status: 'INIT',
|
|
82
|
-
isEmitted: false,
|
|
83
|
-
totalCheck: 0
|
|
84
|
-
};
|
|
73
|
+
translation[lang] = { translation: '', status: 'INIT' };
|
|
74
|
+
tts[lang] = { ttsAudioPath: '', status: 'INIT', isEmitted: false, totalCheck: 0 };
|
|
85
75
|
}
|
|
86
76
|
const newChunk = {
|
|
87
77
|
roomId,
|
|
@@ -92,22 +82,29 @@ class MulingstreamChunkManager {
|
|
|
92
82
|
shortCodeTargetLanguages,
|
|
93
83
|
finalTranscription: '',
|
|
94
84
|
sttStatus: 'INIT',
|
|
85
|
+
createdAt: Date.now(),
|
|
95
86
|
audioChunk,
|
|
96
87
|
stt,
|
|
97
88
|
translation,
|
|
98
89
|
tts
|
|
99
90
|
};
|
|
100
|
-
|
|
91
|
+
/* ---------- pull existing room array ---------- */
|
|
92
|
+
let chunks = (_a = (await this.redisClient.jsonGet(`[${roomId}]`, '.'))) !== null && _a !== void 0 ? _a : [];
|
|
93
|
+
/* ---------- reset the room if this is the first chunk ---------- */
|
|
94
|
+
if (chunkNumber === 1) {
|
|
95
|
+
chunks = []; // start fresh
|
|
96
|
+
}
|
|
97
|
+
/* ---------- insert / replace ---------- */
|
|
101
98
|
const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
|
|
102
99
|
if (idx !== -1) {
|
|
103
100
|
chunks[idx] = newChunk;
|
|
104
101
|
}
|
|
105
102
|
else {
|
|
106
103
|
chunks.push(newChunk);
|
|
107
|
-
if (chunks.length > ROOM_ARRAY_LENGTH)
|
|
104
|
+
if (chunks.length > ROOM_ARRAY_LENGTH)
|
|
108
105
|
chunks.shift();
|
|
109
|
-
}
|
|
110
106
|
}
|
|
107
|
+
/* ---------- persist ---------- */
|
|
111
108
|
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
112
109
|
await this.redisClient.expire(`[${roomId}]`, EXPIRATION);
|
|
113
110
|
}
|
|
@@ -398,5 +395,65 @@ class MulingstreamChunkManager {
|
|
|
398
395
|
}
|
|
399
396
|
return Object.values(chunk.translation).every((t) => t.status !== 'INIT');
|
|
400
397
|
}
|
|
398
|
+
async getAllReadyTts(roomId, language, timeoutMs = 15000) {
|
|
399
|
+
const chunks = await this.getMulingstreamChunksByRoom(roomId);
|
|
400
|
+
if (!(chunks === null || chunks === void 0 ? void 0 : chunks.length))
|
|
401
|
+
return [];
|
|
402
|
+
chunks.sort((a, b) => a.chunkNumber - b.chunkNumber);
|
|
403
|
+
/* ---- isolate the tail where the language exists ---- */
|
|
404
|
+
let lastLangIdx = -1;
|
|
405
|
+
for (let i = chunks.length - 1; i >= 0; i--) {
|
|
406
|
+
if (chunks[i].tts[language]) {
|
|
407
|
+
lastLangIdx = i;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (lastLangIdx === -1)
|
|
412
|
+
return [];
|
|
413
|
+
let firstLangIdx = lastLangIdx;
|
|
414
|
+
for (let i = lastLangIdx - 1; i >= 0; i--) {
|
|
415
|
+
if (!chunks[i].tts[language])
|
|
416
|
+
break;
|
|
417
|
+
firstLangIdx = i;
|
|
418
|
+
}
|
|
419
|
+
const window = chunks.slice(firstLangIdx, lastLangIdx + 1);
|
|
420
|
+
/* ---- find last USED / DISCARDED in that window ---- */
|
|
421
|
+
let lastDone = -1;
|
|
422
|
+
for (let i = window.length - 1; i >= 0; i--) {
|
|
423
|
+
const st = window[i].tts[language].status;
|
|
424
|
+
if (st === 'USED' || st === 'DISCARDED') {
|
|
425
|
+
lastDone = i;
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
const ready = [];
|
|
430
|
+
let blocked = false;
|
|
431
|
+
const now = Date.now();
|
|
432
|
+
for (let i = lastDone + 1; i < window.length; i++) {
|
|
433
|
+
const entry = window[i].tts[language];
|
|
434
|
+
if (entry.status === 'INIT') {
|
|
435
|
+
console.log(window[i].createdAt, ' --- ', window[i].chunkNumber);
|
|
436
|
+
if (now - window[i].createdAt > timeoutMs) {
|
|
437
|
+
entry.status = 'DISCARDED';
|
|
438
|
+
}
|
|
439
|
+
else {
|
|
440
|
+
blocked = true; // still waiting ⇒ cannot emit READYs
|
|
441
|
+
}
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
if (entry.status === 'READY') {
|
|
445
|
+
if (blocked)
|
|
446
|
+
break; // earlier INIT still pending
|
|
447
|
+
ready.push(window[i]);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
450
|
+
break; // unexpected USED / DISCARDED
|
|
451
|
+
}
|
|
452
|
+
// persist any DISCARDED changes we made
|
|
453
|
+
if (ready.length === 0 || blocked) {
|
|
454
|
+
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
455
|
+
}
|
|
456
|
+
return ready;
|
|
457
|
+
}
|
|
401
458
|
}
|
|
402
459
|
exports.MulingstreamChunkManager = MulingstreamChunkManager;
|