@mulingai-npm/redis 2.1.2 → 2.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.
|
@@ -59,14 +59,7 @@ export declare class MulingstreamChunkManager {
|
|
|
59
59
|
* or null if the room doesn't exist in Redis.
|
|
60
60
|
*/
|
|
61
61
|
getMulingstreamChunksByRoom(roomId: string): Promise<MulingstreamChunkData[] | null>;
|
|
62
|
-
/**
|
|
63
|
-
* Returns the room array "as is" for debugging
|
|
64
|
-
* (same as getMulingstreamChunksByRoom in this example).
|
|
65
|
-
*/
|
|
66
62
|
getRoomById(roomId: string): Promise<MulingstreamChunkData[] | null>;
|
|
67
|
-
/**
|
|
68
|
-
* Adds a new Mulingstream chunk to the array stored at [${roomId}].
|
|
69
|
-
*/
|
|
70
63
|
addMulingstreamChunk(params: {
|
|
71
64
|
roomId: string;
|
|
72
65
|
chunkNumber: number;
|
|
@@ -107,4 +100,8 @@ export declare class MulingstreamChunkManager {
|
|
|
107
100
|
* Discards a specific language in both translation and tts for a chunk.
|
|
108
101
|
*/
|
|
109
102
|
discardLanguage(roomId: string, chunkNumber: number, language: string): Promise<boolean>;
|
|
103
|
+
updateTranslation(roomId: string, chunkNumber: number, language: string, options: {
|
|
104
|
+
translation?: string;
|
|
105
|
+
status?: StepStatus;
|
|
106
|
+
}): Promise<boolean>;
|
|
110
107
|
}
|
|
@@ -47,25 +47,12 @@ class MulingstreamChunkManager {
|
|
|
47
47
|
}
|
|
48
48
|
return chunks;
|
|
49
49
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Returns the room array "as is" for debugging
|
|
52
|
-
* (same as getMulingstreamChunksByRoom in this example).
|
|
53
|
-
*/
|
|
54
50
|
async getRoomById(roomId) {
|
|
55
51
|
return this.getMulingstreamChunksByRoom(roomId);
|
|
56
52
|
}
|
|
57
|
-
/**
|
|
58
|
-
* Adds a new Mulingstream chunk to the array stored at [${roomId}].
|
|
59
|
-
*/
|
|
60
53
|
async addMulingstreamChunk(params) {
|
|
54
|
+
var _a;
|
|
61
55
|
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, sttProviders, translationTargetLanguages, ttsTargetLanguages } = params;
|
|
62
|
-
// ensure we only keep the last 5 elements
|
|
63
|
-
const currentLength = await this.redisClient.jsonArrLen(`[${roomId}]`, '.');
|
|
64
|
-
if ((currentLength !== null && currentLength !== void 0 ? currentLength : 0) >= ROOM_ARRAY_LENGTH) {
|
|
65
|
-
// remove the oldest (front of the array)
|
|
66
|
-
await this.redisClient.jsonArrPop(`[${roomId}]`, '.', 0);
|
|
67
|
-
}
|
|
68
|
-
// Build the chunk
|
|
69
56
|
const audioChunk = {
|
|
70
57
|
start,
|
|
71
58
|
end,
|
|
@@ -75,25 +62,23 @@ class MulingstreamChunkManager {
|
|
|
75
62
|
theme,
|
|
76
63
|
processingStart: Date.now()
|
|
77
64
|
};
|
|
78
|
-
// Build stt object
|
|
79
65
|
const stt = {};
|
|
80
|
-
for (const
|
|
81
|
-
stt[
|
|
66
|
+
for (const sttProvider of sttProviders) {
|
|
67
|
+
stt[sttProvider] = {
|
|
82
68
|
transcription: '',
|
|
83
69
|
status: 'INIT'
|
|
84
70
|
};
|
|
85
71
|
}
|
|
86
|
-
// Build translation and tts objects
|
|
87
72
|
const translation = {};
|
|
88
73
|
const tts = {};
|
|
89
|
-
for (const
|
|
90
|
-
translation[
|
|
74
|
+
for (const lang of translationTargetLanguages) {
|
|
75
|
+
translation[lang] = {
|
|
91
76
|
translation: '',
|
|
92
77
|
status: 'INIT'
|
|
93
78
|
};
|
|
94
79
|
}
|
|
95
|
-
for (const
|
|
96
|
-
tts[
|
|
80
|
+
for (const lang of ttsTargetLanguages) {
|
|
81
|
+
tts[lang] = {
|
|
97
82
|
ttsAudioPath: '',
|
|
98
83
|
status: 'INIT',
|
|
99
84
|
isEmitted: false
|
|
@@ -113,9 +98,19 @@ class MulingstreamChunkManager {
|
|
|
113
98
|
translation,
|
|
114
99
|
tts
|
|
115
100
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
101
|
+
const chunks = (_a = (await this.redisClient.jsonGet(`[${roomId}]`, '.'))) !== null && _a !== void 0 ? _a : [];
|
|
102
|
+
const idx = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
|
|
103
|
+
if (idx !== -1) {
|
|
104
|
+
chunks[idx] = newChunk;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
chunks.push(newChunk);
|
|
108
|
+
if (chunks.length > ROOM_ARRAY_LENGTH) {
|
|
109
|
+
chunks.shift();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
113
|
+
await this.redisClient.expire(`[${roomId}]`, EXPIRATION);
|
|
119
114
|
}
|
|
120
115
|
/**
|
|
121
116
|
* Given roomId and chunkNumber, return the single chunk from the array
|
|
@@ -220,5 +215,30 @@ class MulingstreamChunkManager {
|
|
|
220
215
|
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
221
216
|
return true;
|
|
222
217
|
}
|
|
218
|
+
async updateTranslation(roomId, chunkNumber, language, options) {
|
|
219
|
+
// Fetch all chunks for this room
|
|
220
|
+
const chunks = await this.getMulingstreamChunksByRoom(roomId);
|
|
221
|
+
if (!chunks)
|
|
222
|
+
return false;
|
|
223
|
+
// Locate the target chunk
|
|
224
|
+
const chunkIndex = chunks.findIndex((c) => c.chunkNumber === chunkNumber);
|
|
225
|
+
if (chunkIndex === -1)
|
|
226
|
+
return false;
|
|
227
|
+
const chunk = chunks[chunkIndex];
|
|
228
|
+
// Make sure the requested language exists in this chunk
|
|
229
|
+
if (!chunk.translation[language]) {
|
|
230
|
+
return false;
|
|
231
|
+
}
|
|
232
|
+
if (options.translation !== undefined) {
|
|
233
|
+
chunk.translation[language].translation = options.translation;
|
|
234
|
+
}
|
|
235
|
+
if (options.status !== undefined) {
|
|
236
|
+
chunk.translation[language].status = options.status;
|
|
237
|
+
}
|
|
238
|
+
// Persist the whole array back to Redis
|
|
239
|
+
chunks[chunkIndex] = chunk;
|
|
240
|
+
await this.redisClient.jsonSet(`[${roomId}]`, '.', chunks);
|
|
241
|
+
return true;
|
|
242
|
+
}
|
|
223
243
|
}
|
|
224
244
|
exports.MulingstreamChunkManager = MulingstreamChunkManager;
|