@mulingai-npm/redis 1.4.0 → 1.6.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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RedisClient } from '../redis-client';
|
|
2
|
-
type AudioSttStatus = 'RECEIVED' | 'DISCARDED' | 'READY' | 'USED';
|
|
2
|
+
type AudioSttStatus = 'RECEIVED' | 'DISCARDED' | 'EMPTY' | 'READY' | 'USED';
|
|
3
3
|
export type AudioSttData = {
|
|
4
4
|
audioSttId: string;
|
|
5
5
|
roomId: string;
|
|
@@ -11,6 +11,7 @@ export type AudioSttData = {
|
|
|
11
11
|
isLast: boolean;
|
|
12
12
|
language: string;
|
|
13
13
|
theme: string;
|
|
14
|
+
services: string[];
|
|
14
15
|
azureTranscription?: string;
|
|
15
16
|
whisperTranscription?: string;
|
|
16
17
|
googleTranscription?: string;
|
|
@@ -27,5 +28,6 @@ export declare class AudioSttManager {
|
|
|
27
28
|
getAllAudioSttByRoom(roomId: string): Promise<AudioSttData[]>;
|
|
28
29
|
getAudioStt(audioSttId: string): Promise<AudioSttData | null>;
|
|
29
30
|
updateAudioSttStatus(audioSttId: string, status: AudioSttStatus): Promise<boolean>;
|
|
31
|
+
updateAudioSttAzureTranscription(audioSttId: string, azureTranscription: string, status: AudioSttStatus): Promise<boolean>;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -19,6 +19,7 @@ class AudioSttManager {
|
|
|
19
19
|
isLast: data.isLast === 'true',
|
|
20
20
|
language: data.language,
|
|
21
21
|
theme: data.theme,
|
|
22
|
+
services: data.services ? JSON.parse(data.services) : [],
|
|
22
23
|
azureTranscription: data.azureTranscription || undefined,
|
|
23
24
|
whisperTranscription: data.whisperTranscription || undefined,
|
|
24
25
|
googleTranscription: data.googleTranscription || undefined,
|
|
@@ -33,6 +34,7 @@ class AudioSttManager {
|
|
|
33
34
|
// - Optionally sets an expiration (4h).
|
|
34
35
|
async addAudioStt(sttData) {
|
|
35
36
|
const audioSttId = `[${sttData.roomId}]-[${(0, uuid_1.v4)()}]`;
|
|
37
|
+
const servicesJson = sttData.services ? JSON.stringify(sttData.services) : '[]';
|
|
36
38
|
// Add audioSttId to the set for that room
|
|
37
39
|
await this.redisClient.sadd(`room:${sttData.roomId}:audioStt`, audioSttId);
|
|
38
40
|
// Store audio-stt data in a hash
|
|
@@ -47,6 +49,7 @@ class AudioSttManager {
|
|
|
47
49
|
isLast: sttData.isLast.toString(),
|
|
48
50
|
language: sttData.language,
|
|
49
51
|
theme: sttData.theme,
|
|
52
|
+
services: servicesJson,
|
|
50
53
|
processingStart: Date.now().toString(),
|
|
51
54
|
totalStatusCheck: (0).toString(),
|
|
52
55
|
status: 'RECEIVED'
|
|
@@ -110,5 +113,19 @@ class AudioSttManager {
|
|
|
110
113
|
});
|
|
111
114
|
return true;
|
|
112
115
|
}
|
|
116
|
+
async updateAudioSttAzureTranscription(audioSttId, azureTranscription, status) {
|
|
117
|
+
// Attempt to fetch the data first
|
|
118
|
+
const data = await this.redisClient.hgetall(`audioStt:${audioSttId}`);
|
|
119
|
+
if (!data || !data.audioSttId) {
|
|
120
|
+
// AudioStt either doesn’t exist or has expired
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
// Update the azureTranscription and status fields
|
|
124
|
+
await this.redisClient.hset(`audioStt:${audioSttId}`, {
|
|
125
|
+
azureTranscription,
|
|
126
|
+
status
|
|
127
|
+
});
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
113
130
|
}
|
|
114
131
|
exports.AudioSttManager = AudioSttManager;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { RedisClient } from '../redis-client';
|
|
2
|
+
export type SttStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
|
|
3
|
+
export type TranslationStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
|
|
4
|
+
export type TtsStatus = 'INIT' | 'DISCARDED' | 'READY' | 'USED';
|
|
5
|
+
export type MulingstreamChunkStatus = 'INIT' | 'DISCARDED' | 'USED';
|
|
6
|
+
export type MulingstreamChunkData = {
|
|
7
|
+
mulingstreamChunkId: string;
|
|
8
|
+
roomId: string;
|
|
9
|
+
chunkNumber: number;
|
|
10
|
+
language: string;
|
|
11
|
+
mulingstreamChunkStatus: MulingstreamChunkStatus;
|
|
12
|
+
audioChunk: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
duration: number;
|
|
16
|
+
isFirst: boolean;
|
|
17
|
+
isLast: boolean;
|
|
18
|
+
theme: string;
|
|
19
|
+
processingStart: number;
|
|
20
|
+
};
|
|
21
|
+
stt: {
|
|
22
|
+
services: string[];
|
|
23
|
+
azureTranscription?: string;
|
|
24
|
+
whisperTranscription?: string;
|
|
25
|
+
googleTranscription?: string;
|
|
26
|
+
finalTranscription: string;
|
|
27
|
+
status: SttStatus;
|
|
28
|
+
};
|
|
29
|
+
postStt: {
|
|
30
|
+
[language: string]: {
|
|
31
|
+
translation: string;
|
|
32
|
+
translationStatus: TranslationStatus;
|
|
33
|
+
ttsAudioPath: string;
|
|
34
|
+
ttsStatus: TtsStatus;
|
|
35
|
+
isEmitted: boolean;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export declare class MulingstreamChunkManager {
|
|
40
|
+
private redisClient;
|
|
41
|
+
constructor(redisClient: RedisClient);
|
|
42
|
+
private parseHashData;
|
|
43
|
+
addMulingstreamChunk(params: {
|
|
44
|
+
roomId: string;
|
|
45
|
+
chunkNumber: number;
|
|
46
|
+
language: string;
|
|
47
|
+
start: number;
|
|
48
|
+
end: number;
|
|
49
|
+
duration: number;
|
|
50
|
+
isFirst: boolean;
|
|
51
|
+
isLast: boolean;
|
|
52
|
+
theme: string;
|
|
53
|
+
services: string[];
|
|
54
|
+
postSttLanguages: string[];
|
|
55
|
+
}): Promise<string>;
|
|
56
|
+
getMulingstreamChunks(): Promise<MulingstreamChunkData[]>;
|
|
57
|
+
getMulingstreamChunk(mulingstreamChunkId: string): Promise<MulingstreamChunkData | null>;
|
|
58
|
+
getMulingstreamChunksByRoom(roomId: string): Promise<MulingstreamChunkData[]>;
|
|
59
|
+
getByChunkNumber(chunkNumber: number, roomId: string): Promise<MulingstreamChunkData | null>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MulingstreamChunkManager = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
const EXPIRATION = 4 * 60 * 60; // 4 hours in seconds
|
|
6
|
+
class MulingstreamChunkManager {
|
|
7
|
+
constructor(redisClient) {
|
|
8
|
+
this.redisClient = redisClient;
|
|
9
|
+
}
|
|
10
|
+
parseHashData(data) {
|
|
11
|
+
// Parse nested JSON fields
|
|
12
|
+
const audioChunk = JSON.parse(data.audioChunk);
|
|
13
|
+
const stt = JSON.parse(data.stt);
|
|
14
|
+
const postStt = JSON.parse(data.postStt);
|
|
15
|
+
return {
|
|
16
|
+
mulingstreamChunkId: data.mulingstreamChunkId,
|
|
17
|
+
roomId: data.roomId,
|
|
18
|
+
chunkNumber: parseInt(data.chunkNumber, 10),
|
|
19
|
+
language: data.language,
|
|
20
|
+
mulingstreamChunkStatus: data.mulingstreamChunkStatus,
|
|
21
|
+
audioChunk,
|
|
22
|
+
stt,
|
|
23
|
+
postStt
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
// Adds a new mulingstream chunk.
|
|
27
|
+
// - Creates a unique mulingstreamChunkId.
|
|
28
|
+
// - Stores the chunk data in a Redis hash under `mulingstreamChunk:{mulingstreamChunkId}`.
|
|
29
|
+
// - Applies an expiration (4h).
|
|
30
|
+
async addMulingstreamChunk(params) {
|
|
31
|
+
const { roomId, chunkNumber, language, start, end, duration, isFirst, isLast, theme, services, postSttLanguages } = params;
|
|
32
|
+
const mulingstreamChunkId = `[${roomId}]-[${chunkNumber}]-[${(0, uuid_1.v4)()}]`;
|
|
33
|
+
// Prepare the nested objects
|
|
34
|
+
const audioChunk = {
|
|
35
|
+
start,
|
|
36
|
+
end,
|
|
37
|
+
duration,
|
|
38
|
+
isFirst,
|
|
39
|
+
isLast,
|
|
40
|
+
theme,
|
|
41
|
+
processingStart: Date.now()
|
|
42
|
+
};
|
|
43
|
+
const stt = {
|
|
44
|
+
services,
|
|
45
|
+
azureTranscription: '',
|
|
46
|
+
whisperTranscription: '',
|
|
47
|
+
googleTranscription: '',
|
|
48
|
+
finalTranscription: '',
|
|
49
|
+
status: 'INIT'
|
|
50
|
+
};
|
|
51
|
+
// Build postStt object keyed by each language
|
|
52
|
+
const postStt = {};
|
|
53
|
+
for (const lang of postSttLanguages) {
|
|
54
|
+
postStt[lang] = {
|
|
55
|
+
translation: '',
|
|
56
|
+
translationStatus: 'INIT',
|
|
57
|
+
ttsAudioPath: '',
|
|
58
|
+
ttsStatus: 'INIT',
|
|
59
|
+
isEmitted: false
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// Store the data in a Redis hash
|
|
63
|
+
await this.redisClient.hset(`mulingstreamChunk:${mulingstreamChunkId}`, {
|
|
64
|
+
mulingstreamChunkId,
|
|
65
|
+
roomId,
|
|
66
|
+
chunkNumber: chunkNumber.toString(),
|
|
67
|
+
language,
|
|
68
|
+
mulingstreamChunkStatus: 'INIT',
|
|
69
|
+
audioChunk: JSON.stringify(audioChunk),
|
|
70
|
+
stt: JSON.stringify(stt),
|
|
71
|
+
postStt: JSON.stringify(postStt)
|
|
72
|
+
});
|
|
73
|
+
// set expiration
|
|
74
|
+
await this.redisClient.expire(`mulingstreamChunk:${mulingstreamChunkId}`, EXPIRATION);
|
|
75
|
+
return mulingstreamChunkId;
|
|
76
|
+
}
|
|
77
|
+
// Retrieves all mulingstream chunks by scanning keys `mulingstreamChunk:*`.
|
|
78
|
+
async getMulingstreamChunks() {
|
|
79
|
+
const keys = await this.redisClient.keys('mulingstreamChunk:*');
|
|
80
|
+
if (!keys || keys.length === 0) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
const results = [];
|
|
84
|
+
for (const key of keys) {
|
|
85
|
+
const data = await this.redisClient.hgetall(key);
|
|
86
|
+
if (data && data.mulingstreamChunkId) {
|
|
87
|
+
results.push(this.parseHashData(data));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return results;
|
|
91
|
+
}
|
|
92
|
+
// Retrieves a single mulingstream chunk by ID.
|
|
93
|
+
async getMulingstreamChunk(mulingstreamChunkId) {
|
|
94
|
+
const data = await this.redisClient.hgetall(`mulingstreamChunk:${mulingstreamChunkId}`);
|
|
95
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return this.parseHashData(data);
|
|
99
|
+
}
|
|
100
|
+
// Retrieves all mulingstream chunks for a specific room by pattern matching keys `mulingstreamChunk:[roomId]-*`.
|
|
101
|
+
async getMulingstreamChunksByRoom(roomId) {
|
|
102
|
+
const pattern = `mulingstreamChunk:[${roomId}]-*`;
|
|
103
|
+
const keys = await this.redisClient.keys(pattern);
|
|
104
|
+
if (!keys || keys.length === 0) {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
const results = [];
|
|
108
|
+
for (const key of keys) {
|
|
109
|
+
const data = await this.redisClient.hgetall(key);
|
|
110
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
results.push(this.parseHashData(data));
|
|
114
|
+
}
|
|
115
|
+
return results;
|
|
116
|
+
}
|
|
117
|
+
// Retrieves a mulingstream chunk by (roomId, chunkNumber).
|
|
118
|
+
// Since mulingstreamChunkId = `[${roomId}]-[${chunkNumber}]-[uuid]`, we can pattern-match on keys.
|
|
119
|
+
async getByChunkNumber(chunkNumber, roomId) {
|
|
120
|
+
const pattern = `mulingstreamChunk:[${roomId}]-[${chunkNumber}]-*`;
|
|
121
|
+
const keys = await this.redisClient.keys(pattern);
|
|
122
|
+
if (!keys || keys.length === 0) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
// If multiple match, return the first
|
|
126
|
+
const data = await this.redisClient.hgetall(keys[0]);
|
|
127
|
+
if (!data || !data.mulingstreamChunkId) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
return this.parseHashData(data);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.MulingstreamChunkManager = MulingstreamChunkManager;
|