@mulingai-npm/redis 3.3.0 → 3.4.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.
@@ -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,41 @@ 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>;
90
89
  updateFinalTranscription(roomId: string, n: number, opt: {
91
90
  transcription?: string;
92
91
  sttStatus?: StepStatus;
93
- }): Promise<MulingstreamChunkData>;
94
- discardPostStt(roomId: string, n: number): Promise<boolean>;
95
- discardLanguage(roomId: string, n: number, lang: string): Promise<boolean>;
92
+ }): Promise<MulingstreamChunkData | null>;
93
+ discardPostStt(roomId: string, n: number): Promise<MulingstreamChunkData | null>;
94
+ discardLanguage(roomId: string, n: number, lang: string): Promise<MulingstreamChunkData | null>;
96
95
  discardLanguages(roomId: string, n: number, opt: {
97
96
  translation?: string[];
98
97
  tts?: string[];
99
- }): Promise<MulingstreamChunkData>;
98
+ }): Promise<MulingstreamChunkData | null>;
100
99
  updateTranslation(roomId: string, n: number, lang: string, opt: {
101
100
  translation?: string;
102
101
  status?: StepStatus;
103
- }): Promise<MulingstreamChunkData>;
104
- updateTranslationInBulk(roomId: string, n: number, dict: Record<string, string>, status?: StepStatus): Promise<MulingstreamChunkData>;
102
+ }): Promise<MulingstreamChunkData | null>;
103
+ updateTranslationInBulk(roomId: string, n: number, dict: Record<string, string>, status?: StepStatus): Promise<MulingstreamChunkData | null>;
105
104
  updateTts(roomId: string, n: number, lang: string, opt: {
106
105
  ttsAudioPath?: string;
107
106
  status?: StepStatus;
108
107
  isEmitted?: boolean;
109
- totalCheck?: number;
110
- }): Promise<MulingstreamChunkData>;
111
- increaseTotalCheck(roomId: string, n: number, lang: string): Promise<MulingstreamChunkData>;
108
+ }): Promise<MulingstreamChunkData | null>;
112
109
  areTranslationsProcessed(roomId: string, n: number): Promise<boolean>;
113
110
  getAllReadyTts(roomId: string, lang: string): Promise<MulingstreamChunkData[]>;
114
111
  }
@@ -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,37 @@ 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
+ });
204
218
  }
205
219
  async updateFinalTranscription(roomId, n, opt) {
206
220
  return this.withChunk(roomId, n, (c) => {
@@ -208,24 +222,21 @@ class MulingstreamChunkManager {
208
222
  c.finalTranscription = opt.transcription;
209
223
  if (opt.sttStatus !== undefined)
210
224
  c.sttStatus = opt.sttStatus;
211
- return c;
212
225
  });
213
226
  }
214
227
  async discardPostStt(roomId, n) {
215
- return ((await this.withChunk(roomId, n, (c) => {
228
+ return this.withChunk(roomId, n, (c) => {
216
229
  Object.values(c.translation).forEach((t) => (t.status = 'DISCARDED'));
217
230
  Object.values(c.tts).forEach((t) => (t.status = 'DISCARDED'));
218
- return true;
219
- })) === true);
231
+ });
220
232
  }
221
233
  async discardLanguage(roomId, n, lang) {
222
- return ((await this.withChunk(roomId, n, (c) => {
234
+ return this.withChunk(roomId, n, (c) => {
223
235
  if (c.translation[lang])
224
236
  c.translation[lang].status = 'DISCARDED';
225
237
  if (c.tts[lang])
226
238
  c.tts[lang].status = 'DISCARDED';
227
- return true;
228
- })) === true);
239
+ });
229
240
  }
230
241
  async discardLanguages(roomId, n, opt) {
231
242
  return this.withChunk(roomId, n, (c) => {
@@ -240,19 +251,17 @@ class MulingstreamChunkManager {
240
251
  if (e && e.status === 'INIT')
241
252
  e.status = 'DISCARDED';
242
253
  });
243
- return c;
244
254
  });
245
255
  }
246
256
  async updateTranslation(roomId, n, lang, opt) {
247
257
  return this.withChunk(roomId, n, (c) => {
248
258
  const e = c.translation[lang];
249
259
  if (!e)
250
- return null;
260
+ return;
251
261
  if (opt.translation !== undefined)
252
262
  e.translation = opt.translation;
253
263
  if (opt.status !== undefined)
254
264
  e.status = opt.status;
255
- return c;
256
265
  });
257
266
  }
258
267
  async updateTranslationInBulk(roomId, n, dict, status = 'READY') {
@@ -263,31 +272,19 @@ class MulingstreamChunkManager {
263
272
  c.translation[l].translation = txt;
264
273
  c.translation[l].status = status;
265
274
  });
266
- return c;
267
275
  });
268
276
  }
269
277
  async updateTts(roomId, n, lang, opt) {
270
278
  return this.withChunk(roomId, n, (c) => {
271
279
  const e = c.tts[lang];
272
280
  if (!e)
273
- return null;
281
+ return;
274
282
  if (opt.ttsAudioPath !== undefined)
275
283
  e.ttsAudioPath = opt.ttsAudioPath;
276
284
  if (opt.status !== undefined)
277
285
  e.status = opt.status;
278
286
  if (opt.isEmitted !== undefined)
279
287
  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
288
  });
292
289
  }
293
290
  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.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {