@mulingai-npm/redis 3.3.0 → 3.4.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.
@@ -7,6 +7,7 @@ export interface ChunkLogOptions {
7
7
  processLength?: boolean;
8
8
  finalTranscription?: boolean;
9
9
  sttStatus?: boolean;
10
+ audioFilePath?: boolean;
10
11
  stt?: boolean;
11
12
  translation?: boolean;
12
13
  tts?: boolean;
@@ -5,6 +5,7 @@ const mulingstream_chunk_manager_1 = require("../managers/mulingstream-chunk-man
5
5
  const defaults = {
6
6
  chunkId: false,
7
7
  chunkNumber: true,
8
+ audioFilePath: true,
8
9
  roomId: false,
9
10
  processLength: false,
10
11
  language: false,
@@ -61,6 +62,8 @@ class MulingstreamChunkLogger extends mulingstream_chunk_manager_1.MulingstreamC
61
62
  out.roomId = chunk.roomId;
62
63
  if (o.chunkNumber)
63
64
  out.chunkNumber = chunk.chunkNumber;
65
+ if (o.audioFilePath)
66
+ out.audioFilePath = chunk.audioChunk.audioFilePath;
64
67
  if (o.processLength)
65
68
  out.processLength = Date.now() - chunk.createdAt + 'ms';
66
69
  if (o.language)
@@ -42,7 +42,6 @@ export type MulingstreamChunkData = {
42
42
  ttsAudioPath: string;
43
43
  status: StepStatus;
44
44
  isEmitted: boolean;
45
- totalCheck: number;
46
45
  };
47
46
  };
48
47
  };
@@ -72,43 +71,42 @@ export declare class MulingstreamChunkManager {
72
71
  sttProviders: SttProvider[];
73
72
  targetLanguages: string[];
74
73
  shortCodeTargetLanguages: string[];
75
- }): Promise<void>;
74
+ }): Promise<MulingstreamChunkData>;
76
75
  private getChunkId;
77
76
  getMulingstreamChunkById(roomId: string, n: number): Promise<MulingstreamChunkData>;
78
77
  private withChunk;
79
- updateAudioFilePath(roomId: string, n: number, audioFilePath: string): Promise<boolean>;
78
+ updateAudioFilePath(roomId: string, chunkNumber: number, audioFilePath: string): Promise<MulingstreamChunkData | null>;
80
79
  updateStt(roomId: string, n: number, service: SttService, opt: {
81
80
  transcription?: string;
82
81
  sttStatus?: StepStatus;
83
- }): Promise<boolean>;
82
+ }): Promise<MulingstreamChunkData | null>;
84
83
  updateSttObject(roomId: string, n: number, newStt: Record<string, {
85
84
  transcription: string;
86
85
  model?: string;
87
86
  status: StepStatus;
88
- }>): Promise<boolean>;
89
- discardStt(roomId: string, n: number): Promise<boolean>;
87
+ }>): Promise<MulingstreamChunkData | null>;
88
+ discardStt(roomId: string, n: number): Promise<MulingstreamChunkData | null>;
89
+ updateSttAsUsed(roomId: string, chunkNumber: number): Promise<MulingstreamChunkData | null>;
90
90
  updateFinalTranscription(roomId: string, n: number, opt: {
91
91
  transcription?: string;
92
92
  sttStatus?: StepStatus;
93
- }): Promise<MulingstreamChunkData>;
94
- discardPostStt(roomId: string, n: number): Promise<boolean>;
95
- discardLanguage(roomId: string, n: number, lang: string): Promise<boolean>;
93
+ }): Promise<MulingstreamChunkData | null>;
94
+ discardPostStt(roomId: string, n: number): Promise<MulingstreamChunkData | null>;
95
+ discardLanguage(roomId: string, n: number, lang: string): Promise<MulingstreamChunkData | null>;
96
96
  discardLanguages(roomId: string, n: number, opt: {
97
97
  translation?: string[];
98
98
  tts?: string[];
99
- }): Promise<MulingstreamChunkData>;
99
+ }): Promise<MulingstreamChunkData | null>;
100
100
  updateTranslation(roomId: string, n: number, lang: string, opt: {
101
101
  translation?: string;
102
102
  status?: StepStatus;
103
- }): Promise<MulingstreamChunkData>;
104
- updateTranslationInBulk(roomId: string, n: number, dict: Record<string, string>, status?: StepStatus): Promise<MulingstreamChunkData>;
103
+ }): Promise<MulingstreamChunkData | null>;
104
+ updateTranslationInBulk(roomId: string, n: number, dict: Record<string, string>, status?: StepStatus): Promise<MulingstreamChunkData | null>;
105
105
  updateTts(roomId: string, n: number, lang: string, opt: {
106
106
  ttsAudioPath?: string;
107
107
  status?: StepStatus;
108
108
  isEmitted?: boolean;
109
- totalCheck?: number;
110
- }): Promise<MulingstreamChunkData>;
111
- increaseTotalCheck(roomId: string, n: number, lang: string): Promise<MulingstreamChunkData>;
109
+ }): Promise<MulingstreamChunkData | null>;
112
110
  areTranslationsProcessed(roomId: string, n: number): Promise<boolean>;
113
111
  getAllReadyTts(roomId: string, lang: string): Promise<MulingstreamChunkData[]>;
114
112
  }
@@ -42,7 +42,7 @@ class MulingstreamChunkManager {
42
42
  };
43
43
  }
44
44
  getTimeout(start, end) {
45
- return 30000;
45
+ return 25000;
46
46
  }
47
47
  async initRoom(roomId) {
48
48
  const exists = await this.redisClient.exists(this.roomZsetKey(roomId));
@@ -98,8 +98,25 @@ class MulingstreamChunkManager {
98
98
  const tts = {};
99
99
  shortCodeTargetLanguages.forEach((l) => {
100
100
  translation[l] = { translation: '', status: 'INIT' };
101
- tts[l] = { ttsAudioPath: '', status: 'INIT', isEmitted: false, totalCheck: 0 };
101
+ tts[l] = { ttsAudioPath: '', status: 'INIT', isEmitted: false };
102
102
  });
103
+ const createdAt = Date.now();
104
+ const chunk = {
105
+ chunkId,
106
+ roomId,
107
+ chunkNumber,
108
+ language,
109
+ sttProviders,
110
+ targetLanguages,
111
+ shortCodeTargetLanguages,
112
+ finalTranscription: '',
113
+ sttStatus: 'INIT',
114
+ createdAt,
115
+ audioChunk,
116
+ stt,
117
+ translation,
118
+ tts
119
+ };
103
120
  const hash = {
104
121
  chunkId,
105
122
  roomId,
@@ -110,7 +127,7 @@ class MulingstreamChunkManager {
110
127
  shortCodeTargetLanguages: this.serialize(shortCodeTargetLanguages),
111
128
  finalTranscription: '',
112
129
  sttStatus: 'INIT',
113
- createdAt: String(Date.now()),
130
+ createdAt: String(createdAt),
114
131
  audioChunk: this.serialize(audioChunk),
115
132
  stt: this.serialize(stt),
116
133
  translation: this.serialize(translation),
@@ -133,6 +150,7 @@ class MulingstreamChunkManager {
133
150
  oldIds.forEach((cid) => trim.unlink(this.chunkHashKey(cid)));
134
151
  await trim.exec();
135
152
  }
153
+ return chunk;
136
154
  }
137
155
  async getChunkId(roomId, n) {
138
156
  const ids = await this.redisClient.zrangebyscore(this.roomZsetKey(roomId), n, n);
@@ -154,7 +172,7 @@ class MulingstreamChunkManager {
154
172
  if (!raw.chunkId)
155
173
  return null;
156
174
  const chunk = this.hashToChunk(raw);
157
- const out = await fn(chunk);
175
+ await fn(chunk);
158
176
  const p = this.redisClient.pipeline();
159
177
  p.hset(key, {
160
178
  finalTranscription: chunk.finalTranscription,
@@ -166,41 +184,44 @@ class MulingstreamChunkManager {
166
184
  });
167
185
  p.expire(key, EXPIRATION);
168
186
  await p.exec();
169
- return out;
187
+ return chunk;
170
188
  }
171
- async updateAudioFilePath(roomId, n, audioFilePath) {
172
- return ((await this.withChunk(roomId, n, (c) => {
173
- c.audioChunk.audioFilePath = audioFilePath;
174
- return true;
175
- })) === true);
189
+ async updateAudioFilePath(roomId, chunkNumber, audioFilePath) {
190
+ return this.withChunk(roomId, chunkNumber, (chunk) => {
191
+ chunk.audioChunk.audioFilePath = audioFilePath;
192
+ });
176
193
  }
177
194
  async updateStt(roomId, n, service, opt) {
178
- return ((await this.withChunk(roomId, n, (c) => {
195
+ return this.withChunk(roomId, n, (c) => {
179
196
  if (!c.stt[service])
180
- return false;
197
+ return;
181
198
  if (opt.transcription !== undefined)
182
199
  c.stt[service].transcription = opt.transcription;
183
200
  if (opt.sttStatus !== undefined)
184
201
  c.stt[service].status = opt.sttStatus;
185
- return true;
186
- })) === true);
202
+ });
187
203
  }
188
204
  async updateSttObject(roomId, n, newStt) {
189
- return ((await this.withChunk(roomId, n, (c) => {
205
+ return this.withChunk(roomId, n, (c) => {
190
206
  c.stt = newStt;
191
- return true;
192
- })) === true);
207
+ });
193
208
  }
194
209
  async discardStt(roomId, n) {
195
- return ((await this.withChunk(roomId, n, (c) => {
210
+ return this.withChunk(roomId, n, (c) => {
196
211
  Object.keys(c.stt).forEach((p) => {
197
212
  c.stt[p].transcription = '';
198
213
  c.stt[p].status = 'DISCARDED';
199
214
  });
200
215
  c.finalTranscription = '';
201
216
  c.sttStatus = 'DISCARDED';
202
- return true;
203
- })) === true);
217
+ });
218
+ }
219
+ async updateSttAsUsed(roomId, chunkNumber) {
220
+ return this.withChunk(roomId, chunkNumber, (chunk) => {
221
+ Object.keys(chunk.stt).forEach((sttProvider) => {
222
+ chunk.stt[sttProvider].status = 'USED';
223
+ });
224
+ });
204
225
  }
205
226
  async updateFinalTranscription(roomId, n, opt) {
206
227
  return this.withChunk(roomId, n, (c) => {
@@ -208,24 +229,21 @@ class MulingstreamChunkManager {
208
229
  c.finalTranscription = opt.transcription;
209
230
  if (opt.sttStatus !== undefined)
210
231
  c.sttStatus = opt.sttStatus;
211
- return c;
212
232
  });
213
233
  }
214
234
  async discardPostStt(roomId, n) {
215
- return ((await this.withChunk(roomId, n, (c) => {
235
+ return this.withChunk(roomId, n, (c) => {
216
236
  Object.values(c.translation).forEach((t) => (t.status = 'DISCARDED'));
217
237
  Object.values(c.tts).forEach((t) => (t.status = 'DISCARDED'));
218
- return true;
219
- })) === true);
238
+ });
220
239
  }
221
240
  async discardLanguage(roomId, n, lang) {
222
- return ((await this.withChunk(roomId, n, (c) => {
241
+ return this.withChunk(roomId, n, (c) => {
223
242
  if (c.translation[lang])
224
243
  c.translation[lang].status = 'DISCARDED';
225
244
  if (c.tts[lang])
226
245
  c.tts[lang].status = 'DISCARDED';
227
- return true;
228
- })) === true);
246
+ });
229
247
  }
230
248
  async discardLanguages(roomId, n, opt) {
231
249
  return this.withChunk(roomId, n, (c) => {
@@ -240,19 +258,17 @@ class MulingstreamChunkManager {
240
258
  if (e && e.status === 'INIT')
241
259
  e.status = 'DISCARDED';
242
260
  });
243
- return c;
244
261
  });
245
262
  }
246
263
  async updateTranslation(roomId, n, lang, opt) {
247
264
  return this.withChunk(roomId, n, (c) => {
248
265
  const e = c.translation[lang];
249
266
  if (!e)
250
- return null;
267
+ return;
251
268
  if (opt.translation !== undefined)
252
269
  e.translation = opt.translation;
253
270
  if (opt.status !== undefined)
254
271
  e.status = opt.status;
255
- return c;
256
272
  });
257
273
  }
258
274
  async updateTranslationInBulk(roomId, n, dict, status = 'READY') {
@@ -263,31 +279,19 @@ class MulingstreamChunkManager {
263
279
  c.translation[l].translation = txt;
264
280
  c.translation[l].status = status;
265
281
  });
266
- return c;
267
282
  });
268
283
  }
269
284
  async updateTts(roomId, n, lang, opt) {
270
285
  return this.withChunk(roomId, n, (c) => {
271
286
  const e = c.tts[lang];
272
287
  if (!e)
273
- return null;
288
+ return;
274
289
  if (opt.ttsAudioPath !== undefined)
275
290
  e.ttsAudioPath = opt.ttsAudioPath;
276
291
  if (opt.status !== undefined)
277
292
  e.status = opt.status;
278
293
  if (opt.isEmitted !== undefined)
279
294
  e.isEmitted = opt.isEmitted;
280
- if (opt.totalCheck !== undefined)
281
- e.totalCheck = opt.totalCheck;
282
- return c;
283
- });
284
- }
285
- async increaseTotalCheck(roomId, n, lang) {
286
- return this.withChunk(roomId, n, (c) => {
287
- if (!c.tts[lang])
288
- return null;
289
- c.tts[lang].totalCheck += 1;
290
- return c;
291
295
  });
292
296
  }
293
297
  async areTranslationsProcessed(roomId, n) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "3.3.0",
3
+ "version": "3.4.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {