@mulingai-npm/redis 1.7.0 → 1.8.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.
@@ -3,12 +3,14 @@ export type SttStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
3
3
  export type TranslationStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
4
4
  export type TtsStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
5
5
  export type MulingstreamChunkStatus = 'INIT' | 'DISCARDED' | 'USED';
6
+ export type MulingstreamChunkStep = 'RECEIVED' | 'STT' | 'TRANSLATION' | 'TTS' | 'EMITTED' | 'COMPLETED' | 'CANCELED';
6
7
  export type MulingstreamChunkData = {
7
8
  mulingstreamChunkId: string;
8
9
  roomId: string;
9
10
  chunkNumber: number;
10
11
  language: string;
11
12
  mulingstreamChunkStatus: MulingstreamChunkStatus;
13
+ mulingstreamChunkStep: MulingstreamChunkStep;
12
14
  audioChunk: {
13
15
  start: number;
14
16
  end: number;
@@ -57,4 +59,6 @@ export declare class MulingstreamChunkManager {
57
59
  getMulingstreamChunk(mulingstreamChunkId: string): Promise<MulingstreamChunkData | null>;
58
60
  getMulingstreamChunksByRoom(roomId: string): Promise<MulingstreamChunkData[]>;
59
61
  getByChunkNumber(chunkNumber: number, roomId: string): Promise<MulingstreamChunkData | null>;
62
+ updateSttStatus(mulingstreamChunkId: string, status: SttStatus, chunkStatus: MulingstreamChunkStatus, chunkStep: MulingstreamChunkStep): Promise<boolean>;
63
+ updateAzureTranscription(mulingstreamChunkId: string, transcription: string, sttStatus: SttStatus, chunkStatus: MulingstreamChunkStatus, chunkStep: MulingstreamChunkStep): Promise<boolean>;
60
64
  }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MulingstreamChunkManager = void 0;
4
4
  const uuid_1 = require("uuid");
5
- const EXPIRATION = 4 * 60 * 60; // 4 hours in seconds
5
+ const EXPIRATION = 12 * 60 * 60; // 12 hours in seconds
6
6
  class MulingstreamChunkManager {
7
7
  constructor(redisClient) {
8
8
  this.redisClient = redisClient;
@@ -18,6 +18,7 @@ class MulingstreamChunkManager {
18
18
  chunkNumber: parseInt(data.chunkNumber, 10),
19
19
  language: data.language,
20
20
  mulingstreamChunkStatus: data.mulingstreamChunkStatus,
21
+ mulingstreamChunkStep: data.mulingstreamChunkStep,
21
22
  audioChunk,
22
23
  stt,
23
24
  postStt
@@ -26,7 +27,7 @@ class MulingstreamChunkManager {
26
27
  // Adds a new mulingstream chunk.
27
28
  // - Creates a unique mulingstreamChunkId.
28
29
  // - Stores the chunk data in a Redis hash under `mulingstreamChunk:{mulingstreamChunkId}`.
29
- // - Applies an expiration (4h).
30
+ // - Applies an expiration (12h).
30
31
  async addMulingstreamChunk(params) {
31
32
  const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, services, postSttLanguages } = params;
32
33
  const mulingstreamChunkId = `[${roomId}]-[${chunkNumber}]-[${(0, uuid_1.v4)()}]`;
@@ -66,6 +67,7 @@ class MulingstreamChunkManager {
66
67
  chunkNumber: chunkNumber.toString(),
67
68
  language,
68
69
  mulingstreamChunkStatus: 'INIT',
70
+ mulingstreamChunkStep: 'RECEIVED',
69
71
  audioChunk: JSON.stringify(audioChunk),
70
72
  stt: JSON.stringify(stt),
71
73
  postStt: JSON.stringify(postStt)
@@ -129,5 +131,42 @@ class MulingstreamChunkManager {
129
131
  }
130
132
  return this.parseHashData(data);
131
133
  }
134
+ async updateSttStatus(mulingstreamChunkId, status, chunkStatus, chunkStep) {
135
+ // Fetch the chunk data first
136
+ const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
137
+ if (!data || !data.mulingstreamChunkId) {
138
+ return false; // The chunk may not exist or has expired
139
+ }
140
+ // Parse the existing stt field
141
+ const stt = JSON.parse(data.stt);
142
+ // Update the status
143
+ stt.status = status;
144
+ // Write back the updated stt object
145
+ await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
146
+ mulingstreamChunkStatus: chunkStatus,
147
+ mulingstreamChunkStep: chunkStep,
148
+ stt: JSON.stringify(stt)
149
+ });
150
+ return true;
151
+ }
152
+ async updateAzureTranscription(mulingstreamChunkId, transcription, sttStatus, chunkStatus, chunkStep) {
153
+ // Fetch the chunk data first
154
+ const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
155
+ if (!data || !data.mulingstreamChunkId) {
156
+ return false; // The chunk may not exist or has expired
157
+ }
158
+ // Parse the existing stt field
159
+ const stt = JSON.parse(data.stt);
160
+ // Update fields
161
+ stt.azureTranscription = transcription;
162
+ stt.status = sttStatus;
163
+ // Write back the updated stt object
164
+ await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
165
+ mulingstreamChunkStatus: chunkStatus,
166
+ mulingstreamChunkStep: chunkStep,
167
+ stt: JSON.stringify(stt)
168
+ });
169
+ return true;
170
+ }
132
171
  }
133
172
  exports.MulingstreamChunkManager = MulingstreamChunkManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mulingai-npm/redis",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {