@mulingai-npm/redis 2.12.0 → 2.12.2

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.
@@ -44,6 +44,7 @@ export type MulingstreamChunkData = {
44
44
  export declare class MulingstreamChunkManager {
45
45
  private redisClient;
46
46
  constructor(redisClient: RedisClient);
47
+ private getTimeout;
47
48
  /**
48
49
  * Initializes a room in Redis as an empty JSON array.
49
50
  * If the key [roomId] already exists, we do NOT overwrite it.
@@ -124,5 +125,5 @@ export declare class MulingstreamChunkManager {
124
125
  }): Promise<MulingstreamChunkData | null>;
125
126
  increaseTotalCheck(roomId: string, chunkNumber: number, language: string): Promise<MulingstreamChunkData | null>;
126
127
  areTranslationsProcessed(roomId: string, chunkNumber: number): Promise<boolean>;
127
- getAllReadyTts(roomId: string, language: string, timeoutMs?: number): Promise<MulingstreamChunkData[]>;
128
+ getAllReadyTts(roomId: string, language: string): Promise<MulingstreamChunkData[]>;
128
129
  }
@@ -7,6 +7,30 @@ class MulingstreamChunkManager {
7
7
  constructor(redisClient) {
8
8
  this.redisClient = redisClient;
9
9
  }
10
+ getTimeout(audioStart, audioEnd) {
11
+ const audioChunkLength = audioEnd - audioStart;
12
+ if (audioChunkLength < 1000) {
13
+ return 1500;
14
+ }
15
+ else if (audioChunkLength >= 1000 && audioChunkLength < 3000) {
16
+ return 3000;
17
+ }
18
+ else if (audioChunkLength >= 3000 && audioChunkLength < 5000) {
19
+ return 7000;
20
+ }
21
+ else if (audioChunkLength >= 5000 && audioChunkLength < 8000) {
22
+ return 10000;
23
+ }
24
+ else if (audioChunkLength >= 8000 && audioChunkLength < 12000) {
25
+ return 15000;
26
+ }
27
+ else if (audioChunkLength >= 12000 && audioChunkLength < 20000) {
28
+ return 20000;
29
+ }
30
+ else {
31
+ return 30000;
32
+ }
33
+ }
10
34
  /**
11
35
  * Initializes a room in Redis as an empty JSON array.
12
36
  * If the key [roomId] already exists, we do NOT overwrite it.
@@ -395,11 +419,12 @@ class MulingstreamChunkManager {
395
419
  }
396
420
  return Object.values(chunk.translation).every((t) => t.status !== 'INIT');
397
421
  }
398
- async getAllReadyTts(roomId, language, timeoutMs = 15000) {
422
+ async getAllReadyTts(roomId, language) {
399
423
  const chunks = await this.getMulingstreamChunksByRoom(roomId);
400
424
  if (!(chunks === null || chunks === void 0 ? void 0 : chunks.length))
401
425
  return [];
402
- chunks.sort((a, b) => a.chunkNumber - b.chunkNumber);
426
+ // chunks are received in consecutive order already, no need for sorting for now (maybe in the future we have more speaker in a room, so we may need sorting)
427
+ // chunks.sort((a, b) => a.chunkNumber - b.chunkNumber);
403
428
  /* ---- isolate the tail where the language exists ---- */
404
429
  let lastLangIdx = -1;
405
430
  for (let i = chunks.length - 1; i >= 0; i--) {
@@ -431,13 +456,15 @@ class MulingstreamChunkManager {
431
456
  const now = Date.now();
432
457
  for (let i = lastDone + 1; i < window.length; i++) {
433
458
  const entry = window[i].tts[language];
459
+ const audioChunk = window[i].audioChunk;
434
460
  if (entry.status === 'INIT') {
435
- console.log(now - window[i].createdAt, ' --- ', window[i].chunkNumber);
436
- if (now - window[i].createdAt > timeoutMs) {
461
+ const timeout = this.getTimeout(audioChunk.start, audioChunk.end);
462
+ console.log('AUDIO LENGTH: ', audioChunk.end - audioChunk.start, ' TIMEOUT BASED ON AUDIO LENGTH: ', timeout, ' SINCE CREATED UNTIL NOW: ', now - window[i].createdAt);
463
+ if (now - window[i].createdAt > timeout) {
437
464
  entry.status = 'DISCARDED';
438
465
  }
439
466
  else {
440
- blocked = true; // still waiting ⇒ cannot emit READYs
467
+ blocked = true;
441
468
  }
442
469
  continue;
443
470
  }
@@ -0,0 +1 @@
1
+ export declare function getMappedLanguage(lang: string, targetLanguages: string[], shortCodeTargetLanguages: string[]): string | null;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMappedLanguage = void 0;
4
+ function getMappedLanguage(lang, targetLanguages, shortCodeTargetLanguages) {
5
+ // Full → short
6
+ let idx = targetLanguages.indexOf(lang);
7
+ if (idx !== -1) {
8
+ return shortCodeTargetLanguages[idx];
9
+ }
10
+ // Short → full
11
+ idx = shortCodeTargetLanguages.indexOf(lang);
12
+ if (idx !== -1) {
13
+ return targetLanguages[idx];
14
+ }
15
+ // No match
16
+ return '';
17
+ }
18
+ exports.getMappedLanguage = getMappedLanguage;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "2.12.0",
3
+ "version": "2.12.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {