@mulingai-npm/redis 3.2.2 → 3.3.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.
|
@@ -22,8 +22,7 @@ export type MulingstreamChunkData = {
|
|
|
22
22
|
duration: number;
|
|
23
23
|
isFirst: boolean;
|
|
24
24
|
isLast: boolean;
|
|
25
|
-
|
|
26
|
-
processingStart: number;
|
|
25
|
+
audioFilePath: string;
|
|
27
26
|
};
|
|
28
27
|
stt: {
|
|
29
28
|
[service: string]: {
|
|
@@ -70,7 +69,6 @@ export declare class MulingstreamChunkManager {
|
|
|
70
69
|
duration: number;
|
|
71
70
|
isFirst: boolean;
|
|
72
71
|
isLast: boolean;
|
|
73
|
-
theme: string;
|
|
74
72
|
sttProviders: SttProvider[];
|
|
75
73
|
targetLanguages: string[];
|
|
76
74
|
shortCodeTargetLanguages: string[];
|
|
@@ -78,6 +76,7 @@ export declare class MulingstreamChunkManager {
|
|
|
78
76
|
private getChunkId;
|
|
79
77
|
getMulingstreamChunkById(roomId: string, n: number): Promise<MulingstreamChunkData>;
|
|
80
78
|
private withChunk;
|
|
79
|
+
updateAudioFilePath(roomId: string, n: number, audioFilePath: string): Promise<boolean>;
|
|
81
80
|
updateStt(roomId: string, n: number, service: SttService, opt: {
|
|
82
81
|
transcription?: string;
|
|
83
82
|
sttStatus?: StepStatus;
|
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.MulingstreamChunkManager = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/* -------------------------------------------------------------------------- */
|
|
8
|
-
const EXPIRATION = 12 * 60 * 60; // 12 h
|
|
9
|
-
const ROOM_ARRAY_LENGTH = 50; // keep last 50 chunks
|
|
10
|
-
/* -------------------------------------------------------------------------- */
|
|
11
|
-
/* Main class */
|
|
12
|
-
/* -------------------------------------------------------------------------- */
|
|
5
|
+
const EXPIRATION = 12 * 60 * 60;
|
|
6
|
+
const ROOM_ARRAY_LENGTH = 50;
|
|
13
7
|
class MulingstreamChunkManager {
|
|
14
8
|
constructor(redisClient) {
|
|
15
9
|
this.redisClient = redisClient;
|
|
16
10
|
}
|
|
17
|
-
/* ----------------------------- key helpers ----------------------------- */
|
|
18
11
|
roomZsetKey(roomId) {
|
|
19
12
|
return `room:${roomId}:chunks`;
|
|
20
13
|
}
|
|
@@ -24,7 +17,6 @@ class MulingstreamChunkManager {
|
|
|
24
17
|
generateChunkId(roomId, chunkNumber) {
|
|
25
18
|
return `[${roomId}]-[${chunkNumber}]-[${(0, uuid_1.v4)()}]`;
|
|
26
19
|
}
|
|
27
|
-
/* --------------------------- (de)serialization -------------------------- */
|
|
28
20
|
serialize(value) {
|
|
29
21
|
return JSON.stringify(value);
|
|
30
22
|
}
|
|
@@ -49,14 +41,9 @@ class MulingstreamChunkManager {
|
|
|
49
41
|
tts: this.deserialize(h.tts)
|
|
50
42
|
};
|
|
51
43
|
}
|
|
52
|
-
/* ------------------------------ timeouts ------------------------------- */
|
|
53
44
|
getTimeout(start, end) {
|
|
54
45
|
return 30000;
|
|
55
46
|
}
|
|
56
|
-
/* ---------------------------------------------------------------------- */
|
|
57
|
-
/* Public API (same) */
|
|
58
|
-
/* ---------------------------------------------------------------------- */
|
|
59
|
-
/* Room helpers ---------------------------------------------------------- */
|
|
60
47
|
async initRoom(roomId) {
|
|
61
48
|
const exists = await this.redisClient.exists(this.roomZsetKey(roomId));
|
|
62
49
|
if (exists)
|
|
@@ -82,10 +69,9 @@ class MulingstreamChunkManager {
|
|
|
82
69
|
getRoomById(roomId) {
|
|
83
70
|
return this.getMulingstreamChunksByRoom(roomId);
|
|
84
71
|
}
|
|
85
|
-
/* ------------------------- chunk insertion ---------------------------- */
|
|
86
72
|
async addMulingstreamChunk(params) {
|
|
87
73
|
var _a, _b;
|
|
88
|
-
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast,
|
|
74
|
+
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, sttProviders, targetLanguages, shortCodeTargetLanguages } = params;
|
|
89
75
|
if (chunkNumber === 1) {
|
|
90
76
|
const old = await this.redisClient.zrange(this.roomZsetKey(roomId), 0, -1);
|
|
91
77
|
if (old.length) {
|
|
@@ -105,7 +91,7 @@ class MulingstreamChunkManager {
|
|
|
105
91
|
}
|
|
106
92
|
}
|
|
107
93
|
const chunkId = this.generateChunkId(roomId, chunkNumber);
|
|
108
|
-
const audioChunk = { start, end, duration, isFirst, isLast,
|
|
94
|
+
const audioChunk = { start, end, duration, isFirst, isLast, audioFilePath: '' };
|
|
109
95
|
const stt = {};
|
|
110
96
|
sttProviders.forEach((p) => (stt[p.service] = { transcription: '', model: p.model, status: 'INIT' }));
|
|
111
97
|
const translation = {};
|
|
@@ -148,7 +134,6 @@ class MulingstreamChunkManager {
|
|
|
148
134
|
await trim.exec();
|
|
149
135
|
}
|
|
150
136
|
}
|
|
151
|
-
/* --------------------------- helper lookup ---------------------------- */
|
|
152
137
|
async getChunkId(roomId, n) {
|
|
153
138
|
const ids = await this.redisClient.zrangebyscore(this.roomZsetKey(roomId), n, n);
|
|
154
139
|
return ids.length ? ids[0] : null;
|
|
@@ -160,8 +145,6 @@ class MulingstreamChunkManager {
|
|
|
160
145
|
const raw = await this.redisClient.hgetall(this.chunkHashKey(cid));
|
|
161
146
|
return raw.chunkId ? this.hashToChunk(raw) : null;
|
|
162
147
|
}
|
|
163
|
-
/* ------------------------------ Updaters ------------------------------ */
|
|
164
|
-
/* helper to fetch-mutate-save one chunk */
|
|
165
148
|
async withChunk(roomId, n, fn) {
|
|
166
149
|
const cid = await this.getChunkId(roomId, n);
|
|
167
150
|
if (!cid)
|
|
@@ -178,12 +161,19 @@ class MulingstreamChunkManager {
|
|
|
178
161
|
sttStatus: chunk.sttStatus,
|
|
179
162
|
stt: this.serialize(chunk.stt),
|
|
180
163
|
translation: this.serialize(chunk.translation),
|
|
181
|
-
tts: this.serialize(chunk.tts)
|
|
164
|
+
tts: this.serialize(chunk.tts),
|
|
165
|
+
audioChunk: this.serialize(chunk.audioChunk)
|
|
182
166
|
});
|
|
183
167
|
p.expire(key, EXPIRATION);
|
|
184
168
|
await p.exec();
|
|
185
169
|
return out;
|
|
186
170
|
}
|
|
171
|
+
async updateAudioFilePath(roomId, n, audioFilePath) {
|
|
172
|
+
return ((await this.withChunk(roomId, n, (c) => {
|
|
173
|
+
c.audioChunk.audioFilePath = audioFilePath;
|
|
174
|
+
return true;
|
|
175
|
+
})) === true);
|
|
176
|
+
}
|
|
187
177
|
async updateStt(roomId, n, service, opt) {
|
|
188
178
|
return ((await this.withChunk(roomId, n, (c) => {
|
|
189
179
|
if (!c.stt[service])
|
|
@@ -304,7 +294,6 @@ class MulingstreamChunkManager {
|
|
|
304
294
|
const c = await this.getMulingstreamChunkById(roomId, n);
|
|
305
295
|
return !!c && Object.values(c.translation).every((t) => t.status !== 'INIT');
|
|
306
296
|
}
|
|
307
|
-
/* -------------------------- READY-TTS sequence ------------------------- */
|
|
308
297
|
async getAllReadyTts(roomId, lang) {
|
|
309
298
|
var _a;
|
|
310
299
|
const chunks = (_a = (await this.getMulingstreamChunksByRoom(roomId))) !== null && _a !== void 0 ? _a : [];
|