-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.ts
More file actions
273 lines (234 loc) · 7.63 KB
/
types.ts
File metadata and controls
273 lines (234 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/**
* FluidAudio React Native Types
*/
// ============================================================================
// System Info
// ============================================================================
export interface SystemInfo {
isAppleSilicon: boolean;
platform: 'ios';
summary: string;
}
// ============================================================================
// ASR (Automatic Speech Recognition)
// ============================================================================
export interface ASRConfig {
/** Sample rate in Hz (default: 16000) */
sampleRate?: number;
/** Enable streaming for long audio (default: true) */
streamingEnabled?: boolean;
/** Streaming threshold in samples (default: 480000 ~30s) */
streamingThreshold?: number;
}
export interface TokenTiming {
token: string;
tokenId: number;
startTime: number;
endTime: number;
confidence: number;
}
export interface ASRPerformanceMetrics {
preprocessDuration: number;
encoderDuration: number;
decoderDuration: number;
}
export interface ASRResult {
/** Transcribed text */
text: string;
/** Overall confidence score (0-1) */
confidence: number;
/** Audio duration in seconds */
duration: number;
/** Processing time in seconds */
processingTime: number;
/** Real-time factor (duration / processingTime) */
rtfx: number;
/** Per-token timing information */
tokenTimings?: TokenTiming[];
/** Detailed performance metrics */
performanceMetrics?: ASRPerformanceMetrics;
}
export interface ASRInitResult {
success: boolean;
compilationDuration: number;
}
// ============================================================================
// Streaming ASR
// ============================================================================
export interface StreamingASRConfig {
/** Audio source: 'microphone' or 'system' (macOS only) */
source?: 'microphone' | 'system';
/** Chunk duration in seconds */
chunkDuration?: number;
}
export interface StreamingUpdate {
/** Current volatile (unconfirmed) transcript */
volatile: string;
/** Confirmed transcript */
confirmed: string;
/** Whether this is the final update */
isFinal: boolean;
}
export interface StreamingStopResult {
text: string;
success: boolean;
}
// ============================================================================
// VAD (Voice Activity Detection)
// ============================================================================
export interface VADConfig {
/** Voice activity threshold (0-1, default: 0.85) */
threshold?: number;
/** Enable debug mode */
debugMode?: boolean;
}
export interface VADChunkResult {
/** Chunk index in the audio */
chunkIndex: number;
/** Voice activity probability (0-1) */
probability: number;
/** Whether voice activity is detected */
isActive: boolean;
/** Processing time for this chunk */
processingTime: number;
}
export interface VADResult {
/** Per-chunk VAD results */
results: VADChunkResult[];
/** Chunk size in samples */
chunkSize: number;
/** Sample rate used */
sampleRate: number;
}
// ============================================================================
// Diarization (Speaker Identification)
// ============================================================================
export interface DiarizationConfig {
/** Clustering threshold (0.5-0.9, default: 0.7) */
clusteringThreshold?: number;
/** Minimum speech duration in seconds (default: 1.0) */
minSpeechDuration?: number;
/** Minimum silence gap in seconds (default: 0.5) */
minSilenceGap?: number;
/** Number of speakers (-1 for automatic, default: -1) */
numClusters?: number;
/** Enable debug mode */
debugMode?: boolean;
}
export interface SpeakerSegment {
/** Unique segment ID */
id: string;
/** Speaker identifier */
speakerId: string;
/** Start time in seconds */
startTime: number;
/** End time in seconds */
endTime: number;
/** Segment duration in seconds */
duration: number;
/** Quality score for this segment */
qualityScore: number;
/** 256-dimensional speaker embedding */
embedding: number[];
}
export interface DiarizationTimings {
total: number;
segmentation: number;
embedding: number;
clustering: number;
}
export interface DiarizationResult {
/** Speaker segments with timing and identity */
segments: SpeakerSegment[];
/** Speaker embeddings database */
speakerDatabase?: Record<string, number[]>;
/** Processing timings */
timings?: DiarizationTimings;
}
export interface DiarizationInitResult {
success: boolean;
compilationDuration: number;
}
export interface KnownSpeaker {
/** Unique speaker ID */
id: string;
/** Speaker display name */
name: string;
/** 256-dimensional speaker embedding */
embedding: number[];
}
// ============================================================================
// TTS (Text-to-Speech)
// ============================================================================
export interface TTSConfig {
/** Enable debug mode */
debugMode?: boolean;
/** Model variant: 'fiveSecond' or 'fifteenSecond' */
variant?: 'fiveSecond' | 'fifteenSecond';
}
export interface TTSResult {
/** Base64-encoded audio data */
audioData: string;
/** Audio duration in seconds */
duration: number;
/** Sample rate */
sampleRate: number;
}
// ============================================================================
// Events
// ============================================================================
export interface ModelLoadProgressEvent {
type?: 'asr' | 'diarization' | 'vad' | 'tts';
status: 'downloading' | 'compiling' | 'ready';
progress: number;
}
export interface TranscriptionErrorEvent {
code: string;
message: string;
}
export interface TTSSynthesizeFileResult {
success: boolean;
outputPath: string;
}
// ============================================================================
// Native Module Interface
// ============================================================================
export interface FluidAudioNativeModule {
// System
getSystemInfo(): Promise<SystemInfo>;
// ASR
initializeAsr(config?: ASRConfig): Promise<ASRInitResult>;
transcribeFile(filePath: string): Promise<ASRResult>;
transcribeAudioData(base64Audio: string, sampleRate: number): Promise<ASRResult>;
isAsrAvailable(): Promise<boolean>;
// Streaming ASR
startStreamingAsr(config?: StreamingASRConfig): Promise<{ success: boolean }>;
feedStreamingAudio(base64Audio: string): Promise<{ success: boolean }>;
stopStreamingAsr(): Promise<StreamingStopResult>;
// VAD
initializeVad(config?: VADConfig): Promise<{ success: boolean }>;
processVad(filePath: string): Promise<VADResult>;
processVadAudioData(base64Audio: string): Promise<VADResult>;
isVadAvailable(): Promise<boolean>;
// Diarization
initializeDiarization(config?: DiarizationConfig): Promise<DiarizationInitResult>;
performDiarization(filePath: string, sampleRate: number): Promise<DiarizationResult>;
performDiarizationOnAudioData(
base64Audio: string,
sampleRate: number
): Promise<DiarizationResult>;
initializeKnownSpeakers(
speakers: KnownSpeaker[]
): Promise<{ success: boolean; speakerCount: number }>;
isDiarizationAvailable(): Promise<boolean>;
// TTS
initializeTts(config?: TTSConfig): Promise<{ success: boolean }>;
synthesize(text: string, voice?: string): Promise<TTSResult>;
synthesizeToFile(text: string, voice: string | null, outputPath: string): Promise<TTSSynthesizeFileResult>;
isTtsAvailable(): Promise<boolean>;
// Cleanup
cleanup(): Promise<{ success: boolean }>;
// Event emitter methods
addListener(eventType: string): void;
removeListeners(count: number): void;
}