@mulingai-npm/redis 3.1.2 → 3.2.1
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.
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { RedisClient } from '../redis-client';
|
|
2
2
|
export type StepStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
|
|
3
|
-
export type
|
|
3
|
+
export type SttService = 'azure' | 'whisper' | 'deepgram';
|
|
4
|
+
export type SttProvider = {
|
|
5
|
+
service: SttService;
|
|
6
|
+
model?: string;
|
|
7
|
+
};
|
|
4
8
|
export type MulingstreamChunkData = {
|
|
5
9
|
chunkId: string;
|
|
6
10
|
roomId: string;
|
|
@@ -22,9 +26,9 @@ export type MulingstreamChunkData = {
|
|
|
22
26
|
processingStart: number;
|
|
23
27
|
};
|
|
24
28
|
stt: {
|
|
25
|
-
[
|
|
29
|
+
[service: string]: {
|
|
26
30
|
transcription: string;
|
|
27
|
-
|
|
31
|
+
model?: string;
|
|
28
32
|
status: StepStatus;
|
|
29
33
|
};
|
|
30
34
|
};
|
|
@@ -74,13 +78,13 @@ export declare class MulingstreamChunkManager {
|
|
|
74
78
|
private getChunkId;
|
|
75
79
|
getMulingstreamChunkById(roomId: string, n: number): Promise<MulingstreamChunkData>;
|
|
76
80
|
private withChunk;
|
|
77
|
-
updateStt(roomId: string, n: number,
|
|
81
|
+
updateStt(roomId: string, n: number, service: SttService, opt: {
|
|
78
82
|
transcription?: string;
|
|
79
83
|
sttStatus?: StepStatus;
|
|
80
84
|
}): Promise<boolean>;
|
|
81
85
|
updateSttObject(roomId: string, n: number, newStt: Record<string, {
|
|
82
86
|
transcription: string;
|
|
83
|
-
|
|
87
|
+
model?: string;
|
|
84
88
|
status: StepStatus;
|
|
85
89
|
}>): Promise<boolean>;
|
|
86
90
|
discardStt(roomId: string, n: number): Promise<boolean>;
|
|
@@ -51,13 +51,6 @@ class MulingstreamChunkManager {
|
|
|
51
51
|
}
|
|
52
52
|
/* ------------------------------ timeouts ------------------------------- */
|
|
53
53
|
getTimeout(start, end) {
|
|
54
|
-
// const len = end - start;
|
|
55
|
-
// if (len < 1_000) return 1_500;
|
|
56
|
-
// if (len < 3_000) return 3_000;
|
|
57
|
-
// if (len < 5_000) return 7_000;
|
|
58
|
-
// if (len < 8_000) return 10_000;
|
|
59
|
-
// if (len < 12_000) return 15_000;
|
|
60
|
-
// if (len < 20_000) return 20_000;
|
|
61
54
|
return 30000;
|
|
62
55
|
}
|
|
63
56
|
/* ---------------------------------------------------------------------- */
|
|
@@ -114,7 +107,7 @@ class MulingstreamChunkManager {
|
|
|
114
107
|
const chunkId = this.generateChunkId(roomId, chunkNumber);
|
|
115
108
|
const audioChunk = { start, end, duration, isFirst, isLast, theme, processingStart: Date.now() };
|
|
116
109
|
const stt = {};
|
|
117
|
-
sttProviders.forEach((p) => (stt[p] = { transcription: '',
|
|
110
|
+
sttProviders.forEach((p) => (stt[p.service] = { transcription: '', model: p.model, status: 'INIT' }));
|
|
118
111
|
const translation = {};
|
|
119
112
|
const tts = {};
|
|
120
113
|
shortCodeTargetLanguages.forEach((l) => {
|
|
@@ -191,15 +184,14 @@ class MulingstreamChunkManager {
|
|
|
191
184
|
await p.exec();
|
|
192
185
|
return out;
|
|
193
186
|
}
|
|
194
|
-
|
|
195
|
-
async updateStt(roomId, n, provider, opt) {
|
|
187
|
+
async updateStt(roomId, n, service, opt) {
|
|
196
188
|
return ((await this.withChunk(roomId, n, (c) => {
|
|
197
|
-
if (!c.stt[
|
|
189
|
+
if (!c.stt[service])
|
|
198
190
|
return false;
|
|
199
191
|
if (opt.transcription !== undefined)
|
|
200
|
-
c.stt[
|
|
192
|
+
c.stt[service].transcription = opt.transcription;
|
|
201
193
|
if (opt.sttStatus !== undefined)
|
|
202
|
-
c.stt[
|
|
194
|
+
c.stt[service].status = opt.sttStatus;
|
|
203
195
|
return true;
|
|
204
196
|
})) === true);
|
|
205
197
|
}
|
|
@@ -319,7 +311,6 @@ class MulingstreamChunkManager {
|
|
|
319
311
|
if (!chunks.length)
|
|
320
312
|
return [];
|
|
321
313
|
chunks.sort((a, b) => a.chunkNumber - b.chunkNumber);
|
|
322
|
-
/* isolate window where lang exists */
|
|
323
314
|
let lastIdx = -1;
|
|
324
315
|
for (let i = chunks.length - 1; i >= 0; i--)
|
|
325
316
|
if (chunks[i].tts[lang]) {
|
|
@@ -335,7 +326,6 @@ class MulingstreamChunkManager {
|
|
|
335
326
|
firstIdx = i;
|
|
336
327
|
}
|
|
337
328
|
const window = chunks.slice(firstIdx, lastIdx + 1);
|
|
338
|
-
/* find last USED/DISCARDED */
|
|
339
329
|
let lastDone = -1;
|
|
340
330
|
for (let i = window.length - 1; i >= 0; i--) {
|
|
341
331
|
const s = window[i].tts[lang].status;
|
|
@@ -363,9 +353,8 @@ class MulingstreamChunkManager {
|
|
|
363
353
|
ready.push(window[i]);
|
|
364
354
|
continue;
|
|
365
355
|
}
|
|
366
|
-
break;
|
|
356
|
+
break;
|
|
367
357
|
}
|
|
368
|
-
/* persist DISCARDED changes (if any) */
|
|
369
358
|
if (!ready.length || blocked) {
|
|
370
359
|
const p = this.redisClient.pipeline();
|
|
371
360
|
window.forEach((c) => p.hset(this.chunkHashKey(c.chunkId), { tts: this.serialize(c.tts) }));
|