@mulingai-npm/redis 1.13.0 → 1.14.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.
- package/dist/enums/redis-database.d.ts +1 -1
- package/dist/enums/redis-database.js +1 -1
- package/dist/managers/mulingstream-chunk-manager.d.ts +15 -0
- package/dist/managers/mulingstream-chunk-manager.js +78 -0
- package/dist/managers/mulingstream-room-tracker.d.ts +10 -0
- package/dist/managers/mulingstream-room-tracker.js +41 -0
- package/package.json +1 -1
|
@@ -4,6 +4,6 @@ exports.RedisDatabase = void 0;
|
|
|
4
4
|
var RedisDatabase;
|
|
5
5
|
(function (RedisDatabase) {
|
|
6
6
|
RedisDatabase[RedisDatabase["MULINGSTREAM_LISTENER"] = 0] = "MULINGSTREAM_LISTENER";
|
|
7
|
-
RedisDatabase[RedisDatabase["
|
|
7
|
+
RedisDatabase[RedisDatabase["MULINGSTREAM_ROOM_TRACKER"] = 1] = "MULINGSTREAM_ROOM_TRACKER";
|
|
8
8
|
RedisDatabase[RedisDatabase["MULINGSTREAM_CHUNK"] = 2] = "MULINGSTREAM_CHUNK";
|
|
9
9
|
})(RedisDatabase = exports.RedisDatabase || (exports.RedisDatabase = {}));
|
|
@@ -67,4 +67,19 @@ export declare class MulingstreamChunkManager {
|
|
|
67
67
|
updateFinalTranscription(mulingstreamChunkId: string, finalTranscription: string): Promise<boolean>;
|
|
68
68
|
updateSttStatus(mulingstreamChunkId: string, service: SttProvider, status: StepStatus): Promise<boolean>;
|
|
69
69
|
updateTranscription(mulingstreamChunkId: string, service: SttProvider, transcription: string, sttStatus: StepStatus): Promise<boolean>;
|
|
70
|
+
/****
|
|
71
|
+
* Discards all post-STT steps for a given chunk, i.e. sets
|
|
72
|
+
* all translation[].status and all tts[].status to "DISCARDED".
|
|
73
|
+
****/
|
|
74
|
+
discardAllPostStt(mulingstreamChunkId: string): Promise<boolean>;
|
|
75
|
+
/****
|
|
76
|
+
* Discards all post-translation steps for a given chunk, i.e. sets
|
|
77
|
+
* all tts[].status to "DISCARDED" (leaves translation alone).
|
|
78
|
+
****/
|
|
79
|
+
discardAllPostTranslation(mulingstreamChunkId: string): Promise<boolean>;
|
|
80
|
+
/****
|
|
81
|
+
* Discards a specific language in both the translation and tts objects,
|
|
82
|
+
* setting status to DISCARDED for just that one language.
|
|
83
|
+
****/
|
|
84
|
+
discardLanguage(mulingstreamChunkId: string, language: string): Promise<boolean>;
|
|
70
85
|
}
|
|
@@ -206,5 +206,83 @@ class MulingstreamChunkManager {
|
|
|
206
206
|
});
|
|
207
207
|
return true;
|
|
208
208
|
}
|
|
209
|
+
/****
|
|
210
|
+
* Discards all post-STT steps for a given chunk, i.e. sets
|
|
211
|
+
* all translation[].status and all tts[].status to "DISCARDED".
|
|
212
|
+
****/
|
|
213
|
+
async discardAllPostStt(mulingstreamChunkId) {
|
|
214
|
+
// Fetch the chunk
|
|
215
|
+
const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
|
|
216
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
// Parse the translation and tts objects
|
|
220
|
+
const translation = JSON.parse(data.translation);
|
|
221
|
+
const tts = JSON.parse(data.tts);
|
|
222
|
+
// Set every language status to DISCARDED in translation
|
|
223
|
+
for (const lang of Object.keys(translation)) {
|
|
224
|
+
translation[lang].status = 'DISCARDED';
|
|
225
|
+
}
|
|
226
|
+
// Set every language status to DISCARDED in tts
|
|
227
|
+
for (const lang of Object.keys(tts)) {
|
|
228
|
+
tts[lang].status = 'DISCARDED';
|
|
229
|
+
}
|
|
230
|
+
// Write back
|
|
231
|
+
await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
|
|
232
|
+
translation: JSON.stringify(translation),
|
|
233
|
+
tts: JSON.stringify(tts)
|
|
234
|
+
});
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
/****
|
|
238
|
+
* Discards all post-translation steps for a given chunk, i.e. sets
|
|
239
|
+
* all tts[].status to "DISCARDED" (leaves translation alone).
|
|
240
|
+
****/
|
|
241
|
+
async discardAllPostTranslation(mulingstreamChunkId) {
|
|
242
|
+
// Fetch the chunk
|
|
243
|
+
const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
|
|
244
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
// Parse the tts object
|
|
248
|
+
const tts = JSON.parse(data.tts);
|
|
249
|
+
// Set every language status to DISCARDED in tts
|
|
250
|
+
for (const lang of Object.keys(tts)) {
|
|
251
|
+
tts[lang].status = 'DISCARDED';
|
|
252
|
+
}
|
|
253
|
+
// Write back
|
|
254
|
+
await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
|
|
255
|
+
tts: JSON.stringify(tts)
|
|
256
|
+
});
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
/****
|
|
260
|
+
* Discards a specific language in both the translation and tts objects,
|
|
261
|
+
* setting status to DISCARDED for just that one language.
|
|
262
|
+
****/
|
|
263
|
+
async discardLanguage(mulingstreamChunkId, language) {
|
|
264
|
+
// Fetch the chunk
|
|
265
|
+
const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
|
|
266
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
// Parse the translation and tts objects
|
|
270
|
+
const translation = JSON.parse(data.translation);
|
|
271
|
+
const tts = JSON.parse(data.tts);
|
|
272
|
+
// If the language exists in translation, discard
|
|
273
|
+
if (translation[language]) {
|
|
274
|
+
translation[language].status = 'DISCARDED';
|
|
275
|
+
}
|
|
276
|
+
// If the language exists in tts, discard
|
|
277
|
+
if (tts[language]) {
|
|
278
|
+
tts[language].status = 'DISCARDED';
|
|
279
|
+
}
|
|
280
|
+
// Write back
|
|
281
|
+
await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
|
|
282
|
+
translation: JSON.stringify(translation),
|
|
283
|
+
tts: JSON.stringify(tts)
|
|
284
|
+
});
|
|
285
|
+
return true;
|
|
286
|
+
}
|
|
209
287
|
}
|
|
210
288
|
exports.MulingstreamChunkManager = MulingstreamChunkManager;
|
|
@@ -3,9 +3,14 @@ export type SttProvider = 'azure' | 'whisper' | 'google' | 'aws';
|
|
|
3
3
|
export type MulingstreamRoomData = {
|
|
4
4
|
mulingstreamRoomTrackerId: string;
|
|
5
5
|
roomId: string;
|
|
6
|
+
sttProviders: SttProvider[];
|
|
7
|
+
targetLanguages: string[];
|
|
6
8
|
lastReadyChunk: number;
|
|
7
9
|
lastUsedChunk: number;
|
|
8
10
|
lastDiscardedChunk: number;
|
|
11
|
+
lastReadyTranscription: number;
|
|
12
|
+
lastUsedTranscription: number;
|
|
13
|
+
lastDiscardedTranscription: number;
|
|
9
14
|
stt: {
|
|
10
15
|
[sttProvider: string]: {
|
|
11
16
|
lastReadyStt: number;
|
|
@@ -58,6 +63,11 @@ export declare class MulingstreamRoomTracker {
|
|
|
58
63
|
* Any argument passed as null means "do not update that field."
|
|
59
64
|
*/
|
|
60
65
|
updateChunkTracker(roomId: string, lastReadyChunk: number | null, lastUsedChunk: number | null, lastDiscardedChunk: number | null): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Updates the transcription tracker fields (lastReadyTranscription, lastUsedTranscription , lastDiscardedTranscription).
|
|
68
|
+
* Any argument passed as null means "do not update that field."
|
|
69
|
+
*/
|
|
70
|
+
updateTranscriptionTracker(roomId: string, lastReadyTranscription: number | null, lastUsedTranscription: number | null, lastDiscardedTranscription: number | null): Promise<boolean>;
|
|
61
71
|
/**
|
|
62
72
|
* Updates the stt tracker for a specific STT provider in the room.
|
|
63
73
|
* If any argument is null, we do not update that field.
|
|
@@ -7,15 +7,23 @@ class MulingstreamRoomTracker {
|
|
|
7
7
|
this.redisClient = redisClient;
|
|
8
8
|
}
|
|
9
9
|
parseHashData(data) {
|
|
10
|
+
// Parse any JSON fields
|
|
11
|
+
const sttProviders = JSON.parse(data.sttProviders);
|
|
12
|
+
const targetLanguages = JSON.parse(data.targetLanguages);
|
|
10
13
|
const stt = JSON.parse(data.stt);
|
|
11
14
|
const translation = JSON.parse(data.translation);
|
|
12
15
|
const tts = JSON.parse(data.tts);
|
|
13
16
|
return {
|
|
14
17
|
mulingstreamRoomTrackerId: data.mulingstreamRoomTrackerId,
|
|
15
18
|
roomId: data.roomId,
|
|
19
|
+
sttProviders,
|
|
20
|
+
targetLanguages,
|
|
16
21
|
lastReadyChunk: parseInt(data.lastReadyChunk, 10),
|
|
17
22
|
lastUsedChunk: parseInt(data.lastUsedChunk, 10),
|
|
18
23
|
lastDiscardedChunk: parseInt(data.lastDiscardedChunk, 10),
|
|
24
|
+
lastReadyTranscription: parseInt(data.lastReadyTranscription, 10),
|
|
25
|
+
lastUsedTranscription: parseInt(data.lastUsedTranscription, 10),
|
|
26
|
+
lastDiscardedTranscription: parseInt(data.lastDiscardedTranscription, 10),
|
|
19
27
|
stt,
|
|
20
28
|
translation,
|
|
21
29
|
tts
|
|
@@ -67,13 +75,21 @@ class MulingstreamRoomTracker {
|
|
|
67
75
|
const lastReadyChunk = -1;
|
|
68
76
|
const lastUsedChunk = -1;
|
|
69
77
|
const lastDiscardedChunk = -1;
|
|
78
|
+
const lastReadyTranscription = -1;
|
|
79
|
+
const lastUsedTranscription = -1;
|
|
80
|
+
const lastDiscardedTranscription = -1;
|
|
70
81
|
// Store everything in Redis
|
|
71
82
|
await this.redisClient.hset(`mulingstreamRoomTracker:${mulingstreamRoomTrackerId}`, {
|
|
72
83
|
mulingstreamRoomTrackerId,
|
|
73
84
|
roomId,
|
|
85
|
+
sttProviders: JSON.stringify(sttProviders),
|
|
86
|
+
targetLanguages: JSON.stringify(targetLanguages),
|
|
74
87
|
lastReadyChunk: lastReadyChunk.toString(),
|
|
75
88
|
lastUsedChunk: lastUsedChunk.toString(),
|
|
76
89
|
lastDiscardedChunk: lastDiscardedChunk.toString(),
|
|
90
|
+
lastReadyTranscription: lastReadyTranscription.toString(),
|
|
91
|
+
lastUsedTranscription: lastUsedTranscription.toString(),
|
|
92
|
+
lastDiscardedTranscription: lastDiscardedTranscription.toString(),
|
|
77
93
|
stt: JSON.stringify(stt),
|
|
78
94
|
translation: JSON.stringify(translation),
|
|
79
95
|
tts: JSON.stringify(tts)
|
|
@@ -136,6 +152,31 @@ class MulingstreamRoomTracker {
|
|
|
136
152
|
}
|
|
137
153
|
return true;
|
|
138
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Updates the transcription tracker fields (lastReadyTranscription, lastUsedTranscription , lastDiscardedTranscription).
|
|
157
|
+
* Any argument passed as null means "do not update that field."
|
|
158
|
+
*/
|
|
159
|
+
async updateTranscriptionTracker(roomId, lastReadyTranscription, lastUsedTranscription, lastDiscardedTranscription) {
|
|
160
|
+
const mulingstreamRoomTrackerId = `[${roomId}]`;
|
|
161
|
+
const data = await this.redisClient.hgetall(`mulingstreamRoomTracker:${mulingstreamRoomTrackerId}`);
|
|
162
|
+
if (!data || !data.mulingstreamRoomTrackerId) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
const updates = {};
|
|
166
|
+
if (lastReadyTranscription !== null) {
|
|
167
|
+
updates.lastReadyTranscription = lastReadyTranscription.toString();
|
|
168
|
+
}
|
|
169
|
+
if (lastUsedTranscription !== null) {
|
|
170
|
+
updates.lastUsedTranscription = lastUsedTranscription.toString();
|
|
171
|
+
}
|
|
172
|
+
if (lastDiscardedTranscription !== null) {
|
|
173
|
+
updates.lastDiscardedTranscription = lastDiscardedTranscription.toString();
|
|
174
|
+
}
|
|
175
|
+
if (Object.keys(updates).length > 0) {
|
|
176
|
+
await this.redisClient.hset(`mulingstreamRoomTracker:${mulingstreamRoomTrackerId}`, updates);
|
|
177
|
+
}
|
|
178
|
+
return true;
|
|
179
|
+
}
|
|
139
180
|
/**
|
|
140
181
|
* Updates the stt tracker for a specific STT provider in the room.
|
|
141
182
|
* If any argument is null, we do not update that field.
|