fi-glass 1.1.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.
- package/LICENSE +77 -0
- package/README.md +162 -0
- package/dist/agent/index.d.ts +399 -0
- package/dist/agent/index.js +1979 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/composer/index.d.ts +57 -0
- package/dist/composer/index.js +112 -0
- package/dist/composer/index.js.map +1 -0
- package/dist/conversation/index.d.ts +80 -0
- package/dist/conversation/index.js +207 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/glass-theme-D-leVuKb.d.ts +19 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +4316 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/index.d.ts +213 -0
- package/dist/messages/index.js +337 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/persona-selector/index.d.ts +54 -0
- package/dist/persona-selector/index.js +215 -0
- package/dist/persona-selector/index.js.map +1 -0
- package/dist/shell/index.d.ts +429 -0
- package/dist/shell/index.js +1566 -0
- package/dist/shell/index.js.map +1 -0
- package/dist/theme/index.d.ts +58 -0
- package/dist/theme/index.js +38 -0
- package/dist/theme/index.js.map +1 -0
- package/dist/voice/index.d.ts +790 -0
- package/dist/voice/index.js +2591 -0
- package/dist/voice/index.js.map +1 -0
- package/package.json +85 -0
- package/src/theme/glass-chat-preset.ts +74 -0
- package/src/theme/glass-chat.css +217 -0
- package/src/theme/glass-theme.ts +26 -0
- package/src/theme/glass.css +27 -0
- package/src/theme/index.css +3 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/tokens.css +13 -0
|
@@ -0,0 +1,2591 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/voice/recording/RecordingButton.tsx
|
|
4
|
+
import { forwardRef } from "react";
|
|
5
|
+
import { Loader2 } from "lucide-react";
|
|
6
|
+
|
|
7
|
+
// src/voice/recording/types.ts
|
|
8
|
+
var BUTTON_SIZES = {
|
|
9
|
+
sm: {
|
|
10
|
+
button: "rec-btn-sm",
|
|
11
|
+
icon: "rec-icon-sm",
|
|
12
|
+
ring: "rec-ring-sm"
|
|
13
|
+
},
|
|
14
|
+
md: {
|
|
15
|
+
button: "rec-btn-md",
|
|
16
|
+
icon: "rec-icon-md",
|
|
17
|
+
ring: "rec-ring-md"
|
|
18
|
+
},
|
|
19
|
+
lg: {
|
|
20
|
+
button: "rec-btn-lg",
|
|
21
|
+
icon: "rec-icon-lg",
|
|
22
|
+
ring: "rec-ring-lg"
|
|
23
|
+
},
|
|
24
|
+
xl: {
|
|
25
|
+
button: "rec-btn-xl",
|
|
26
|
+
icon: "rec-icon-xl",
|
|
27
|
+
ring: "rec-ring-xl"
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
var COLOR_THEMES = {
|
|
31
|
+
medical: {
|
|
32
|
+
idle: "rec-theme-medical-idle",
|
|
33
|
+
starting: "rec-theme-medical-starting",
|
|
34
|
+
recording: "rec-theme-medical-recording",
|
|
35
|
+
pausing: "rec-theme-medical-pausing",
|
|
36
|
+
paused: "rec-theme-medical-paused",
|
|
37
|
+
resuming: "rec-theme-medical-resuming",
|
|
38
|
+
processing: "rec-theme-medical-processing",
|
|
39
|
+
stopping: "rec-theme-medical-stopping",
|
|
40
|
+
finalized: "rec-theme-medical-finalized"
|
|
41
|
+
},
|
|
42
|
+
chat: {
|
|
43
|
+
idle: "rec-theme-chat-idle",
|
|
44
|
+
starting: "rec-theme-chat-starting",
|
|
45
|
+
recording: "rec-theme-chat-recording",
|
|
46
|
+
pausing: "rec-theme-chat-pausing",
|
|
47
|
+
paused: "rec-theme-chat-paused",
|
|
48
|
+
resuming: "rec-theme-chat-resuming",
|
|
49
|
+
processing: "rec-theme-chat-processing",
|
|
50
|
+
stopping: "rec-theme-chat-stopping",
|
|
51
|
+
finalized: "rec-theme-chat-finalized"
|
|
52
|
+
},
|
|
53
|
+
minimal: {
|
|
54
|
+
idle: "rec-theme-minimal-idle",
|
|
55
|
+
starting: "rec-theme-minimal-starting",
|
|
56
|
+
recording: "rec-theme-minimal-recording",
|
|
57
|
+
pausing: "rec-theme-minimal-pausing",
|
|
58
|
+
paused: "rec-theme-minimal-paused",
|
|
59
|
+
resuming: "rec-theme-minimal-resuming",
|
|
60
|
+
processing: "rec-theme-minimal-processing",
|
|
61
|
+
stopping: "rec-theme-minimal-stopping",
|
|
62
|
+
finalized: "rec-theme-minimal-finalized"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
var STATUS_TEXT_ES = {
|
|
66
|
+
idle: "Presiona para comenzar",
|
|
67
|
+
starting: "Iniciando...",
|
|
68
|
+
recording: "Grabando...",
|
|
69
|
+
pausing: "Pausando...",
|
|
70
|
+
paused: "Pausado",
|
|
71
|
+
resuming: "Reanudando...",
|
|
72
|
+
processing: "Procesando...",
|
|
73
|
+
stopping: "Finalizando...",
|
|
74
|
+
finalized: "Completado"
|
|
75
|
+
};
|
|
76
|
+
var STATUS_TEXT_EN = {
|
|
77
|
+
idle: "Press to start",
|
|
78
|
+
starting: "Starting...",
|
|
79
|
+
recording: "Recording...",
|
|
80
|
+
pausing: "Pausing...",
|
|
81
|
+
paused: "Paused",
|
|
82
|
+
resuming: "Resuming...",
|
|
83
|
+
processing: "Processing...",
|
|
84
|
+
stopping: "Stopping...",
|
|
85
|
+
finalized: "Complete"
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// src/voice/recording/RecordingButton.tsx
|
|
89
|
+
import { jsx } from "react/jsx-runtime";
|
|
90
|
+
var RecordingButton = forwardRef(
|
|
91
|
+
function RecordingButton2({
|
|
92
|
+
size = "md",
|
|
93
|
+
bgColor,
|
|
94
|
+
icon: Icon,
|
|
95
|
+
iconSpin = false,
|
|
96
|
+
iconColor = "rec-icon-white",
|
|
97
|
+
disabled = false,
|
|
98
|
+
onClick,
|
|
99
|
+
ariaLabel,
|
|
100
|
+
className = "",
|
|
101
|
+
borderStyle = "",
|
|
102
|
+
animate = ""
|
|
103
|
+
}, ref) {
|
|
104
|
+
const sizeConfig = BUTTON_SIZES[size];
|
|
105
|
+
const DisplayIcon = iconSpin ? Loader2 : Icon;
|
|
106
|
+
return /* @__PURE__ */ jsx(
|
|
107
|
+
"button",
|
|
108
|
+
{
|
|
109
|
+
ref,
|
|
110
|
+
onClick,
|
|
111
|
+
disabled,
|
|
112
|
+
"aria-label": ariaLabel,
|
|
113
|
+
className: `fi-recording-btn-base ${sizeConfig.button} ${bgColor} ${borderStyle} ${animate} ${disabled ? "rec-btn-disabled" : "rec-btn-enabled"} ${className}`,
|
|
114
|
+
children: /* @__PURE__ */ jsx(
|
|
115
|
+
DisplayIcon,
|
|
116
|
+
{
|
|
117
|
+
className: `${sizeConfig.icon} ${iconColor} ${iconSpin ? "rec-icon-spin" : ""}`
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
// src/voice/recording/PulseRings.tsx
|
|
126
|
+
import { motion } from "framer-motion";
|
|
127
|
+
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
128
|
+
function PingRings({ color = "yellow-500" }) {
|
|
129
|
+
const bgClass = `rec-pulse-bg-${color}`;
|
|
130
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
131
|
+
/* @__PURE__ */ jsx2(
|
|
132
|
+
"div",
|
|
133
|
+
{
|
|
134
|
+
className: `rec-pulse-ping-primary ${bgClass}`
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
/* @__PURE__ */ jsx2(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
className: `rec-pulse-ping-secondary ${bgClass}`,
|
|
141
|
+
style: { animation: "pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite" }
|
|
142
|
+
}
|
|
143
|
+
)
|
|
144
|
+
] });
|
|
145
|
+
}
|
|
146
|
+
function ConcentricRings({ color = "yellow-500" }) {
|
|
147
|
+
const borderClass = `rec-pulse-border-${color}`;
|
|
148
|
+
const rings = [
|
|
149
|
+
{ scale: 1.3, opacity: 0.4, delay: 0 },
|
|
150
|
+
{ scale: 1.5, opacity: 0.3, delay: 0.2 },
|
|
151
|
+
{ scale: 1.7, opacity: 0.2, delay: 0.4 }
|
|
152
|
+
];
|
|
153
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: rings.map((ring, i) => /* @__PURE__ */ jsx2(
|
|
154
|
+
motion.div,
|
|
155
|
+
{
|
|
156
|
+
className: `rec-pulse-concentric ${borderClass}`,
|
|
157
|
+
initial: { scale: 1, opacity: ring.opacity },
|
|
158
|
+
animate: {
|
|
159
|
+
scale: [1, ring.scale, 1],
|
|
160
|
+
opacity: [ring.opacity, ring.opacity * 0.5, ring.opacity]
|
|
161
|
+
},
|
|
162
|
+
transition: {
|
|
163
|
+
duration: 1.5,
|
|
164
|
+
repeat: Infinity,
|
|
165
|
+
ease: "easeInOut",
|
|
166
|
+
delay: ring.delay
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
i
|
|
170
|
+
)) });
|
|
171
|
+
}
|
|
172
|
+
function VADRings({
|
|
173
|
+
audioLevel = 0,
|
|
174
|
+
isSilent = true
|
|
175
|
+
}) {
|
|
176
|
+
const audioScale = !isSilent ? Math.max(1, 1 + audioLevel / 255 * 1) : 1;
|
|
177
|
+
const ringColor = isSilent ? "rgb(239, 68, 68)" : "rgb(34, 197, 94)";
|
|
178
|
+
const rings = [
|
|
179
|
+
{ baseScale: 1.2, opacityBase: 0.6 },
|
|
180
|
+
{ baseScale: 1.4, opacityBase: 0.4 },
|
|
181
|
+
{ baseScale: 1.6, opacityBase: 0.2 }
|
|
182
|
+
];
|
|
183
|
+
return /* @__PURE__ */ jsx2(Fragment, { children: rings.map((ring, i) => /* @__PURE__ */ jsx2(
|
|
184
|
+
motion.div,
|
|
185
|
+
{
|
|
186
|
+
className: "rec-pulse-vad",
|
|
187
|
+
style: { borderColor: ringColor },
|
|
188
|
+
animate: {
|
|
189
|
+
scale: audioScale * ring.baseScale,
|
|
190
|
+
opacity: ring.opacityBase
|
|
191
|
+
},
|
|
192
|
+
transition: {
|
|
193
|
+
duration: 0.2,
|
|
194
|
+
// Transición suave pero rápida para seguir el ritmo
|
|
195
|
+
ease: "easeOut"
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
i
|
|
199
|
+
)) });
|
|
200
|
+
}
|
|
201
|
+
function PulseRings({
|
|
202
|
+
style,
|
|
203
|
+
color = "yellow-500",
|
|
204
|
+
audioLevel = 0,
|
|
205
|
+
isSilent = true,
|
|
206
|
+
className = ""
|
|
207
|
+
}) {
|
|
208
|
+
if (style === "none") return null;
|
|
209
|
+
return /* @__PURE__ */ jsxs("div", { className: `rec-pulse-container ${className}`, children: [
|
|
210
|
+
style === "ping" && /* @__PURE__ */ jsx2(PingRings, { color }),
|
|
211
|
+
style === "rings" && /* @__PURE__ */ jsx2(ConcentricRings, { color }),
|
|
212
|
+
style === "vad" && /* @__PURE__ */ jsx2(VADRings, { audioLevel, isSilent })
|
|
213
|
+
] });
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/voice/recording/RecordingTimer.tsx
|
|
217
|
+
import { motion as motion2 } from "framer-motion";
|
|
218
|
+
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
219
|
+
function formatRecordingTime(seconds) {
|
|
220
|
+
const mins = Math.floor(seconds / 60);
|
|
221
|
+
const secs = seconds % 60;
|
|
222
|
+
return `${mins}:${secs.toString().padStart(2, "0")}`;
|
|
223
|
+
}
|
|
224
|
+
var SIZE_CLASSES = {
|
|
225
|
+
sm: "rec-timer-sm",
|
|
226
|
+
md: "rec-timer-md",
|
|
227
|
+
lg: "rec-timer-lg"
|
|
228
|
+
};
|
|
229
|
+
function RecordingTimer({
|
|
230
|
+
time,
|
|
231
|
+
visible = true,
|
|
232
|
+
size = "md",
|
|
233
|
+
showDot = false,
|
|
234
|
+
textColor = "rec-timer-text-white",
|
|
235
|
+
dotColor = "rec-timer-dot-red",
|
|
236
|
+
className = ""
|
|
237
|
+
}) {
|
|
238
|
+
if (!visible || time <= 0) return null;
|
|
239
|
+
return /* @__PURE__ */ jsxs2("div", { className: `rec-timer-wrap ${SIZE_CLASSES[size]} ${className}`, children: [
|
|
240
|
+
showDot && /* @__PURE__ */ jsx3(
|
|
241
|
+
motion2.div,
|
|
242
|
+
{
|
|
243
|
+
className: `rec-timer-dot ${dotColor}`,
|
|
244
|
+
animate: { opacity: [1, 0.3, 1] },
|
|
245
|
+
transition: {
|
|
246
|
+
duration: 1.5,
|
|
247
|
+
repeat: Infinity,
|
|
248
|
+
ease: "easeInOut"
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
),
|
|
252
|
+
/* @__PURE__ */ jsx3("span", { className: `${textColor} rec-timer-value`, children: formatRecordingTime(time) })
|
|
253
|
+
] });
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/voice/recording/StatusText.tsx
|
|
257
|
+
import { Loader2 as Loader22 } from "lucide-react";
|
|
258
|
+
import { motion as motion3 } from "framer-motion";
|
|
259
|
+
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
260
|
+
function StatusText({
|
|
261
|
+
text,
|
|
262
|
+
color = "rec-status-color-default",
|
|
263
|
+
showLoader = false,
|
|
264
|
+
animate = false,
|
|
265
|
+
className = ""
|
|
266
|
+
}) {
|
|
267
|
+
const content = /* @__PURE__ */ jsxs3("div", { className: `rec-status-wrap ${color} ${className}`, children: [
|
|
268
|
+
showLoader && /* @__PURE__ */ jsx4(Loader22, { className: "rec-status-loader" }),
|
|
269
|
+
/* @__PURE__ */ jsx4("p", { className: "rec-status-text", children: text })
|
|
270
|
+
] });
|
|
271
|
+
if (animate) {
|
|
272
|
+
return /* @__PURE__ */ jsx4(
|
|
273
|
+
motion3.div,
|
|
274
|
+
{
|
|
275
|
+
initial: { opacity: 0.7 },
|
|
276
|
+
animate: { opacity: [0.7, 1, 0.7] },
|
|
277
|
+
transition: { duration: 1.5, repeat: Infinity, ease: "easeInOut" },
|
|
278
|
+
children: content
|
|
279
|
+
}
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
return content;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/voice/VoiceMicButton.tsx
|
|
286
|
+
import { Mic, Square, Loader2 as Loader23 } from "lucide-react";
|
|
287
|
+
import { motion as motion4 } from "framer-motion";
|
|
288
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
289
|
+
function deriveState(isRecording, isTranscribing) {
|
|
290
|
+
if (isTranscribing && !isRecording) return "processing";
|
|
291
|
+
if (isRecording) return "recording";
|
|
292
|
+
return "idle";
|
|
293
|
+
}
|
|
294
|
+
function getButtonColor(state, isSilent) {
|
|
295
|
+
if (state === "recording") {
|
|
296
|
+
return isSilent ? "bg-red-500 hover:bg-red-600 text-white" : "bg-green-500 hover:bg-green-600 text-white";
|
|
297
|
+
}
|
|
298
|
+
if (state === "processing") {
|
|
299
|
+
return "bg-blue-500 text-white";
|
|
300
|
+
}
|
|
301
|
+
return "bg-gray-200 hover:bg-gray-300 text-gray-700 dark:bg-gray-700 dark:hover:bg-gray-600 dark:text-gray-200";
|
|
302
|
+
}
|
|
303
|
+
function VoiceMicButton({
|
|
304
|
+
isRecording,
|
|
305
|
+
isTranscribing,
|
|
306
|
+
audioLevel,
|
|
307
|
+
isSilent,
|
|
308
|
+
recordingTime,
|
|
309
|
+
onStart,
|
|
310
|
+
onStop,
|
|
311
|
+
className = ""
|
|
312
|
+
}) {
|
|
313
|
+
const state = deriveState(isRecording, isTranscribing);
|
|
314
|
+
const isDisabled = isTranscribing && !isRecording;
|
|
315
|
+
const handleClick = () => {
|
|
316
|
+
if (isRecording) {
|
|
317
|
+
onStop();
|
|
318
|
+
} else if (!isTranscribing) {
|
|
319
|
+
onStart();
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
const icon = isTranscribing ? Loader23 : isRecording ? Square : Mic;
|
|
323
|
+
const iconColor = state === "idle" ? "text-gray-700 dark:text-gray-200" : "text-white";
|
|
324
|
+
return /* @__PURE__ */ jsxs4("div", { className: `relative inline-flex items-center gap-3 ${className}`, children: [
|
|
325
|
+
/* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
326
|
+
isRecording && /* @__PURE__ */ jsx5(
|
|
327
|
+
PulseRings,
|
|
328
|
+
{
|
|
329
|
+
style: "vad",
|
|
330
|
+
audioLevel,
|
|
331
|
+
isSilent
|
|
332
|
+
}
|
|
333
|
+
),
|
|
334
|
+
/* @__PURE__ */ jsx5(
|
|
335
|
+
motion4.div,
|
|
336
|
+
{
|
|
337
|
+
animate: {
|
|
338
|
+
scale: isRecording && !isSilent ? [1, 1.05, 1] : 1
|
|
339
|
+
},
|
|
340
|
+
transition: {
|
|
341
|
+
duration: 0.6,
|
|
342
|
+
repeat: isRecording && !isSilent ? Infinity : 0,
|
|
343
|
+
ease: "easeInOut"
|
|
344
|
+
},
|
|
345
|
+
children: /* @__PURE__ */ jsx5(
|
|
346
|
+
RecordingButton,
|
|
347
|
+
{
|
|
348
|
+
size: "md",
|
|
349
|
+
bgColor: getButtonColor(state, isSilent),
|
|
350
|
+
icon,
|
|
351
|
+
iconSpin: isTranscribing && !isRecording,
|
|
352
|
+
iconColor,
|
|
353
|
+
disabled: isDisabled,
|
|
354
|
+
onClick: handleClick,
|
|
355
|
+
ariaLabel: isRecording ? "Detener grabaci\xF3n" : "Iniciar grabaci\xF3n de voz",
|
|
356
|
+
className: "relative z-10"
|
|
357
|
+
}
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
)
|
|
361
|
+
] }),
|
|
362
|
+
isRecording && /* @__PURE__ */ jsx5(
|
|
363
|
+
motion4.div,
|
|
364
|
+
{
|
|
365
|
+
initial: { opacity: 0, x: -10 },
|
|
366
|
+
animate: { opacity: 1, x: 0 },
|
|
367
|
+
exit: { opacity: 0, x: -10 },
|
|
368
|
+
children: /* @__PURE__ */ jsx5(
|
|
369
|
+
RecordingTimer,
|
|
370
|
+
{
|
|
371
|
+
time: recordingTime,
|
|
372
|
+
size: "sm",
|
|
373
|
+
showDot: true,
|
|
374
|
+
textColor: "text-gray-700 dark:text-gray-300"
|
|
375
|
+
}
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
),
|
|
379
|
+
isTranscribing && !isRecording && /* @__PURE__ */ jsx5(
|
|
380
|
+
motion4.div,
|
|
381
|
+
{
|
|
382
|
+
initial: { opacity: 0 },
|
|
383
|
+
animate: { opacity: 1 },
|
|
384
|
+
className: "text-sm text-blue-600 dark:fi-text-primary font-medium",
|
|
385
|
+
children: "Transcribiendo..."
|
|
386
|
+
}
|
|
387
|
+
)
|
|
388
|
+
] });
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// src/voice/SpeakButton.tsx
|
|
392
|
+
import { Volume2, Loader2 as Loader24, Play } from "lucide-react";
|
|
393
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
394
|
+
var ICON_SIZE = { xs: "w-3 h-3", sm: "w-3.5 h-3.5", md: "w-4 h-4" };
|
|
395
|
+
var PAD_SIZE = { xs: "p-1", sm: "p-1.5", md: "p-2" };
|
|
396
|
+
function formatVoiceName(voiceId) {
|
|
397
|
+
const match = voiceId.match(/([A-Z][a-z]+)Neural$/);
|
|
398
|
+
if (match) return match[1];
|
|
399
|
+
return voiceId.charAt(0).toUpperCase() + voiceId.slice(1);
|
|
400
|
+
}
|
|
401
|
+
function SpeakButton({
|
|
402
|
+
content,
|
|
403
|
+
voice = "nova",
|
|
404
|
+
isUserMessage = false,
|
|
405
|
+
onOpenPlayer,
|
|
406
|
+
busy = false,
|
|
407
|
+
cached = false,
|
|
408
|
+
size = "sm",
|
|
409
|
+
className,
|
|
410
|
+
iconClassName,
|
|
411
|
+
title,
|
|
412
|
+
busyTitle = "Generando audio\u2026",
|
|
413
|
+
cachedTitle = "Reproducir (ya generado)"
|
|
414
|
+
}) {
|
|
415
|
+
const voiceDisplay = formatVoiceName(voice);
|
|
416
|
+
const icon = iconClassName ?? ICON_SIZE[size];
|
|
417
|
+
const label = busy ? busyTitle : cached ? cachedTitle : title ?? `Escuchar (${voiceDisplay})`;
|
|
418
|
+
return /* @__PURE__ */ jsx6(
|
|
419
|
+
"button",
|
|
420
|
+
{
|
|
421
|
+
type: "button",
|
|
422
|
+
onClick: () => {
|
|
423
|
+
if (!busy) onOpenPlayer(content, voice, isUserMessage);
|
|
424
|
+
},
|
|
425
|
+
disabled: busy,
|
|
426
|
+
"aria-busy": busy,
|
|
427
|
+
className: className ?? PAD_SIZE[size],
|
|
428
|
+
title: label,
|
|
429
|
+
"aria-label": busy ? busyTitle : cached ? cachedTitle : `Escuchar mensaje con voz ${voiceDisplay}`,
|
|
430
|
+
children: busy ? /* @__PURE__ */ jsx6(Loader24, { className: `${icon} animate-spin` }) : cached ? /* @__PURE__ */ jsx6(Play, { className: icon }) : /* @__PURE__ */ jsx6(Volume2, { className: icon })
|
|
431
|
+
}
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// src/voice/createAudioPlayer.ts
|
|
436
|
+
function clampSeekTarget(seconds, duration) {
|
|
437
|
+
if (!Number.isFinite(seconds)) return 0;
|
|
438
|
+
const lowerBounded = Math.max(0, seconds);
|
|
439
|
+
if (Number.isFinite(duration) && duration > 0) {
|
|
440
|
+
return Math.min(lowerBounded, duration);
|
|
441
|
+
}
|
|
442
|
+
return lowerBounded;
|
|
443
|
+
}
|
|
444
|
+
var INITIAL = {
|
|
445
|
+
status: "idle",
|
|
446
|
+
isPlaying: false,
|
|
447
|
+
isLoading: false,
|
|
448
|
+
error: null,
|
|
449
|
+
currentSrc: null,
|
|
450
|
+
duration: 0,
|
|
451
|
+
currentTime: 0
|
|
452
|
+
};
|
|
453
|
+
function defaultCreateElement() {
|
|
454
|
+
if (typeof Audio === "undefined") {
|
|
455
|
+
throw new Error(
|
|
456
|
+
"createAudioPlayer: no Audio constructor available. Run in a browser, or inject `createElement` for non-DOM environments/tests."
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
return new Audio();
|
|
460
|
+
}
|
|
461
|
+
function isBlob(source) {
|
|
462
|
+
return typeof Blob !== "undefined" && source instanceof Blob;
|
|
463
|
+
}
|
|
464
|
+
function createAudioPlayer(options = {}) {
|
|
465
|
+
const {
|
|
466
|
+
createElement = defaultCreateElement,
|
|
467
|
+
createObjectURL = (blob) => URL.createObjectURL(blob),
|
|
468
|
+
revokeObjectURL = (url) => URL.revokeObjectURL(url),
|
|
469
|
+
onError,
|
|
470
|
+
onEnded
|
|
471
|
+
} = options;
|
|
472
|
+
let state = { ...INITIAL };
|
|
473
|
+
let el = null;
|
|
474
|
+
let ownedUrl = null;
|
|
475
|
+
let disposed = false;
|
|
476
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
477
|
+
function emit() {
|
|
478
|
+
for (const l of listeners) l();
|
|
479
|
+
}
|
|
480
|
+
function setState(patch) {
|
|
481
|
+
state = { ...state, ...patch };
|
|
482
|
+
emit();
|
|
483
|
+
}
|
|
484
|
+
const onLoadedMetadata = () => {
|
|
485
|
+
setState({
|
|
486
|
+
isLoading: false,
|
|
487
|
+
duration: Number.isFinite(el?.duration) ? el.duration : 0
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
const onTimeUpdate = () => {
|
|
491
|
+
if (el) setState({ currentTime: el.currentTime });
|
|
492
|
+
};
|
|
493
|
+
const onPlaying = () => {
|
|
494
|
+
setState({ status: "playing", isPlaying: true, isLoading: false, error: null });
|
|
495
|
+
};
|
|
496
|
+
const onPause = () => {
|
|
497
|
+
if (state.status !== "idle" && state.status !== "error") {
|
|
498
|
+
setState({ status: "paused", isPlaying: false });
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
const onEndedEvt = () => {
|
|
502
|
+
setState({ status: "idle", isPlaying: false, currentTime: 0 });
|
|
503
|
+
onEnded?.();
|
|
504
|
+
};
|
|
505
|
+
const onErrorEvt = () => {
|
|
506
|
+
const err = new Error("audio element error");
|
|
507
|
+
setState({ status: "error", isPlaying: false, isLoading: false, error: err });
|
|
508
|
+
onError?.(err, "audioPlayer:element");
|
|
509
|
+
};
|
|
510
|
+
function ensureElement() {
|
|
511
|
+
if (el) return el;
|
|
512
|
+
el = createElement();
|
|
513
|
+
el.addEventListener("loadedmetadata", onLoadedMetadata);
|
|
514
|
+
el.addEventListener("timeupdate", onTimeUpdate);
|
|
515
|
+
el.addEventListener("playing", onPlaying);
|
|
516
|
+
el.addEventListener("play", onPlaying);
|
|
517
|
+
el.addEventListener("pause", onPause);
|
|
518
|
+
el.addEventListener("ended", onEndedEvt);
|
|
519
|
+
el.addEventListener("error", onErrorEvt);
|
|
520
|
+
return el;
|
|
521
|
+
}
|
|
522
|
+
function releaseOwnedUrl() {
|
|
523
|
+
if (ownedUrl) {
|
|
524
|
+
revokeObjectURL(ownedUrl);
|
|
525
|
+
ownedUrl = null;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
function load(source) {
|
|
529
|
+
if (disposed) return;
|
|
530
|
+
const element = ensureElement();
|
|
531
|
+
releaseOwnedUrl();
|
|
532
|
+
let url;
|
|
533
|
+
if (isBlob(source)) {
|
|
534
|
+
url = createObjectURL(source);
|
|
535
|
+
ownedUrl = url;
|
|
536
|
+
} else {
|
|
537
|
+
url = source.url;
|
|
538
|
+
}
|
|
539
|
+
element.src = url;
|
|
540
|
+
element.load();
|
|
541
|
+
setState({
|
|
542
|
+
status: "loading",
|
|
543
|
+
isLoading: true,
|
|
544
|
+
isPlaying: false,
|
|
545
|
+
error: null,
|
|
546
|
+
currentSrc: url,
|
|
547
|
+
currentTime: 0,
|
|
548
|
+
duration: 0
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
async function play() {
|
|
552
|
+
if (disposed || !el) return;
|
|
553
|
+
try {
|
|
554
|
+
await el.play();
|
|
555
|
+
setState({ status: "playing", isPlaying: true, error: null });
|
|
556
|
+
} catch (error) {
|
|
557
|
+
setState({
|
|
558
|
+
status: "error",
|
|
559
|
+
isPlaying: false,
|
|
560
|
+
error: error instanceof Error ? error : new Error(String(error))
|
|
561
|
+
});
|
|
562
|
+
onError?.(error, "audioPlayer:play");
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
function pause() {
|
|
566
|
+
if (disposed || !el) return;
|
|
567
|
+
el.pause();
|
|
568
|
+
setState({ status: "paused", isPlaying: false });
|
|
569
|
+
}
|
|
570
|
+
function stop() {
|
|
571
|
+
if (disposed || !el) return;
|
|
572
|
+
el.pause();
|
|
573
|
+
el.currentTime = 0;
|
|
574
|
+
el.src = "";
|
|
575
|
+
releaseOwnedUrl();
|
|
576
|
+
setState({
|
|
577
|
+
status: "idle",
|
|
578
|
+
isPlaying: false,
|
|
579
|
+
isLoading: false,
|
|
580
|
+
currentSrc: null,
|
|
581
|
+
currentTime: 0
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
async function toggle() {
|
|
585
|
+
if (state.isPlaying) {
|
|
586
|
+
pause();
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
await play();
|
|
590
|
+
}
|
|
591
|
+
function seek(seconds) {
|
|
592
|
+
if (disposed || !el) return;
|
|
593
|
+
const target = clampSeekTarget(seconds, state.duration);
|
|
594
|
+
el.currentTime = target;
|
|
595
|
+
setState({ currentTime: target });
|
|
596
|
+
}
|
|
597
|
+
function seekBy(deltaSeconds) {
|
|
598
|
+
if (disposed || !el) return;
|
|
599
|
+
const base = Number.isFinite(el.currentTime) ? el.currentTime : state.currentTime;
|
|
600
|
+
seek(base + deltaSeconds);
|
|
601
|
+
}
|
|
602
|
+
function dispose() {
|
|
603
|
+
if (disposed) return;
|
|
604
|
+
disposed = true;
|
|
605
|
+
if (el) {
|
|
606
|
+
el.pause();
|
|
607
|
+
el.removeEventListener("loadedmetadata", onLoadedMetadata);
|
|
608
|
+
el.removeEventListener("timeupdate", onTimeUpdate);
|
|
609
|
+
el.removeEventListener("playing", onPlaying);
|
|
610
|
+
el.removeEventListener("play", onPlaying);
|
|
611
|
+
el.removeEventListener("pause", onPause);
|
|
612
|
+
el.removeEventListener("ended", onEndedEvt);
|
|
613
|
+
el.removeEventListener("error", onErrorEvt);
|
|
614
|
+
}
|
|
615
|
+
releaseOwnedUrl();
|
|
616
|
+
listeners.clear();
|
|
617
|
+
}
|
|
618
|
+
return {
|
|
619
|
+
getState: () => state,
|
|
620
|
+
subscribe(listener) {
|
|
621
|
+
listeners.add(listener);
|
|
622
|
+
return () => listeners.delete(listener);
|
|
623
|
+
},
|
|
624
|
+
load,
|
|
625
|
+
play,
|
|
626
|
+
pause,
|
|
627
|
+
stop,
|
|
628
|
+
toggle,
|
|
629
|
+
seek,
|
|
630
|
+
seekBy,
|
|
631
|
+
dispose
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/voice/useAudioPlayer.ts
|
|
636
|
+
import { useEffect, useMemo, useRef, useSyncExternalStore } from "react";
|
|
637
|
+
function useAudioPlayer(opts = {}) {
|
|
638
|
+
const cbRef = useRef(opts);
|
|
639
|
+
cbRef.current = opts;
|
|
640
|
+
const controller = useMemo(
|
|
641
|
+
() => createAudioPlayer({
|
|
642
|
+
onError: (e, ctx) => cbRef.current.onError?.(e, ctx),
|
|
643
|
+
onEnded: () => cbRef.current.onEnded?.(),
|
|
644
|
+
...opts.deps
|
|
645
|
+
}),
|
|
646
|
+
// One controller for the component's lifetime; deps are read once by design.
|
|
647
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
648
|
+
[]
|
|
649
|
+
);
|
|
650
|
+
useEffect(() => () => controller.dispose(), [controller]);
|
|
651
|
+
const state = useSyncExternalStore(
|
|
652
|
+
controller.subscribe,
|
|
653
|
+
controller.getState,
|
|
654
|
+
controller.getState
|
|
655
|
+
);
|
|
656
|
+
return {
|
|
657
|
+
...state,
|
|
658
|
+
load: controller.load,
|
|
659
|
+
play: controller.play,
|
|
660
|
+
pause: controller.pause,
|
|
661
|
+
stop: controller.stop,
|
|
662
|
+
toggle: controller.toggle,
|
|
663
|
+
seek: controller.seek,
|
|
664
|
+
seekBy: controller.seekBy,
|
|
665
|
+
playSource: async (source) => {
|
|
666
|
+
controller.load(source);
|
|
667
|
+
await controller.play();
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
// src/voice/AudioPlayer.tsx
|
|
673
|
+
import { Play as Play2, Pause, Square as Square2, Loader2 as Loader25, AlertCircle } from "lucide-react";
|
|
674
|
+
import { useEffect as useEffect2 } from "react";
|
|
675
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
676
|
+
var ICON = "w-4 h-4";
|
|
677
|
+
var BTN = "p-2 disabled:opacity-40";
|
|
678
|
+
function AudioPlayer({
|
|
679
|
+
source,
|
|
680
|
+
autoPlay = false,
|
|
681
|
+
onError,
|
|
682
|
+
onEnded,
|
|
683
|
+
className,
|
|
684
|
+
buttonClassName,
|
|
685
|
+
iconClassName
|
|
686
|
+
}) {
|
|
687
|
+
const player = useAudioPlayer({ onError, onEnded });
|
|
688
|
+
const { load, play, toggle, stop, isPlaying, isLoading, error, currentSrc } = player;
|
|
689
|
+
useEffect2(() => {
|
|
690
|
+
if (!source) return;
|
|
691
|
+
load(source);
|
|
692
|
+
if (autoPlay) void play();
|
|
693
|
+
}, [source, autoPlay]);
|
|
694
|
+
const hasSource = currentSrc !== null;
|
|
695
|
+
const btnClass = buttonClassName ?? BTN;
|
|
696
|
+
const iconClass = iconClassName ?? ICON;
|
|
697
|
+
return /* @__PURE__ */ jsxs5("div", { className, "data-fi-audio-player": "", children: [
|
|
698
|
+
/* @__PURE__ */ jsx7(
|
|
699
|
+
"button",
|
|
700
|
+
{
|
|
701
|
+
type: "button",
|
|
702
|
+
onClick: () => void toggle(),
|
|
703
|
+
disabled: !hasSource || isLoading,
|
|
704
|
+
"aria-pressed": isPlaying,
|
|
705
|
+
"aria-label": isPlaying ? "Pausar audio" : "Reproducir audio",
|
|
706
|
+
className: btnClass,
|
|
707
|
+
children: isLoading ? /* @__PURE__ */ jsx7(Loader25, { className: `${iconClass} animate-spin`, "aria-hidden": true }) : isPlaying ? /* @__PURE__ */ jsx7(Pause, { className: iconClass, "aria-hidden": true }) : /* @__PURE__ */ jsx7(Play2, { className: iconClass, "aria-hidden": true })
|
|
708
|
+
}
|
|
709
|
+
),
|
|
710
|
+
/* @__PURE__ */ jsx7(
|
|
711
|
+
"button",
|
|
712
|
+
{
|
|
713
|
+
type: "button",
|
|
714
|
+
onClick: stop,
|
|
715
|
+
disabled: !hasSource,
|
|
716
|
+
"aria-label": "Detener audio",
|
|
717
|
+
className: btnClass,
|
|
718
|
+
children: /* @__PURE__ */ jsx7(Square2, { className: iconClass, "aria-hidden": true })
|
|
719
|
+
}
|
|
720
|
+
),
|
|
721
|
+
error ? /* @__PURE__ */ jsxs5("span", { role: "alert", className: "inline-flex items-center gap-1 text-xs", children: [
|
|
722
|
+
/* @__PURE__ */ jsx7(AlertCircle, { className: iconClass, "aria-hidden": true }),
|
|
723
|
+
"Error de audio"
|
|
724
|
+
] }) : null
|
|
725
|
+
] });
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// src/voice/RichAudioPlayer.tsx
|
|
729
|
+
import {
|
|
730
|
+
Play as Play3,
|
|
731
|
+
Pause as Pause2,
|
|
732
|
+
Square as Square3,
|
|
733
|
+
Loader2 as Loader26,
|
|
734
|
+
AlertCircle as AlertCircle2,
|
|
735
|
+
RotateCcw,
|
|
736
|
+
RotateCw
|
|
737
|
+
} from "lucide-react";
|
|
738
|
+
import { useEffect as useEffect3 } from "react";
|
|
739
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
740
|
+
var ICON2 = "w-4 h-4";
|
|
741
|
+
var BTN2 = "p-2 disabled:opacity-40";
|
|
742
|
+
function formatPlaybackTime(seconds) {
|
|
743
|
+
if (!Number.isFinite(seconds) || seconds < 0) seconds = 0;
|
|
744
|
+
const total = Math.floor(seconds);
|
|
745
|
+
const h = Math.floor(total / 3600);
|
|
746
|
+
const m = Math.floor(total % 3600 / 60);
|
|
747
|
+
const s = total % 60;
|
|
748
|
+
const ss = String(s).padStart(2, "0");
|
|
749
|
+
if (h > 0) return `${h}:${String(m).padStart(2, "0")}:${ss}`;
|
|
750
|
+
return `${m}:${ss}`;
|
|
751
|
+
}
|
|
752
|
+
function RichAudioPlayer({
|
|
753
|
+
source,
|
|
754
|
+
autoPlay = false,
|
|
755
|
+
skipSeconds = 10,
|
|
756
|
+
showTime = true,
|
|
757
|
+
onError,
|
|
758
|
+
onEnded,
|
|
759
|
+
className,
|
|
760
|
+
buttonClassName,
|
|
761
|
+
iconClassName,
|
|
762
|
+
progressClassName
|
|
763
|
+
}) {
|
|
764
|
+
const player = useAudioPlayer({ onError, onEnded });
|
|
765
|
+
const {
|
|
766
|
+
load,
|
|
767
|
+
play,
|
|
768
|
+
toggle,
|
|
769
|
+
stop,
|
|
770
|
+
seek,
|
|
771
|
+
seekBy,
|
|
772
|
+
isPlaying,
|
|
773
|
+
isLoading,
|
|
774
|
+
error,
|
|
775
|
+
currentSrc,
|
|
776
|
+
duration,
|
|
777
|
+
currentTime
|
|
778
|
+
} = player;
|
|
779
|
+
useEffect3(() => {
|
|
780
|
+
if (!source) return;
|
|
781
|
+
load(source);
|
|
782
|
+
if (autoPlay) void play();
|
|
783
|
+
}, [source, autoPlay]);
|
|
784
|
+
const hasSource = currentSrc !== null;
|
|
785
|
+
const canSeek = hasSource && duration > 0;
|
|
786
|
+
const btnClass = buttonClassName ?? BTN2;
|
|
787
|
+
const iconClass = iconClassName ?? ICON2;
|
|
788
|
+
const positionLabel = `${formatPlaybackTime(currentTime)} / ${formatPlaybackTime(
|
|
789
|
+
duration
|
|
790
|
+
)}`;
|
|
791
|
+
return /* @__PURE__ */ jsxs6(
|
|
792
|
+
"div",
|
|
793
|
+
{
|
|
794
|
+
className,
|
|
795
|
+
"data-fi-audio-player": "rich",
|
|
796
|
+
role: "group",
|
|
797
|
+
"aria-label": "Controles de reproducci\xF3n de audio",
|
|
798
|
+
children: [
|
|
799
|
+
/* @__PURE__ */ jsx8(
|
|
800
|
+
"button",
|
|
801
|
+
{
|
|
802
|
+
type: "button",
|
|
803
|
+
onClick: () => seekBy(-skipSeconds),
|
|
804
|
+
disabled: !canSeek,
|
|
805
|
+
"aria-label": `Retroceder ${skipSeconds} segundos`,
|
|
806
|
+
className: btnClass,
|
|
807
|
+
children: /* @__PURE__ */ jsx8(RotateCcw, { className: iconClass, "aria-hidden": true })
|
|
808
|
+
}
|
|
809
|
+
),
|
|
810
|
+
/* @__PURE__ */ jsx8(
|
|
811
|
+
"button",
|
|
812
|
+
{
|
|
813
|
+
type: "button",
|
|
814
|
+
onClick: () => void toggle(),
|
|
815
|
+
disabled: !hasSource || isLoading,
|
|
816
|
+
"aria-pressed": isPlaying,
|
|
817
|
+
"aria-label": isPlaying ? "Pausar audio" : "Reproducir audio",
|
|
818
|
+
className: btnClass,
|
|
819
|
+
children: isLoading ? /* @__PURE__ */ jsx8(Loader26, { className: `${iconClass} animate-spin`, "aria-hidden": true }) : isPlaying ? /* @__PURE__ */ jsx8(Pause2, { className: iconClass, "aria-hidden": true }) : /* @__PURE__ */ jsx8(Play3, { className: iconClass, "aria-hidden": true })
|
|
820
|
+
}
|
|
821
|
+
),
|
|
822
|
+
/* @__PURE__ */ jsx8(
|
|
823
|
+
"button",
|
|
824
|
+
{
|
|
825
|
+
type: "button",
|
|
826
|
+
onClick: stop,
|
|
827
|
+
disabled: !hasSource,
|
|
828
|
+
"aria-label": "Detener audio",
|
|
829
|
+
className: btnClass,
|
|
830
|
+
children: /* @__PURE__ */ jsx8(Square3, { className: iconClass, "aria-hidden": true })
|
|
831
|
+
}
|
|
832
|
+
),
|
|
833
|
+
/* @__PURE__ */ jsx8(
|
|
834
|
+
"button",
|
|
835
|
+
{
|
|
836
|
+
type: "button",
|
|
837
|
+
onClick: () => seekBy(skipSeconds),
|
|
838
|
+
disabled: !canSeek,
|
|
839
|
+
"aria-label": `Avanzar ${skipSeconds} segundos`,
|
|
840
|
+
className: btnClass,
|
|
841
|
+
children: /* @__PURE__ */ jsx8(RotateCw, { className: iconClass, "aria-hidden": true })
|
|
842
|
+
}
|
|
843
|
+
),
|
|
844
|
+
/* @__PURE__ */ jsx8(
|
|
845
|
+
"input",
|
|
846
|
+
{
|
|
847
|
+
type: "range",
|
|
848
|
+
min: 0,
|
|
849
|
+
max: duration > 0 ? duration : 0,
|
|
850
|
+
step: 0.1,
|
|
851
|
+
value: Math.min(currentTime, duration > 0 ? duration : currentTime),
|
|
852
|
+
onChange: (e) => seek(Number(e.target.value)),
|
|
853
|
+
disabled: !canSeek,
|
|
854
|
+
"aria-label": "Progreso de reproducci\xF3n",
|
|
855
|
+
"aria-valuetext": positionLabel,
|
|
856
|
+
className: progressClassName,
|
|
857
|
+
"data-fi-audio-progress": ""
|
|
858
|
+
}
|
|
859
|
+
),
|
|
860
|
+
showTime ? /* @__PURE__ */ jsx8("span", { "data-fi-audio-time": "", "aria-hidden": true, className: "text-xs tabular-nums", children: positionLabel }) : null,
|
|
861
|
+
error ? /* @__PURE__ */ jsxs6("span", { role: "alert", className: "inline-flex items-center gap-1 text-xs", children: [
|
|
862
|
+
/* @__PURE__ */ jsx8(AlertCircle2, { className: iconClass, "aria-hidden": true }),
|
|
863
|
+
"Error de audio"
|
|
864
|
+
] }) : null
|
|
865
|
+
]
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
// src/voice/AudioVisualizer.tsx
|
|
871
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
872
|
+
var MIN_BAR_PCT = 4;
|
|
873
|
+
function normalizeLevels(levels) {
|
|
874
|
+
return levels.map(
|
|
875
|
+
(v) => !Number.isFinite(v) ? 0 : v < 0 ? 0 : v > 1 ? 1 : v
|
|
876
|
+
);
|
|
877
|
+
}
|
|
878
|
+
function resampleLevels(levels, count) {
|
|
879
|
+
if (count <= 0) return [];
|
|
880
|
+
if (levels.length === 0) return new Array(count).fill(0);
|
|
881
|
+
if (levels.length === count) return levels.slice();
|
|
882
|
+
const out = [];
|
|
883
|
+
for (let i = 0; i < count; i++) {
|
|
884
|
+
const idx = Math.min(
|
|
885
|
+
levels.length - 1,
|
|
886
|
+
Math.floor(i / count * levels.length)
|
|
887
|
+
);
|
|
888
|
+
out.push(levels[idx]);
|
|
889
|
+
}
|
|
890
|
+
return out;
|
|
891
|
+
}
|
|
892
|
+
function AudioVisualizer({
|
|
893
|
+
levels,
|
|
894
|
+
variant = "bars",
|
|
895
|
+
active = true,
|
|
896
|
+
barCount,
|
|
897
|
+
label = "Visualizador de nivel de audio",
|
|
898
|
+
className,
|
|
899
|
+
barClassName,
|
|
900
|
+
color
|
|
901
|
+
}) {
|
|
902
|
+
const normalized = normalizeLevels(levels);
|
|
903
|
+
if (variant === "pulse") {
|
|
904
|
+
const peak = active && normalized.length ? Math.max(...normalized) : 0;
|
|
905
|
+
const scale = 1 + peak;
|
|
906
|
+
return /* @__PURE__ */ jsx9(
|
|
907
|
+
"div",
|
|
908
|
+
{
|
|
909
|
+
role: "img",
|
|
910
|
+
"aria-label": label,
|
|
911
|
+
className,
|
|
912
|
+
"data-fi-audio-visualizer": "pulse",
|
|
913
|
+
"data-active": active ? "" : void 0,
|
|
914
|
+
children: /* @__PURE__ */ jsx9(
|
|
915
|
+
"span",
|
|
916
|
+
{
|
|
917
|
+
"data-fi-pulse-core": "",
|
|
918
|
+
style: {
|
|
919
|
+
display: "inline-block",
|
|
920
|
+
transform: `scale(${scale})`,
|
|
921
|
+
borderColor: color
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
)
|
|
925
|
+
}
|
|
926
|
+
);
|
|
927
|
+
}
|
|
928
|
+
const count = barCount && barCount > 0 ? barCount : normalized.length;
|
|
929
|
+
const bars = resampleLevels(normalized, count);
|
|
930
|
+
return /* @__PURE__ */ jsx9(
|
|
931
|
+
"div",
|
|
932
|
+
{
|
|
933
|
+
role: "img",
|
|
934
|
+
"aria-label": label,
|
|
935
|
+
className,
|
|
936
|
+
"data-fi-audio-visualizer": "bars",
|
|
937
|
+
"data-active": active ? "" : void 0,
|
|
938
|
+
style: { display: "inline-flex", alignItems: "flex-end" },
|
|
939
|
+
children: bars.map((level, i) => {
|
|
940
|
+
const pct = active ? Math.max(MIN_BAR_PCT, level * 100) : MIN_BAR_PCT;
|
|
941
|
+
return /* @__PURE__ */ jsx9(
|
|
942
|
+
"span",
|
|
943
|
+
{
|
|
944
|
+
"data-fi-audio-bar": "",
|
|
945
|
+
className: barClassName,
|
|
946
|
+
style: { height: `${pct}%`, backgroundColor: color }
|
|
947
|
+
},
|
|
948
|
+
i
|
|
949
|
+
);
|
|
950
|
+
})
|
|
951
|
+
}
|
|
952
|
+
);
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
// src/voice/ComposerMicSlot.tsx
|
|
956
|
+
import { Mic as Mic2, MicOff, Square as Square4, Loader2 as Loader27 } from "lucide-react";
|
|
957
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
958
|
+
var ICON3 = "w-4 h-4";
|
|
959
|
+
var BTN3 = "p-2 disabled:opacity-40";
|
|
960
|
+
function ComposerMicSlot({
|
|
961
|
+
available = false,
|
|
962
|
+
recording = false,
|
|
963
|
+
busy = false,
|
|
964
|
+
onStart,
|
|
965
|
+
onStop,
|
|
966
|
+
unavailableLabel = "Dictado por voz no disponible todav\xEDa",
|
|
967
|
+
startLabel = "Iniciar dictado por voz",
|
|
968
|
+
stopLabel = "Detener dictado por voz",
|
|
969
|
+
busyLabel = "Transcribiendo\u2026",
|
|
970
|
+
className,
|
|
971
|
+
buttonClassName,
|
|
972
|
+
iconClassName
|
|
973
|
+
}) {
|
|
974
|
+
const btnClass = buttonClassName ?? BTN3;
|
|
975
|
+
const iconClass = iconClassName ?? ICON3;
|
|
976
|
+
const disabled = !available || busy;
|
|
977
|
+
const label = !available ? unavailableLabel : busy ? busyLabel : recording ? stopLabel : startLabel;
|
|
978
|
+
const handleClick = () => {
|
|
979
|
+
if (disabled) return;
|
|
980
|
+
if (recording) onStop?.();
|
|
981
|
+
else onStart?.();
|
|
982
|
+
};
|
|
983
|
+
const Icon = !available ? MicOff : busy ? Loader27 : recording ? Square4 : Mic2;
|
|
984
|
+
return /* @__PURE__ */ jsx10("div", { className, "data-fi-mic-slot": "", "data-available": available ? "" : void 0, children: /* @__PURE__ */ jsx10(
|
|
985
|
+
"button",
|
|
986
|
+
{
|
|
987
|
+
type: "button",
|
|
988
|
+
onClick: handleClick,
|
|
989
|
+
disabled,
|
|
990
|
+
"aria-disabled": disabled,
|
|
991
|
+
"aria-pressed": available ? recording : void 0,
|
|
992
|
+
"aria-label": label,
|
|
993
|
+
title: !available ? unavailableLabel : void 0,
|
|
994
|
+
className: btnClass,
|
|
995
|
+
children: /* @__PURE__ */ jsx10(
|
|
996
|
+
Icon,
|
|
997
|
+
{
|
|
998
|
+
className: busy ? `${iconClass} animate-spin` : iconClass,
|
|
999
|
+
"aria-hidden": true
|
|
1000
|
+
}
|
|
1001
|
+
)
|
|
1002
|
+
}
|
|
1003
|
+
) });
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
// src/voice/useVoice.ts
|
|
1007
|
+
import { useCallback, useRef as useRef2, useState } from "react";
|
|
1008
|
+
function toUrl(src) {
|
|
1009
|
+
return src instanceof Blob ? URL.createObjectURL(src) : src.url;
|
|
1010
|
+
}
|
|
1011
|
+
var TTS_CACHE_MAX_CLIPS = 8;
|
|
1012
|
+
var clipKey = (text, voice) => `${voice}\0${text}`;
|
|
1013
|
+
function useVoice(adapter, opts = {}) {
|
|
1014
|
+
const { onError } = opts;
|
|
1015
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
1016
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
1017
|
+
const [audioUrl, setAudioUrl] = useState(null);
|
|
1018
|
+
const [voiceName, setVoiceName] = useState("nova");
|
|
1019
|
+
const [isUserMessage, setIsUserMessage] = useState(false);
|
|
1020
|
+
const [currentVoice, setCurrentVoice] = useState("nova");
|
|
1021
|
+
const [currentText, setCurrentText] = useState("");
|
|
1022
|
+
const inFlight = useRef2(false);
|
|
1023
|
+
const clipCache = useRef2(/* @__PURE__ */ new Map());
|
|
1024
|
+
const synthesizeCached = useCallback(
|
|
1025
|
+
async (text, voice) => {
|
|
1026
|
+
const cache = clipCache.current;
|
|
1027
|
+
const key = clipKey(text, voice);
|
|
1028
|
+
const hit = cache.get(key);
|
|
1029
|
+
if (hit) {
|
|
1030
|
+
cache.delete(key);
|
|
1031
|
+
cache.set(key, hit);
|
|
1032
|
+
return hit;
|
|
1033
|
+
}
|
|
1034
|
+
const src = await adapter.synthesize(text, voice);
|
|
1035
|
+
if (src instanceof Blob && src.size > 0) {
|
|
1036
|
+
cache.set(key, src);
|
|
1037
|
+
while (cache.size > TTS_CACHE_MAX_CLIPS) {
|
|
1038
|
+
const oldest = cache.keys().next().value;
|
|
1039
|
+
if (oldest === void 0) break;
|
|
1040
|
+
cache.delete(oldest);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return src;
|
|
1044
|
+
},
|
|
1045
|
+
[adapter]
|
|
1046
|
+
);
|
|
1047
|
+
const getVoiceDisplayName = useCallback(
|
|
1048
|
+
(voiceId) => {
|
|
1049
|
+
const found = adapter?.availableVoices?.find((v) => v.id === voiceId);
|
|
1050
|
+
if (found) return found.label.split(" ")[0];
|
|
1051
|
+
const match = voiceId.match(/([A-Z][a-z]+)Neural$/);
|
|
1052
|
+
return match ? match[1] : voiceId;
|
|
1053
|
+
},
|
|
1054
|
+
[adapter]
|
|
1055
|
+
);
|
|
1056
|
+
const generateAudio = useCallback(
|
|
1057
|
+
async (text, voice = "nova", isUser = false) => {
|
|
1058
|
+
if (!adapter?.synthesize) return;
|
|
1059
|
+
if (inFlight.current) return;
|
|
1060
|
+
inFlight.current = true;
|
|
1061
|
+
setCurrentText(text);
|
|
1062
|
+
setCurrentVoice(voice);
|
|
1063
|
+
setIsUserMessage(isUser);
|
|
1064
|
+
setVoiceName(getVoiceDisplayName(voice));
|
|
1065
|
+
setIsOpen(true);
|
|
1066
|
+
setAudioUrl((prev) => {
|
|
1067
|
+
if (prev?.startsWith("blob:")) URL.revokeObjectURL(prev);
|
|
1068
|
+
return null;
|
|
1069
|
+
});
|
|
1070
|
+
const isHit = clipCache.current.has(clipKey(text, voice));
|
|
1071
|
+
if (!isHit) setIsLoading(true);
|
|
1072
|
+
try {
|
|
1073
|
+
const src = await synthesizeCached(text, voice);
|
|
1074
|
+
setAudioUrl(toUrl(src));
|
|
1075
|
+
} catch (error) {
|
|
1076
|
+
onError?.(error, "useVoice:TTS");
|
|
1077
|
+
setIsOpen(false);
|
|
1078
|
+
} finally {
|
|
1079
|
+
inFlight.current = false;
|
|
1080
|
+
setIsLoading(false);
|
|
1081
|
+
}
|
|
1082
|
+
},
|
|
1083
|
+
[adapter, getVoiceDisplayName, onError, synthesizeCached]
|
|
1084
|
+
);
|
|
1085
|
+
const changeVoice = useCallback(
|
|
1086
|
+
async (newVoice) => {
|
|
1087
|
+
if (!currentText || !adapter?.synthesize) return;
|
|
1088
|
+
if (inFlight.current) return;
|
|
1089
|
+
inFlight.current = true;
|
|
1090
|
+
setCurrentVoice(newVoice);
|
|
1091
|
+
setVoiceName(getVoiceDisplayName(newVoice));
|
|
1092
|
+
setIsLoading(true);
|
|
1093
|
+
if (audioUrl) URL.revokeObjectURL(audioUrl);
|
|
1094
|
+
setAudioUrl(null);
|
|
1095
|
+
try {
|
|
1096
|
+
const src = await synthesizeCached(currentText, newVoice);
|
|
1097
|
+
setAudioUrl(toUrl(src));
|
|
1098
|
+
} catch (error) {
|
|
1099
|
+
onError?.(error, "useVoice:VoiceChange");
|
|
1100
|
+
} finally {
|
|
1101
|
+
inFlight.current = false;
|
|
1102
|
+
setIsLoading(false);
|
|
1103
|
+
}
|
|
1104
|
+
},
|
|
1105
|
+
[adapter, audioUrl, currentText, getVoiceDisplayName, onError, synthesizeCached]
|
|
1106
|
+
);
|
|
1107
|
+
const close = useCallback(() => {
|
|
1108
|
+
setIsOpen(false);
|
|
1109
|
+
setAudioUrl(null);
|
|
1110
|
+
setIsLoading(false);
|
|
1111
|
+
setCurrentText("");
|
|
1112
|
+
setIsUserMessage(false);
|
|
1113
|
+
}, []);
|
|
1114
|
+
const hasCachedAudio = useCallback(
|
|
1115
|
+
(text, voice = "nova") => clipCache.current.has(clipKey(text, voice)),
|
|
1116
|
+
[]
|
|
1117
|
+
);
|
|
1118
|
+
return {
|
|
1119
|
+
isOpen,
|
|
1120
|
+
isLoading,
|
|
1121
|
+
audioUrl,
|
|
1122
|
+
voiceName,
|
|
1123
|
+
isUserMessage,
|
|
1124
|
+
currentVoice,
|
|
1125
|
+
currentText,
|
|
1126
|
+
generateAudio,
|
|
1127
|
+
changeVoice,
|
|
1128
|
+
close,
|
|
1129
|
+
hasCachedAudio
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
// src/voice/useDictation.ts
|
|
1134
|
+
import { useCallback as useCallback3, useState as useState4 } from "react";
|
|
1135
|
+
|
|
1136
|
+
// src/voice/useRecorder.ts
|
|
1137
|
+
import { useState as useState2, useRef as useRef3, useCallback as useCallback2 } from "react";
|
|
1138
|
+
|
|
1139
|
+
// src/voice/makeRecorder.ts
|
|
1140
|
+
async function makeRecorder(stream, onChunk, opts) {
|
|
1141
|
+
const timeSlice = opts?.timeSlice;
|
|
1142
|
+
const channels = opts?.channels ?? 1;
|
|
1143
|
+
const mod = await import("recordrtc");
|
|
1144
|
+
const RecordRTC = mod.default ?? mod;
|
|
1145
|
+
if (!RecordRTC) {
|
|
1146
|
+
throw new Error("[makeRecorder] RecordRTC library not available");
|
|
1147
|
+
}
|
|
1148
|
+
const mimeType = "audio/wav";
|
|
1149
|
+
let currentRecorder = null;
|
|
1150
|
+
let loopTimer = null;
|
|
1151
|
+
let isActive = false;
|
|
1152
|
+
const createRecorder = () => {
|
|
1153
|
+
return new RecordRTC(stream, {
|
|
1154
|
+
type: "audio",
|
|
1155
|
+
recorderType: RecordRTC.StereoAudioRecorder,
|
|
1156
|
+
mimeType,
|
|
1157
|
+
numberOfAudioChannels: channels,
|
|
1158
|
+
desiredSampRate: opts?.sampleRate ?? 16e3,
|
|
1159
|
+
disableLogs: true
|
|
1160
|
+
});
|
|
1161
|
+
};
|
|
1162
|
+
const startLoop = async () => {
|
|
1163
|
+
if (!isActive) return;
|
|
1164
|
+
currentRecorder = createRecorder();
|
|
1165
|
+
currentRecorder.startRecording();
|
|
1166
|
+
if (timeSlice && timeSlice > 0) {
|
|
1167
|
+
loopTimer = setTimeout(async () => {
|
|
1168
|
+
if (!currentRecorder || !isActive) return;
|
|
1169
|
+
currentRecorder.stopRecording(() => {
|
|
1170
|
+
if (!isActive) return;
|
|
1171
|
+
const blob = currentRecorder.getBlob();
|
|
1172
|
+
if (blob && blob.size > 0) {
|
|
1173
|
+
onChunk(blob);
|
|
1174
|
+
}
|
|
1175
|
+
if (isActive) {
|
|
1176
|
+
startLoop();
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
}, timeSlice);
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
return {
|
|
1183
|
+
start: () => {
|
|
1184
|
+
isActive = true;
|
|
1185
|
+
startLoop();
|
|
1186
|
+
},
|
|
1187
|
+
stop: () => new Promise((resolve) => {
|
|
1188
|
+
isActive = false;
|
|
1189
|
+
if (loopTimer) {
|
|
1190
|
+
clearTimeout(loopTimer);
|
|
1191
|
+
loopTimer = null;
|
|
1192
|
+
}
|
|
1193
|
+
if (currentRecorder) {
|
|
1194
|
+
currentRecorder.stopRecording(() => {
|
|
1195
|
+
const finalBlob = currentRecorder.getBlob();
|
|
1196
|
+
resolve(finalBlob);
|
|
1197
|
+
});
|
|
1198
|
+
} else {
|
|
1199
|
+
resolve(new Blob([], { type: mimeType }));
|
|
1200
|
+
}
|
|
1201
|
+
}),
|
|
1202
|
+
kind: "recordrtc"
|
|
1203
|
+
};
|
|
1204
|
+
}
|
|
1205
|
+
|
|
1206
|
+
// src/voice/useRecorder.ts
|
|
1207
|
+
var log = {
|
|
1208
|
+
error: (_m, _meta) => {
|
|
1209
|
+
void _m;
|
|
1210
|
+
void _meta;
|
|
1211
|
+
},
|
|
1212
|
+
warn: (_m, _meta) => {
|
|
1213
|
+
void _m;
|
|
1214
|
+
void _meta;
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
function useRecorder(config) {
|
|
1218
|
+
const {
|
|
1219
|
+
onChunk,
|
|
1220
|
+
onError,
|
|
1221
|
+
timeSlice = 3e3,
|
|
1222
|
+
sampleRate = 16e3,
|
|
1223
|
+
channels = 1,
|
|
1224
|
+
externalStream = null,
|
|
1225
|
+
deviceId = null
|
|
1226
|
+
} = config;
|
|
1227
|
+
const [isRecording, setIsRecording] = useState2(false);
|
|
1228
|
+
const [recordingTime, setRecordingTime] = useState2(0);
|
|
1229
|
+
const [fullAudioBlob, setFullAudioBlob] = useState2(null);
|
|
1230
|
+
const [fullAudioUrl, setFullAudioUrl] = useState2(null);
|
|
1231
|
+
const [currentStream, setCurrentStream] = useState2(null);
|
|
1232
|
+
const recorderRef = useRef3(null);
|
|
1233
|
+
const continuousRecorderRef = useRef3(null);
|
|
1234
|
+
const currentStreamRef = useRef3(null);
|
|
1235
|
+
const recordingTimerRef = useRef3(null);
|
|
1236
|
+
const fullAudioUrlRef = useRef3(null);
|
|
1237
|
+
const chunkNumberRef = useRef3(0);
|
|
1238
|
+
const startRecording = useCallback2(async () => {
|
|
1239
|
+
try {
|
|
1240
|
+
chunkNumberRef.current = 0;
|
|
1241
|
+
setRecordingTime(0);
|
|
1242
|
+
setFullAudioBlob(null);
|
|
1243
|
+
if (fullAudioUrlRef.current) {
|
|
1244
|
+
URL.revokeObjectURL(fullAudioUrlRef.current);
|
|
1245
|
+
fullAudioUrlRef.current = null;
|
|
1246
|
+
setFullAudioUrl(null);
|
|
1247
|
+
}
|
|
1248
|
+
let stream;
|
|
1249
|
+
if (externalStream) {
|
|
1250
|
+
stream = externalStream;
|
|
1251
|
+
} else {
|
|
1252
|
+
try {
|
|
1253
|
+
const timeoutMs = 15e3;
|
|
1254
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1255
|
+
setTimeout(() => {
|
|
1256
|
+
reject(new Error(
|
|
1257
|
+
"Microphone permission timeout (15s). Check: 1) macOS System Preferences \u2192 Privacy \u2192 Microphone has your browser enabled, 2) Restart browser after granting permission"
|
|
1258
|
+
));
|
|
1259
|
+
}, timeoutMs);
|
|
1260
|
+
});
|
|
1261
|
+
const audioConstraints = deviceId ? { deviceId: { exact: deviceId } } : true;
|
|
1262
|
+
stream = await Promise.race([
|
|
1263
|
+
navigator.mediaDevices.getUserMedia({ audio: audioConstraints }),
|
|
1264
|
+
timeoutPromise
|
|
1265
|
+
]);
|
|
1266
|
+
} catch (micError) {
|
|
1267
|
+
log.error("Microphone access failed", { error: String(micError) });
|
|
1268
|
+
throw micError;
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
currentStreamRef.current = stream;
|
|
1272
|
+
setCurrentStream(stream);
|
|
1273
|
+
const chunkedRecorder = await makeRecorder(
|
|
1274
|
+
stream,
|
|
1275
|
+
async (blob) => {
|
|
1276
|
+
const chunkNumber = chunkNumberRef.current++;
|
|
1277
|
+
await onChunk(blob, chunkNumber);
|
|
1278
|
+
},
|
|
1279
|
+
{
|
|
1280
|
+
timeSlice,
|
|
1281
|
+
sampleRate,
|
|
1282
|
+
channels
|
|
1283
|
+
}
|
|
1284
|
+
);
|
|
1285
|
+
recorderRef.current = chunkedRecorder;
|
|
1286
|
+
chunkedRecorder.start();
|
|
1287
|
+
const continuousRecorder = await makeRecorder(
|
|
1288
|
+
stream,
|
|
1289
|
+
() => {
|
|
1290
|
+
},
|
|
1291
|
+
// Empty callback - blob comes from .stop() return value
|
|
1292
|
+
{
|
|
1293
|
+
// NO timeSlice = records continuously until stop()
|
|
1294
|
+
sampleRate,
|
|
1295
|
+
channels
|
|
1296
|
+
}
|
|
1297
|
+
);
|
|
1298
|
+
continuousRecorderRef.current = continuousRecorder;
|
|
1299
|
+
continuousRecorder.start();
|
|
1300
|
+
setIsRecording(true);
|
|
1301
|
+
recordingTimerRef.current = setInterval(() => {
|
|
1302
|
+
setRecordingTime((prev) => prev + 1);
|
|
1303
|
+
}, 1e3);
|
|
1304
|
+
} catch (err) {
|
|
1305
|
+
const errorMessage = err instanceof Error ? err.message : "No se pudo acceder al micr\xF3fono. Por favor, verifica los permisos.";
|
|
1306
|
+
log.error("Start failed", { error: String(err) });
|
|
1307
|
+
if (onError) {
|
|
1308
|
+
onError(errorMessage);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
}, [onChunk, onError, timeSlice, sampleRate, channels, externalStream, deviceId]);
|
|
1312
|
+
const stopRecording = useCallback2(async () => {
|
|
1313
|
+
try {
|
|
1314
|
+
if (recordingTimerRef.current) {
|
|
1315
|
+
clearInterval(recordingTimerRef.current);
|
|
1316
|
+
recordingTimerRef.current = null;
|
|
1317
|
+
}
|
|
1318
|
+
setIsRecording(false);
|
|
1319
|
+
if (currentStreamRef.current) {
|
|
1320
|
+
currentStreamRef.current.getTracks().forEach((track) => {
|
|
1321
|
+
track.stop();
|
|
1322
|
+
});
|
|
1323
|
+
currentStreamRef.current = null;
|
|
1324
|
+
setCurrentStream(null);
|
|
1325
|
+
}
|
|
1326
|
+
let fullBlob = null;
|
|
1327
|
+
if (continuousRecorderRef.current) {
|
|
1328
|
+
try {
|
|
1329
|
+
fullBlob = await continuousRecorderRef.current.stop();
|
|
1330
|
+
if (fullBlob && fullBlob.size > 0) {
|
|
1331
|
+
if (fullAudioUrlRef.current) {
|
|
1332
|
+
URL.revokeObjectURL(fullAudioUrlRef.current);
|
|
1333
|
+
}
|
|
1334
|
+
const audioUrl = URL.createObjectURL(fullBlob);
|
|
1335
|
+
fullAudioUrlRef.current = audioUrl;
|
|
1336
|
+
setFullAudioUrl(audioUrl);
|
|
1337
|
+
setFullAudioBlob(fullBlob);
|
|
1338
|
+
}
|
|
1339
|
+
} catch (err) {
|
|
1340
|
+
log.warn("Continuous recorder stop error (non-critical)", { error: String(err) });
|
|
1341
|
+
}
|
|
1342
|
+
continuousRecorderRef.current = null;
|
|
1343
|
+
}
|
|
1344
|
+
if (recorderRef.current) {
|
|
1345
|
+
try {
|
|
1346
|
+
const lastChunk = await recorderRef.current.stop();
|
|
1347
|
+
if (lastChunk && lastChunk.size > 0) {
|
|
1348
|
+
const finalChunkNumber = chunkNumberRef.current++;
|
|
1349
|
+
try {
|
|
1350
|
+
const result = onChunk(lastChunk, finalChunkNumber);
|
|
1351
|
+
if (result instanceof Promise) {
|
|
1352
|
+
result.catch((err) => {
|
|
1353
|
+
log.error("Final chunk processing failed", { error: String(err) });
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
} catch (err) {
|
|
1357
|
+
log.error("Final chunk processing failed", { error: String(err) });
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
} catch (err) {
|
|
1361
|
+
log.warn("Chunked recorder stop error (non-critical)", { error: String(err) });
|
|
1362
|
+
}
|
|
1363
|
+
recorderRef.current = null;
|
|
1364
|
+
}
|
|
1365
|
+
return fullBlob;
|
|
1366
|
+
} catch (err) {
|
|
1367
|
+
log.error("Stop failed", { error: String(err) });
|
|
1368
|
+
if (currentStreamRef.current) {
|
|
1369
|
+
currentStreamRef.current.getTracks().forEach((track) => track.stop());
|
|
1370
|
+
currentStreamRef.current = null;
|
|
1371
|
+
setCurrentStream(null);
|
|
1372
|
+
}
|
|
1373
|
+
setIsRecording(false);
|
|
1374
|
+
if (onError) {
|
|
1375
|
+
onError(err instanceof Error ? err.message : "Error al detener grabaci\xF3n");
|
|
1376
|
+
}
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
}, [onChunk, onError]);
|
|
1380
|
+
return {
|
|
1381
|
+
isRecording,
|
|
1382
|
+
recordingTime,
|
|
1383
|
+
currentStream,
|
|
1384
|
+
fullAudioBlob,
|
|
1385
|
+
fullAudioUrl,
|
|
1386
|
+
startRecording,
|
|
1387
|
+
stopRecording
|
|
1388
|
+
};
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
// src/voice/useAudioAnalysis.ts
|
|
1392
|
+
import { useState as useState3, useRef as useRef4, useEffect as useEffect4 } from "react";
|
|
1393
|
+
var AUDIO_CONFIG = { SILENCE_THRESHOLD: 2, AUDIO_GAIN: 2.5 };
|
|
1394
|
+
function frequencyDataToBands(data, bandCount, gain) {
|
|
1395
|
+
if (bandCount <= 0 || data.length === 0) return new Array(Math.max(0, bandCount)).fill(0);
|
|
1396
|
+
const usable = Math.floor(data.length * 0.75) || data.length;
|
|
1397
|
+
const sliceSize = Math.max(1, Math.floor(usable / bandCount));
|
|
1398
|
+
const bands = new Array(bandCount);
|
|
1399
|
+
for (let b = 0; b < bandCount; b++) {
|
|
1400
|
+
const start = b * sliceSize;
|
|
1401
|
+
let sum = 0;
|
|
1402
|
+
let n = 0;
|
|
1403
|
+
for (let i = start; i < start + sliceSize && i < usable; i++) {
|
|
1404
|
+
sum += data[i];
|
|
1405
|
+
n++;
|
|
1406
|
+
}
|
|
1407
|
+
const avg = n ? sum / n : 0;
|
|
1408
|
+
const scaled = avg / 255 * gain;
|
|
1409
|
+
bands[b] = scaled > 1 ? 1 : scaled < 0 ? 0 : scaled;
|
|
1410
|
+
}
|
|
1411
|
+
return bands;
|
|
1412
|
+
}
|
|
1413
|
+
function useAudioAnalysis(stream, config) {
|
|
1414
|
+
const {
|
|
1415
|
+
silenceThreshold = AUDIO_CONFIG.SILENCE_THRESHOLD,
|
|
1416
|
+
gain = AUDIO_CONFIG.AUDIO_GAIN,
|
|
1417
|
+
isActive,
|
|
1418
|
+
bandCount = 24
|
|
1419
|
+
} = config;
|
|
1420
|
+
const [audioLevel, setAudioLevel] = useState3(0);
|
|
1421
|
+
const [bands, setBands] = useState3([]);
|
|
1422
|
+
const analyserRef = useRef4(null);
|
|
1423
|
+
const audioContextRef = useRef4(null);
|
|
1424
|
+
const animationFrameRef = useRef4(null);
|
|
1425
|
+
const isSilent = audioLevel < silenceThreshold;
|
|
1426
|
+
useEffect4(() => {
|
|
1427
|
+
if (!stream || !isActive) {
|
|
1428
|
+
setAudioLevel(0);
|
|
1429
|
+
setBands([]);
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const audioContext = new AudioContext();
|
|
1433
|
+
const analyser = audioContext.createAnalyser();
|
|
1434
|
+
const gainNode = audioContext.createGain();
|
|
1435
|
+
const source = audioContext.createMediaStreamSource(stream);
|
|
1436
|
+
gainNode.gain.value = gain;
|
|
1437
|
+
analyser.fftSize = 256;
|
|
1438
|
+
analyser.smoothingTimeConstant = 0.8;
|
|
1439
|
+
source.connect(gainNode);
|
|
1440
|
+
gainNode.connect(analyser);
|
|
1441
|
+
audioContextRef.current = audioContext;
|
|
1442
|
+
analyserRef.current = analyser;
|
|
1443
|
+
const dataArray = new Uint8Array(analyser.frequencyBinCount);
|
|
1444
|
+
const updateLevel = () => {
|
|
1445
|
+
if (!analyserRef.current) return;
|
|
1446
|
+
analyserRef.current.getByteFrequencyData(dataArray);
|
|
1447
|
+
const average = dataArray.reduce((a, b) => a + b, 0) / dataArray.length;
|
|
1448
|
+
setAudioLevel(average);
|
|
1449
|
+
setBands(frequencyDataToBands(dataArray, bandCount, gain));
|
|
1450
|
+
animationFrameRef.current = requestAnimationFrame(updateLevel);
|
|
1451
|
+
};
|
|
1452
|
+
updateLevel();
|
|
1453
|
+
return () => {
|
|
1454
|
+
if (animationFrameRef.current) {
|
|
1455
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
1456
|
+
}
|
|
1457
|
+
if (audioContextRef.current) {
|
|
1458
|
+
audioContextRef.current.close();
|
|
1459
|
+
}
|
|
1460
|
+
};
|
|
1461
|
+
}, [stream, isActive, gain, silenceThreshold, bandCount]);
|
|
1462
|
+
return { audioLevel, isSilent, bands };
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/voice/useDictation.ts
|
|
1466
|
+
function useDictation(adapter, opts = {}) {
|
|
1467
|
+
const { timeSliceMs = 3e4, deviceId = null, onTranscriptUpdate, onError } = opts;
|
|
1468
|
+
const [liveTranscript, setLiveTranscript] = useState4("");
|
|
1469
|
+
const [isTranscribing, setIsTranscribing] = useState4(false);
|
|
1470
|
+
const handleChunk = useCallback3(
|
|
1471
|
+
async (blob, chunkNumber) => {
|
|
1472
|
+
if (!adapter?.transcribe) return;
|
|
1473
|
+
setIsTranscribing(true);
|
|
1474
|
+
try {
|
|
1475
|
+
const { text } = await adapter.transcribe(blob, { index: chunkNumber });
|
|
1476
|
+
if (text) {
|
|
1477
|
+
setLiveTranscript((prev) => {
|
|
1478
|
+
const updated = prev ? `${prev} ${text}` : text;
|
|
1479
|
+
onTranscriptUpdate?.(updated);
|
|
1480
|
+
return updated;
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
} catch (err) {
|
|
1484
|
+
onError?.(err instanceof Error ? err.message : "transcription failed");
|
|
1485
|
+
} finally {
|
|
1486
|
+
setIsTranscribing(false);
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
[adapter, onTranscriptUpdate, onError]
|
|
1490
|
+
);
|
|
1491
|
+
const { isRecording, recordingTime, currentStream, startRecording, stopRecording } = useRecorder({
|
|
1492
|
+
onChunk: handleChunk,
|
|
1493
|
+
onError,
|
|
1494
|
+
timeSlice: timeSliceMs,
|
|
1495
|
+
deviceId
|
|
1496
|
+
});
|
|
1497
|
+
const { audioLevel, isSilent, bands } = useAudioAnalysis(currentStream, {
|
|
1498
|
+
isActive: isRecording
|
|
1499
|
+
});
|
|
1500
|
+
const start = useCallback3(async () => {
|
|
1501
|
+
setLiveTranscript("");
|
|
1502
|
+
await startRecording();
|
|
1503
|
+
}, [startRecording]);
|
|
1504
|
+
const stop = useCallback3(async () => {
|
|
1505
|
+
await stopRecording();
|
|
1506
|
+
}, [stopRecording]);
|
|
1507
|
+
return {
|
|
1508
|
+
isRecording,
|
|
1509
|
+
recordingTime,
|
|
1510
|
+
audioLevel,
|
|
1511
|
+
isSilent,
|
|
1512
|
+
bands,
|
|
1513
|
+
liveTranscript,
|
|
1514
|
+
isTranscribing,
|
|
1515
|
+
startRecording: start,
|
|
1516
|
+
stopRecording: stop
|
|
1517
|
+
};
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
// src/voice/audioArtifact.ts
|
|
1521
|
+
var AUDIO_QUEUE_DEFAULTS = {
|
|
1522
|
+
maxItems: 10,
|
|
1523
|
+
maxBytes: 50 * 1024 * 1024,
|
|
1524
|
+
// 50 MB total queue
|
|
1525
|
+
maxBytesPerItem: 10 * 1024 * 1024
|
|
1526
|
+
// 10 MB per artifact
|
|
1527
|
+
};
|
|
1528
|
+
function makeArtifactId() {
|
|
1529
|
+
return `audio-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
1530
|
+
}
|
|
1531
|
+
function isPending(a) {
|
|
1532
|
+
return a.state !== "transcribed" && a.state !== "archived" && a.state !== "deleted";
|
|
1533
|
+
}
|
|
1534
|
+
function isTerminal(a) {
|
|
1535
|
+
return a.state === "transcribed" || a.state === "archived" || a.state === "deleted";
|
|
1536
|
+
}
|
|
1537
|
+
function artifactLabel(state) {
|
|
1538
|
+
const map = {
|
|
1539
|
+
recording: "Grabando",
|
|
1540
|
+
paused: "En pausa",
|
|
1541
|
+
stopping: "Guardando...",
|
|
1542
|
+
saved: "Guardado",
|
|
1543
|
+
queued: "En cola",
|
|
1544
|
+
uploading: "Subiendo",
|
|
1545
|
+
transcribing: "Transcribiendo",
|
|
1546
|
+
transcribed: "Transcrito",
|
|
1547
|
+
archived: "Enviado",
|
|
1548
|
+
failed: "Fall\xF3",
|
|
1549
|
+
deleted: "Eliminado"
|
|
1550
|
+
};
|
|
1551
|
+
return map[state];
|
|
1552
|
+
}
|
|
1553
|
+
function formatArtifactSize(bytes) {
|
|
1554
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
1555
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
1556
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
1557
|
+
}
|
|
1558
|
+
function formatArtifactDuration(ms) {
|
|
1559
|
+
if (!ms) return "--:--";
|
|
1560
|
+
const s = Math.floor(ms / 1e3);
|
|
1561
|
+
const m = Math.floor(s / 60);
|
|
1562
|
+
return `${String(m).padStart(2, "0")}:${String(s % 60).padStart(2, "0")}`;
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
// src/voice/AudioQueueStore.ts
|
|
1566
|
+
var DEFAULT_DB_NAME = "free-intelligence-audio-queue";
|
|
1567
|
+
var DEFAULT_STORE_NAME = "audio-artifacts";
|
|
1568
|
+
var DB_VERSION = 1;
|
|
1569
|
+
var CREATED_AT_INDEX = "by_createdAt";
|
|
1570
|
+
function unavailable() {
|
|
1571
|
+
return typeof indexedDB === "undefined";
|
|
1572
|
+
}
|
|
1573
|
+
function unavailableError() {
|
|
1574
|
+
return new Error(
|
|
1575
|
+
"AudioQueueStore: IndexedDB is not available (SSR or storage disabled)."
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1578
|
+
var AudioQueueStore = class {
|
|
1579
|
+
constructor(opts = {}) {
|
|
1580
|
+
this.dbPromise = null;
|
|
1581
|
+
this.dbName = opts.dbName ?? DEFAULT_DB_NAME;
|
|
1582
|
+
this.storeName = opts.storeName ?? DEFAULT_STORE_NAME;
|
|
1583
|
+
}
|
|
1584
|
+
open() {
|
|
1585
|
+
if (unavailable()) return Promise.reject(unavailableError());
|
|
1586
|
+
if (!this.dbPromise) {
|
|
1587
|
+
this.dbPromise = new Promise((resolve, reject) => {
|
|
1588
|
+
const req = indexedDB.open(this.dbName, DB_VERSION);
|
|
1589
|
+
req.onupgradeneeded = () => {
|
|
1590
|
+
const db = req.result;
|
|
1591
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
1592
|
+
const store = db.createObjectStore(this.storeName, { keyPath: "id" });
|
|
1593
|
+
store.createIndex(CREATED_AT_INDEX, "createdAt", { unique: false });
|
|
1594
|
+
}
|
|
1595
|
+
};
|
|
1596
|
+
req.onsuccess = () => resolve(req.result);
|
|
1597
|
+
req.onerror = () => reject(req.error ?? new Error("AudioQueueStore: open failed"));
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
return this.dbPromise;
|
|
1601
|
+
}
|
|
1602
|
+
async run(mode, makeRequest) {
|
|
1603
|
+
const db = await this.open();
|
|
1604
|
+
return new Promise((resolve, reject) => {
|
|
1605
|
+
const tx = db.transaction(this.storeName, mode);
|
|
1606
|
+
const req = makeRequest(tx.objectStore(this.storeName));
|
|
1607
|
+
req.onsuccess = () => resolve(req.result);
|
|
1608
|
+
req.onerror = () => reject(req.error ?? new Error("AudioQueueStore: request failed"));
|
|
1609
|
+
});
|
|
1610
|
+
}
|
|
1611
|
+
async list() {
|
|
1612
|
+
return this.run("readonly", (s) => s.getAll());
|
|
1613
|
+
}
|
|
1614
|
+
async get(id) {
|
|
1615
|
+
const r = await this.run(
|
|
1616
|
+
"readonly",
|
|
1617
|
+
(s) => s.get(id)
|
|
1618
|
+
);
|
|
1619
|
+
return r ?? null;
|
|
1620
|
+
}
|
|
1621
|
+
async put(artifact) {
|
|
1622
|
+
await this.run("readwrite", (s) => s.put(artifact));
|
|
1623
|
+
}
|
|
1624
|
+
async updateMeta(id, patch) {
|
|
1625
|
+
const existing = await this.get(id);
|
|
1626
|
+
if (!existing) return;
|
|
1627
|
+
await this.put({
|
|
1628
|
+
...existing,
|
|
1629
|
+
...patch,
|
|
1630
|
+
id,
|
|
1631
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1632
|
+
});
|
|
1633
|
+
}
|
|
1634
|
+
async delete(id) {
|
|
1635
|
+
await this.run("readwrite", (s) => s.delete(id));
|
|
1636
|
+
}
|
|
1637
|
+
async clear() {
|
|
1638
|
+
await this.run("readwrite", (s) => s.clear());
|
|
1639
|
+
}
|
|
1640
|
+
};
|
|
1641
|
+
|
|
1642
|
+
// src/voice/useDurableRecording.ts
|
|
1643
|
+
import { useState as useState5, useRef as useRef5, useCallback as useCallback4, useEffect as useEffect5 } from "react";
|
|
1644
|
+
|
|
1645
|
+
// src/voice/wav.ts
|
|
1646
|
+
function blobToArrayBuffer(blob) {
|
|
1647
|
+
if (typeof blob.arrayBuffer === "function") return blob.arrayBuffer();
|
|
1648
|
+
return new Promise((resolve, reject) => {
|
|
1649
|
+
const reader = new FileReader();
|
|
1650
|
+
reader.onload = () => resolve(reader.result);
|
|
1651
|
+
reader.onerror = () => reject(reader.error ?? new Error("FileReader failed"));
|
|
1652
|
+
reader.readAsArrayBuffer(blob);
|
|
1653
|
+
});
|
|
1654
|
+
}
|
|
1655
|
+
function readFourCC(view, offset) {
|
|
1656
|
+
return String.fromCharCode(
|
|
1657
|
+
view.getUint8(offset),
|
|
1658
|
+
view.getUint8(offset + 1),
|
|
1659
|
+
view.getUint8(offset + 2),
|
|
1660
|
+
view.getUint8(offset + 3)
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
function parseWav(buffer) {
|
|
1664
|
+
const view = new DataView(buffer);
|
|
1665
|
+
if (buffer.byteLength < 44 || readFourCC(view, 0) !== "RIFF" || readFourCC(view, 8) !== "WAVE") {
|
|
1666
|
+
throw new Error("Not a RIFF/WAVE file");
|
|
1667
|
+
}
|
|
1668
|
+
let fmt = null;
|
|
1669
|
+
let data = null;
|
|
1670
|
+
let offset = 12;
|
|
1671
|
+
while (offset + 8 <= buffer.byteLength) {
|
|
1672
|
+
const id = readFourCC(view, offset);
|
|
1673
|
+
const size = view.getUint32(offset + 4, true);
|
|
1674
|
+
const body = offset + 8;
|
|
1675
|
+
if (id === "fmt ") {
|
|
1676
|
+
fmt = {
|
|
1677
|
+
audioFormat: view.getUint16(body, true),
|
|
1678
|
+
numChannels: view.getUint16(body + 2, true),
|
|
1679
|
+
sampleRate: view.getUint32(body + 4, true),
|
|
1680
|
+
bitsPerSample: view.getUint16(body + 14, true)
|
|
1681
|
+
};
|
|
1682
|
+
} else if (id === "data") {
|
|
1683
|
+
const end = Math.min(body + size, buffer.byteLength);
|
|
1684
|
+
data = new Uint8Array(buffer.slice(body, end));
|
|
1685
|
+
}
|
|
1686
|
+
offset = body + size + size % 2;
|
|
1687
|
+
}
|
|
1688
|
+
if (!fmt || !data) throw new Error("WAV missing fmt or data chunk");
|
|
1689
|
+
return { ...fmt, data };
|
|
1690
|
+
}
|
|
1691
|
+
function buildWav(fmt, pcm) {
|
|
1692
|
+
const header = new ArrayBuffer(44);
|
|
1693
|
+
const view = new DataView(header);
|
|
1694
|
+
const byteRate = fmt.sampleRate * fmt.numChannels * fmt.bitsPerSample / 8;
|
|
1695
|
+
const blockAlign = fmt.numChannels * fmt.bitsPerSample / 8;
|
|
1696
|
+
const writeFourCC = (offset, s) => {
|
|
1697
|
+
for (let i = 0; i < 4; i++) view.setUint8(offset + i, s.charCodeAt(i));
|
|
1698
|
+
};
|
|
1699
|
+
writeFourCC(0, "RIFF");
|
|
1700
|
+
view.setUint32(4, 36 + pcm.byteLength, true);
|
|
1701
|
+
writeFourCC(8, "WAVE");
|
|
1702
|
+
writeFourCC(12, "fmt ");
|
|
1703
|
+
view.setUint32(16, 16, true);
|
|
1704
|
+
view.setUint16(20, fmt.audioFormat, true);
|
|
1705
|
+
view.setUint16(22, fmt.numChannels, true);
|
|
1706
|
+
view.setUint32(24, fmt.sampleRate, true);
|
|
1707
|
+
view.setUint32(28, byteRate, true);
|
|
1708
|
+
view.setUint16(32, blockAlign, true);
|
|
1709
|
+
view.setUint16(34, fmt.bitsPerSample, true);
|
|
1710
|
+
writeFourCC(36, "data");
|
|
1711
|
+
view.setUint32(40, pcm.byteLength, true);
|
|
1712
|
+
return new Blob([header, pcm.buffer], { type: "audio/wav" });
|
|
1713
|
+
}
|
|
1714
|
+
async function mergeWavBlobs(blobs) {
|
|
1715
|
+
if (blobs.length === 0) throw new Error("No WAV segments to merge");
|
|
1716
|
+
if (blobs.length === 1) return blobs[0];
|
|
1717
|
+
const parsed = await Promise.all(
|
|
1718
|
+
blobs.map(async (b) => parseWav(await blobToArrayBuffer(b)))
|
|
1719
|
+
);
|
|
1720
|
+
const first = parsed[0];
|
|
1721
|
+
for (const p of parsed.slice(1)) {
|
|
1722
|
+
if (p.audioFormat !== first.audioFormat || p.numChannels !== first.numChannels || p.sampleRate !== first.sampleRate || p.bitsPerSample !== first.bitsPerSample) {
|
|
1723
|
+
throw new Error("WAV segments have mismatched formats");
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
const total = parsed.reduce((s, p) => s + p.data.byteLength, 0);
|
|
1727
|
+
const pcm = new Uint8Array(total);
|
|
1728
|
+
let cursor = 0;
|
|
1729
|
+
for (const p of parsed) {
|
|
1730
|
+
pcm.set(p.data, cursor);
|
|
1731
|
+
cursor += p.data.byteLength;
|
|
1732
|
+
}
|
|
1733
|
+
return buildWav(first, pcm);
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
// src/voice/useDurableRecording.ts
|
|
1737
|
+
var MIC_TIMEOUT_MS = 15e3;
|
|
1738
|
+
async function loadRecordRTC() {
|
|
1739
|
+
const mod = await import("recordrtc");
|
|
1740
|
+
const RTC = mod.default ?? mod.RecordRTC ?? mod;
|
|
1741
|
+
if (!RTC || typeof RTC !== "function") {
|
|
1742
|
+
throw new Error("[useDurableRecording] RecordRTC not available");
|
|
1743
|
+
}
|
|
1744
|
+
return RTC;
|
|
1745
|
+
}
|
|
1746
|
+
function useDurableRecording(opts) {
|
|
1747
|
+
const {
|
|
1748
|
+
store,
|
|
1749
|
+
policy = AUDIO_QUEUE_DEFAULTS,
|
|
1750
|
+
deviceId = null,
|
|
1751
|
+
onSaved,
|
|
1752
|
+
onError
|
|
1753
|
+
} = opts;
|
|
1754
|
+
const [artifact, setArtifact] = useState5(null);
|
|
1755
|
+
const [recordingTime, setRecordingTime] = useState5(0);
|
|
1756
|
+
const [currentStream, setCurrentStream] = useState5(null);
|
|
1757
|
+
const [isAtCapacity, setIsAtCapacity] = useState5(false);
|
|
1758
|
+
const [isStarting, setIsStarting] = useState5(false);
|
|
1759
|
+
const [pausedPreviewBlob, setPausedPreviewBlob] = useState5(null);
|
|
1760
|
+
const recorderRef = useRef5(null);
|
|
1761
|
+
const streamRef = useRef5(null);
|
|
1762
|
+
const timerRef = useRef5(null);
|
|
1763
|
+
const startTimeRef = useRef5(0);
|
|
1764
|
+
const pausedElapsedRef = useRef5(0);
|
|
1765
|
+
const artifactRef = useRef5(null);
|
|
1766
|
+
const segmentsRef = useRef5([]);
|
|
1767
|
+
const rtcCtorRef = useRef5(null);
|
|
1768
|
+
const pauseOpRef = useRef5(Promise.resolve());
|
|
1769
|
+
useEffect5(() => {
|
|
1770
|
+
artifactRef.current = artifact;
|
|
1771
|
+
}, [artifact]);
|
|
1772
|
+
useEffect5(() => {
|
|
1773
|
+
store.list().then((stored) => {
|
|
1774
|
+
const pending = stored.filter(isPending);
|
|
1775
|
+
const totalBytes = pending.reduce((s, a) => s + a.size, 0);
|
|
1776
|
+
setIsAtCapacity(
|
|
1777
|
+
pending.length >= policy.maxItems || totalBytes >= policy.maxBytes
|
|
1778
|
+
);
|
|
1779
|
+
}).catch(() => {
|
|
1780
|
+
});
|
|
1781
|
+
}, [store, policy]);
|
|
1782
|
+
const { audioLevel, isSilent, bands } = useAudioAnalysis(currentStream, {
|
|
1783
|
+
isActive: artifact?.state === "recording"
|
|
1784
|
+
});
|
|
1785
|
+
const stopTimer = useCallback4(() => {
|
|
1786
|
+
if (timerRef.current) {
|
|
1787
|
+
clearInterval(timerRef.current);
|
|
1788
|
+
timerRef.current = null;
|
|
1789
|
+
}
|
|
1790
|
+
}, []);
|
|
1791
|
+
const releaseStream = useCallback4(() => {
|
|
1792
|
+
if (streamRef.current) {
|
|
1793
|
+
streamRef.current.getTracks().forEach((t) => t.stop());
|
|
1794
|
+
streamRef.current = null;
|
|
1795
|
+
setCurrentStream(null);
|
|
1796
|
+
}
|
|
1797
|
+
}, []);
|
|
1798
|
+
const updateArtifact = useCallback4(
|
|
1799
|
+
(patch) => {
|
|
1800
|
+
const prev = artifactRef.current;
|
|
1801
|
+
if (!prev) return;
|
|
1802
|
+
const updated = { ...prev, ...patch, updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1803
|
+
artifactRef.current = updated;
|
|
1804
|
+
setArtifact(updated);
|
|
1805
|
+
},
|
|
1806
|
+
[]
|
|
1807
|
+
);
|
|
1808
|
+
const startNewRecorderSegment = useCallback4((stream) => {
|
|
1809
|
+
const RecordRTC = rtcCtorRef.current;
|
|
1810
|
+
if (!RecordRTC) throw new Error("[useDurableRecording] RecordRTC not loaded");
|
|
1811
|
+
const recorder = new RecordRTC(stream, {
|
|
1812
|
+
type: "audio",
|
|
1813
|
+
recorderType: RecordRTC.StereoAudioRecorder,
|
|
1814
|
+
mimeType: "audio/wav",
|
|
1815
|
+
numberOfAudioChannels: 1,
|
|
1816
|
+
desiredSampRate: 16e3,
|
|
1817
|
+
disableLogs: true
|
|
1818
|
+
});
|
|
1819
|
+
recorder.startRecording();
|
|
1820
|
+
return recorder;
|
|
1821
|
+
}, []);
|
|
1822
|
+
const startRecording = useCallback4(async () => {
|
|
1823
|
+
if (artifact?.state === "recording" || artifact?.state === "paused") return;
|
|
1824
|
+
setIsStarting(true);
|
|
1825
|
+
try {
|
|
1826
|
+
const stored = await store.list();
|
|
1827
|
+
const pending = stored.filter(isPending);
|
|
1828
|
+
const totalBytes = pending.reduce((s, a) => s + a.size, 0);
|
|
1829
|
+
if (pending.length >= policy.maxItems || totalBytes >= policy.maxBytes) {
|
|
1830
|
+
setIsAtCapacity(true);
|
|
1831
|
+
onError?.(
|
|
1832
|
+
`Cola llena (m\xE1ximo ${policy.maxItems} audios o ${Math.round(policy.maxBytes / 1024 / 1024)} MB). Transcribe o elimina audios antes de grabar.`
|
|
1833
|
+
);
|
|
1834
|
+
return;
|
|
1835
|
+
}
|
|
1836
|
+
const timeoutPromise = new Promise(
|
|
1837
|
+
(_, reject) => setTimeout(
|
|
1838
|
+
() => reject(new Error("Permiso de micr\xF3fono expirado (15s).")),
|
|
1839
|
+
MIC_TIMEOUT_MS
|
|
1840
|
+
)
|
|
1841
|
+
);
|
|
1842
|
+
const audioConstraints = deviceId ? { deviceId: { exact: deviceId } } : true;
|
|
1843
|
+
const stream = await Promise.race([
|
|
1844
|
+
navigator.mediaDevices.getUserMedia({ audio: audioConstraints }),
|
|
1845
|
+
timeoutPromise
|
|
1846
|
+
]);
|
|
1847
|
+
streamRef.current = stream;
|
|
1848
|
+
setCurrentStream(stream);
|
|
1849
|
+
rtcCtorRef.current = await loadRecordRTC();
|
|
1850
|
+
segmentsRef.current = [];
|
|
1851
|
+
pauseOpRef.current = Promise.resolve();
|
|
1852
|
+
setPausedPreviewBlob(null);
|
|
1853
|
+
recorderRef.current = startNewRecorderSegment(stream);
|
|
1854
|
+
const now = Date.now();
|
|
1855
|
+
startTimeRef.current = now;
|
|
1856
|
+
pausedElapsedRef.current = 0;
|
|
1857
|
+
setRecordingTime(0);
|
|
1858
|
+
timerRef.current = setInterval(() => {
|
|
1859
|
+
setRecordingTime(
|
|
1860
|
+
Math.floor((Date.now() - startTimeRef.current) / 1e3)
|
|
1861
|
+
);
|
|
1862
|
+
}, 1e3);
|
|
1863
|
+
const newArtifact = {
|
|
1864
|
+
id: makeArtifactId(),
|
|
1865
|
+
mime: "audio/wav",
|
|
1866
|
+
size: 0,
|
|
1867
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1868
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1869
|
+
state: "recording"
|
|
1870
|
+
};
|
|
1871
|
+
setArtifact(newArtifact);
|
|
1872
|
+
artifactRef.current = newArtifact;
|
|
1873
|
+
} catch (err) {
|
|
1874
|
+
releaseStream();
|
|
1875
|
+
onError?.(err instanceof Error ? err.message : "No se pudo iniciar la grabaci\xF3n.");
|
|
1876
|
+
} finally {
|
|
1877
|
+
setIsStarting(false);
|
|
1878
|
+
}
|
|
1879
|
+
}, [artifact, store, policy, deviceId, onError, releaseStream, startNewRecorderSegment]);
|
|
1880
|
+
const pauseRecording = useCallback4(() => {
|
|
1881
|
+
if (artifactRef.current?.state !== "recording") return;
|
|
1882
|
+
stopTimer();
|
|
1883
|
+
pausedElapsedRef.current = Date.now() - startTimeRef.current;
|
|
1884
|
+
updateArtifact({ state: "paused", durationMs: pausedElapsedRef.current });
|
|
1885
|
+
const recorder = recorderRef.current;
|
|
1886
|
+
recorderRef.current = null;
|
|
1887
|
+
pauseOpRef.current = new Promise((resolve) => {
|
|
1888
|
+
if (!recorder) {
|
|
1889
|
+
resolve();
|
|
1890
|
+
return;
|
|
1891
|
+
}
|
|
1892
|
+
recorder.stopRecording(() => {
|
|
1893
|
+
const segment = recorder.getBlob();
|
|
1894
|
+
if (segment && segment.size > 0) segmentsRef.current.push(segment);
|
|
1895
|
+
const totalBytes = segmentsRef.current.reduce((s, b) => s + b.size, 0);
|
|
1896
|
+
if (totalBytes > policy.maxBytesPerItem) {
|
|
1897
|
+
resolve();
|
|
1898
|
+
return;
|
|
1899
|
+
}
|
|
1900
|
+
void mergeWavBlobs(segmentsRef.current).then((preview) => {
|
|
1901
|
+
if (artifactRef.current?.state === "paused") {
|
|
1902
|
+
setPausedPreviewBlob(preview);
|
|
1903
|
+
}
|
|
1904
|
+
}).catch(() => {
|
|
1905
|
+
}).finally(resolve);
|
|
1906
|
+
});
|
|
1907
|
+
});
|
|
1908
|
+
}, [stopTimer, updateArtifact, policy]);
|
|
1909
|
+
const resumeRecording = useCallback4(() => {
|
|
1910
|
+
if (artifactRef.current?.state !== "paused") return;
|
|
1911
|
+
setPausedPreviewBlob(null);
|
|
1912
|
+
startTimeRef.current = Date.now() - pausedElapsedRef.current;
|
|
1913
|
+
timerRef.current = setInterval(() => {
|
|
1914
|
+
setRecordingTime(
|
|
1915
|
+
Math.floor((Date.now() - startTimeRef.current) / 1e3)
|
|
1916
|
+
);
|
|
1917
|
+
}, 1e3);
|
|
1918
|
+
updateArtifact({ state: "recording" });
|
|
1919
|
+
void pauseOpRef.current.then(() => {
|
|
1920
|
+
if (artifactRef.current?.state !== "recording") return;
|
|
1921
|
+
const stream = streamRef.current;
|
|
1922
|
+
if (!stream) return;
|
|
1923
|
+
try {
|
|
1924
|
+
recorderRef.current = startNewRecorderSegment(stream);
|
|
1925
|
+
} catch (err) {
|
|
1926
|
+
updateArtifact({
|
|
1927
|
+
state: "failed",
|
|
1928
|
+
errorMessage: err instanceof Error ? err.message : "No se pudo reanudar la grabaci\xF3n."
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
});
|
|
1932
|
+
}, [updateArtifact, startNewRecorderSegment]);
|
|
1933
|
+
const stopRecording = useCallback4(async () => {
|
|
1934
|
+
const current = artifactRef.current;
|
|
1935
|
+
if (current?.state !== "recording" && current?.state !== "paused") {
|
|
1936
|
+
return null;
|
|
1937
|
+
}
|
|
1938
|
+
stopTimer();
|
|
1939
|
+
const durationMs = current.state === "paused" ? pausedElapsedRef.current : Date.now() - startTimeRef.current;
|
|
1940
|
+
updateArtifact({ state: "stopping" });
|
|
1941
|
+
setPausedPreviewBlob(null);
|
|
1942
|
+
await pauseOpRef.current;
|
|
1943
|
+
const recorder = recorderRef.current;
|
|
1944
|
+
recorderRef.current = null;
|
|
1945
|
+
if (recorder) {
|
|
1946
|
+
await new Promise((resolve) => recorder.stopRecording(resolve));
|
|
1947
|
+
const segment = recorder.getBlob();
|
|
1948
|
+
if (segment && segment.size > 0) segmentsRef.current.push(segment);
|
|
1949
|
+
}
|
|
1950
|
+
releaseStream();
|
|
1951
|
+
const segments = segmentsRef.current;
|
|
1952
|
+
segmentsRef.current = [];
|
|
1953
|
+
let blob = null;
|
|
1954
|
+
if (segments.length > 0) {
|
|
1955
|
+
try {
|
|
1956
|
+
blob = await mergeWavBlobs(segments);
|
|
1957
|
+
} catch {
|
|
1958
|
+
blob = null;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
if (!blob || blob.size === 0) {
|
|
1962
|
+
updateArtifact({ state: "failed", errorMessage: "Grabaci\xF3n vac\xEDa." });
|
|
1963
|
+
return null;
|
|
1964
|
+
}
|
|
1965
|
+
if (blob.size > policy.maxBytesPerItem) {
|
|
1966
|
+
updateArtifact({
|
|
1967
|
+
state: "failed",
|
|
1968
|
+
errorMessage: `Audio demasiado grande (${Math.round(blob.size / 1024 / 1024)} MB, m\xE1ximo ${Math.round(policy.maxBytesPerItem / 1024 / 1024)} MB).`
|
|
1969
|
+
});
|
|
1970
|
+
return null;
|
|
1971
|
+
}
|
|
1972
|
+
const finalArtifact = {
|
|
1973
|
+
...current,
|
|
1974
|
+
size: blob.size,
|
|
1975
|
+
durationMs,
|
|
1976
|
+
state: "queued",
|
|
1977
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1978
|
+
};
|
|
1979
|
+
updateArtifact({
|
|
1980
|
+
size: blob.size,
|
|
1981
|
+
durationMs,
|
|
1982
|
+
state: "queued"
|
|
1983
|
+
});
|
|
1984
|
+
try {
|
|
1985
|
+
await store.put({ ...finalArtifact, blob });
|
|
1986
|
+
onSaved?.(finalArtifact);
|
|
1987
|
+
setIsAtCapacity(false);
|
|
1988
|
+
return finalArtifact;
|
|
1989
|
+
} catch (err) {
|
|
1990
|
+
const msg = err instanceof Error ? err.message : "Error al guardar audio.";
|
|
1991
|
+
updateArtifact({ state: "failed", errorMessage: msg });
|
|
1992
|
+
onError?.(msg);
|
|
1993
|
+
return null;
|
|
1994
|
+
}
|
|
1995
|
+
}, [store, policy, releaseStream, stopTimer, updateArtifact, onSaved, onError]);
|
|
1996
|
+
const cancelRecording = useCallback4(() => {
|
|
1997
|
+
stopTimer();
|
|
1998
|
+
releaseStream();
|
|
1999
|
+
if (recorderRef.current) {
|
|
2000
|
+
try {
|
|
2001
|
+
recorderRef.current.stopRecording(() => {
|
|
2002
|
+
});
|
|
2003
|
+
} catch {
|
|
2004
|
+
}
|
|
2005
|
+
recorderRef.current = null;
|
|
2006
|
+
}
|
|
2007
|
+
segmentsRef.current = [];
|
|
2008
|
+
setPausedPreviewBlob(null);
|
|
2009
|
+
setArtifact(null);
|
|
2010
|
+
artifactRef.current = null;
|
|
2011
|
+
setRecordingTime(0);
|
|
2012
|
+
}, [stopTimer, releaseStream]);
|
|
2013
|
+
return {
|
|
2014
|
+
artifact,
|
|
2015
|
+
recordingTime,
|
|
2016
|
+
pausedPreviewBlob,
|
|
2017
|
+
bands,
|
|
2018
|
+
audioLevel,
|
|
2019
|
+
isSilent,
|
|
2020
|
+
isStarting,
|
|
2021
|
+
startRecording,
|
|
2022
|
+
pauseRecording,
|
|
2023
|
+
resumeRecording,
|
|
2024
|
+
stopRecording,
|
|
2025
|
+
cancelRecording,
|
|
2026
|
+
isAtCapacity
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
|
|
2030
|
+
// src/voice/useAudioQueue.ts
|
|
2031
|
+
import { useState as useState6, useEffect as useEffect6, useCallback as useCallback5 } from "react";
|
|
2032
|
+
function useAudioQueue(opts) {
|
|
2033
|
+
const { store, adapter, onTranscribed, onError } = opts;
|
|
2034
|
+
const [artifacts, setArtifacts] = useState6([]);
|
|
2035
|
+
const [isLoading, setIsLoading] = useState6(true);
|
|
2036
|
+
const loadFromStore = useCallback5(async () => {
|
|
2037
|
+
try {
|
|
2038
|
+
const stored = await store.list();
|
|
2039
|
+
const metas = stored.filter((a) => a.state !== "deleted").map(({ blob: _blob, ...meta }) => meta).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
2040
|
+
setArtifacts(metas);
|
|
2041
|
+
} catch {
|
|
2042
|
+
}
|
|
2043
|
+
setIsLoading(false);
|
|
2044
|
+
}, [store]);
|
|
2045
|
+
useEffect6(() => {
|
|
2046
|
+
loadFromStore();
|
|
2047
|
+
}, [loadFromStore]);
|
|
2048
|
+
const patchLocal = useCallback5(
|
|
2049
|
+
(id, patch) => {
|
|
2050
|
+
setArtifacts(
|
|
2051
|
+
(prev) => prev.map(
|
|
2052
|
+
(a) => a.id === id ? { ...a, ...patch, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } : a
|
|
2053
|
+
)
|
|
2054
|
+
);
|
|
2055
|
+
},
|
|
2056
|
+
[]
|
|
2057
|
+
);
|
|
2058
|
+
const doTranscribe = useCallback5(
|
|
2059
|
+
async (id) => {
|
|
2060
|
+
if (!adapter?.transcribe) {
|
|
2061
|
+
onError?.(id, "Adaptador de voz sin capacidad de transcripci\xF3n.");
|
|
2062
|
+
return;
|
|
2063
|
+
}
|
|
2064
|
+
patchLocal(id, { state: "transcribing", errorMessage: void 0 });
|
|
2065
|
+
await store.updateMeta(id, { state: "transcribing", errorMessage: void 0 });
|
|
2066
|
+
const stored = await store.get(id);
|
|
2067
|
+
if (!stored) {
|
|
2068
|
+
patchLocal(id, { state: "failed", errorMessage: "Artefacto no encontrado." });
|
|
2069
|
+
onError?.(id, "Artefacto no encontrado.");
|
|
2070
|
+
return;
|
|
2071
|
+
}
|
|
2072
|
+
patchLocal(id, { state: "uploading" });
|
|
2073
|
+
await store.updateMeta(id, { state: "uploading" });
|
|
2074
|
+
try {
|
|
2075
|
+
const { text } = await adapter.transcribe(stored.blob);
|
|
2076
|
+
patchLocal(id, { state: "transcribed", transcript: text });
|
|
2077
|
+
await store.updateMeta(id, { state: "transcribed", transcript: text });
|
|
2078
|
+
onTranscribed?.(id, text);
|
|
2079
|
+
} catch (err) {
|
|
2080
|
+
const msg = err instanceof Error ? err.message : "Transcripci\xF3n fallida.";
|
|
2081
|
+
patchLocal(id, { state: "failed", errorMessage: msg });
|
|
2082
|
+
await store.updateMeta(id, { state: "failed", errorMessage: msg });
|
|
2083
|
+
onError?.(id, msg);
|
|
2084
|
+
}
|
|
2085
|
+
},
|
|
2086
|
+
[adapter, store, patchLocal, onTranscribed, onError]
|
|
2087
|
+
);
|
|
2088
|
+
const transcribeArtifact = useCallback5(
|
|
2089
|
+
async (id) => {
|
|
2090
|
+
const a = artifacts.find((x) => x.id === id);
|
|
2091
|
+
if (!a || a.state !== "queued" && a.state !== "saved") return;
|
|
2092
|
+
await doTranscribe(id);
|
|
2093
|
+
},
|
|
2094
|
+
[artifacts, doTranscribe]
|
|
2095
|
+
);
|
|
2096
|
+
const retryTranscription = useCallback5(
|
|
2097
|
+
async (id) => {
|
|
2098
|
+
const a = artifacts.find((x) => x.id === id);
|
|
2099
|
+
if (!a || a.state !== "failed") return;
|
|
2100
|
+
await doTranscribe(id);
|
|
2101
|
+
},
|
|
2102
|
+
[artifacts, doTranscribe]
|
|
2103
|
+
);
|
|
2104
|
+
const getPlaybackUrl = useCallback5(
|
|
2105
|
+
async (id) => {
|
|
2106
|
+
const stored = await store.get(id);
|
|
2107
|
+
if (!stored?.blob || stored.blob.size === 0) return null;
|
|
2108
|
+
return URL.createObjectURL(stored.blob);
|
|
2109
|
+
},
|
|
2110
|
+
[store]
|
|
2111
|
+
);
|
|
2112
|
+
const deleteArtifact = useCallback5(
|
|
2113
|
+
async (id) => {
|
|
2114
|
+
await store.delete(id);
|
|
2115
|
+
setArtifacts((prev) => prev.filter((a) => a.id !== id));
|
|
2116
|
+
},
|
|
2117
|
+
[store]
|
|
2118
|
+
);
|
|
2119
|
+
const archiveArtifact = useCallback5(
|
|
2120
|
+
async (id) => {
|
|
2121
|
+
const a = artifacts.find((x) => x.id === id);
|
|
2122
|
+
if (!a || a.state !== "transcribed") return;
|
|
2123
|
+
patchLocal(id, { state: "archived" });
|
|
2124
|
+
await store.updateMeta(id, { state: "archived" });
|
|
2125
|
+
},
|
|
2126
|
+
[artifacts, store, patchLocal]
|
|
2127
|
+
);
|
|
2128
|
+
const clearTranscribed = useCallback5(async () => {
|
|
2129
|
+
const used = (a) => a.state === "transcribed" || a.state === "archived";
|
|
2130
|
+
const toDelete = artifacts.filter(used);
|
|
2131
|
+
await Promise.all(toDelete.map((a) => store.delete(a.id)));
|
|
2132
|
+
setArtifacts((prev) => prev.filter((a) => !used(a)));
|
|
2133
|
+
}, [artifacts, store]);
|
|
2134
|
+
const reload = useCallback5(async () => {
|
|
2135
|
+
setIsLoading(true);
|
|
2136
|
+
await loadFromStore();
|
|
2137
|
+
}, [loadFromStore]);
|
|
2138
|
+
const totalBytes = artifacts.filter(isPending).reduce((s, a) => s + a.size, 0);
|
|
2139
|
+
return {
|
|
2140
|
+
artifacts,
|
|
2141
|
+
totalBytes,
|
|
2142
|
+
isLoading,
|
|
2143
|
+
transcribeArtifact,
|
|
2144
|
+
retryTranscription,
|
|
2145
|
+
getPlaybackUrl,
|
|
2146
|
+
deleteArtifact,
|
|
2147
|
+
archiveArtifact,
|
|
2148
|
+
clearTranscribed,
|
|
2149
|
+
reload
|
|
2150
|
+
};
|
|
2151
|
+
}
|
|
2152
|
+
|
|
2153
|
+
// src/voice/AudioQueuePanel.tsx
|
|
2154
|
+
import { useEffect as useEffect7, useState as useState8 } from "react";
|
|
2155
|
+
import { Loader2 as Loader29, Trash2 as Trash22, Info } from "lucide-react";
|
|
2156
|
+
|
|
2157
|
+
// src/voice/AudioQueueItem.tsx
|
|
2158
|
+
import { useState as useState7, useCallback as useCallback6 } from "react";
|
|
2159
|
+
import {
|
|
2160
|
+
Mic as Mic3,
|
|
2161
|
+
PauseCircle,
|
|
2162
|
+
CheckCircle2,
|
|
2163
|
+
CheckCheck,
|
|
2164
|
+
AlertCircle as AlertCircle3,
|
|
2165
|
+
Loader2 as Loader28,
|
|
2166
|
+
Play as Play4,
|
|
2167
|
+
RotateCcw as RotateCcw2,
|
|
2168
|
+
Trash2,
|
|
2169
|
+
FileAudio
|
|
2170
|
+
} from "lucide-react";
|
|
2171
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2172
|
+
function StateIcon({ state }) {
|
|
2173
|
+
const base = "w-4 h-4 shrink-0";
|
|
2174
|
+
switch (state) {
|
|
2175
|
+
case "recording":
|
|
2176
|
+
return /* @__PURE__ */ jsx11(Mic3, { className: `${base} text-red-400 animate-pulse` });
|
|
2177
|
+
case "paused":
|
|
2178
|
+
return /* @__PURE__ */ jsx11(PauseCircle, { className: `${base} text-yellow-400` });
|
|
2179
|
+
case "stopping":
|
|
2180
|
+
return /* @__PURE__ */ jsx11(Loader28, { className: `${base} text-amber-400 animate-spin` });
|
|
2181
|
+
case "transcribed":
|
|
2182
|
+
return /* @__PURE__ */ jsx11(CheckCircle2, { className: `${base} text-green-400` });
|
|
2183
|
+
case "failed":
|
|
2184
|
+
return /* @__PURE__ */ jsx11(AlertCircle3, { className: `${base} text-red-400` });
|
|
2185
|
+
case "transcribing":
|
|
2186
|
+
case "uploading":
|
|
2187
|
+
return /* @__PURE__ */ jsx11(Loader28, { className: `${base} text-blue-400 animate-spin` });
|
|
2188
|
+
default:
|
|
2189
|
+
return /* @__PURE__ */ jsx11(FileAudio, { className: `${base} text-gray-400` });
|
|
2190
|
+
}
|
|
2191
|
+
}
|
|
2192
|
+
function AudioQueueItem({
|
|
2193
|
+
artifact,
|
|
2194
|
+
onTranscribe,
|
|
2195
|
+
onRetry,
|
|
2196
|
+
onDelete,
|
|
2197
|
+
onArchive,
|
|
2198
|
+
onGetPlaybackUrl,
|
|
2199
|
+
className = ""
|
|
2200
|
+
}) {
|
|
2201
|
+
const [playing, setPlaying] = useState7(false);
|
|
2202
|
+
const [audioEl, setAudioEl] = useState7(null);
|
|
2203
|
+
const handlePlay = useCallback6(async () => {
|
|
2204
|
+
if (!onGetPlaybackUrl) return;
|
|
2205
|
+
if (playing && audioEl) {
|
|
2206
|
+
audioEl.pause();
|
|
2207
|
+
setPlaying(false);
|
|
2208
|
+
return;
|
|
2209
|
+
}
|
|
2210
|
+
const url = await onGetPlaybackUrl(artifact.id);
|
|
2211
|
+
if (!url) return;
|
|
2212
|
+
const el = new Audio(url);
|
|
2213
|
+
setAudioEl(el);
|
|
2214
|
+
setPlaying(true);
|
|
2215
|
+
el.play().catch(() => setPlaying(false));
|
|
2216
|
+
el.addEventListener("ended", () => {
|
|
2217
|
+
setPlaying(false);
|
|
2218
|
+
URL.revokeObjectURL(url);
|
|
2219
|
+
});
|
|
2220
|
+
el.addEventListener("error", () => {
|
|
2221
|
+
setPlaying(false);
|
|
2222
|
+
URL.revokeObjectURL(url);
|
|
2223
|
+
});
|
|
2224
|
+
}, [artifact.id, onGetPlaybackUrl, playing, audioEl]);
|
|
2225
|
+
const canTranscribe = artifact.state === "queued" || artifact.state === "saved";
|
|
2226
|
+
const canRetry = artifact.state === "failed";
|
|
2227
|
+
const canPlay = !!onGetPlaybackUrl && artifact.size > 0 && artifact.state !== "recording" && artifact.state !== "paused";
|
|
2228
|
+
const isBusy = artifact.state === "transcribing" || artifact.state === "uploading";
|
|
2229
|
+
return /* @__PURE__ */ jsxs7(
|
|
2230
|
+
"div",
|
|
2231
|
+
{
|
|
2232
|
+
className: `flex items-start gap-3 p-3 rounded-lg bg-white/5 border border-white/10 ${className}`,
|
|
2233
|
+
children: [
|
|
2234
|
+
/* @__PURE__ */ jsx11(StateIcon, { state: artifact.state }),
|
|
2235
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex-1 min-w-0 space-y-0.5", children: [
|
|
2236
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-2 text-xs", children: [
|
|
2237
|
+
/* @__PURE__ */ jsx11("span", { className: "font-medium text-white/80", children: artifactLabel(artifact.state) }),
|
|
2238
|
+
/* @__PURE__ */ jsx11("span", { className: "text-white/40", children: "\xB7" }),
|
|
2239
|
+
/* @__PURE__ */ jsx11("span", { className: "text-white/50", children: formatArtifactDuration(artifact.durationMs) }),
|
|
2240
|
+
/* @__PURE__ */ jsx11("span", { className: "text-white/40", children: "\xB7" }),
|
|
2241
|
+
/* @__PURE__ */ jsx11("span", { className: "text-white/50", children: formatArtifactSize(artifact.size) })
|
|
2242
|
+
] }),
|
|
2243
|
+
artifact.state === "transcribed" && artifact.transcript && /* @__PURE__ */ jsx11("p", { className: "text-xs text-white/60 truncate", children: artifact.transcript }),
|
|
2244
|
+
artifact.state === "failed" && artifact.errorMessage && /* @__PURE__ */ jsx11("p", { className: "text-xs text-red-400/80 truncate", children: artifact.errorMessage }),
|
|
2245
|
+
/* @__PURE__ */ jsx11("p", { className: "text-[10px] text-white/30", children: new Date(artifact.createdAt).toLocaleString("es-MX", {
|
|
2246
|
+
hour: "2-digit",
|
|
2247
|
+
minute: "2-digit",
|
|
2248
|
+
day: "numeric",
|
|
2249
|
+
month: "short"
|
|
2250
|
+
}) })
|
|
2251
|
+
] }),
|
|
2252
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex items-center gap-1 shrink-0", children: [
|
|
2253
|
+
canPlay && /* @__PURE__ */ jsx11(
|
|
2254
|
+
"button",
|
|
2255
|
+
{
|
|
2256
|
+
onClick: handlePlay,
|
|
2257
|
+
disabled: isBusy,
|
|
2258
|
+
className: "p-1.5 rounded-md hover:bg-white/10 text-white/50 hover:text-white/80 transition-colors",
|
|
2259
|
+
"aria-label": playing ? "Pausar" : "Reproducir",
|
|
2260
|
+
children: /* @__PURE__ */ jsx11(Play4, { className: "w-3.5 h-3.5" })
|
|
2261
|
+
}
|
|
2262
|
+
),
|
|
2263
|
+
canTranscribe && onTranscribe && /* @__PURE__ */ jsx11(
|
|
2264
|
+
"button",
|
|
2265
|
+
{
|
|
2266
|
+
onClick: () => onTranscribe(artifact.id),
|
|
2267
|
+
disabled: isBusy,
|
|
2268
|
+
className: "px-2 py-1 rounded-md text-xs bg-blue-500/20 hover:bg-blue-500/30 text-blue-300 transition-colors",
|
|
2269
|
+
children: "Transcribir"
|
|
2270
|
+
}
|
|
2271
|
+
),
|
|
2272
|
+
canRetry && onRetry && /* @__PURE__ */ jsx11(
|
|
2273
|
+
"button",
|
|
2274
|
+
{
|
|
2275
|
+
onClick: () => onRetry(artifact.id),
|
|
2276
|
+
className: "p-1.5 rounded-md hover:bg-white/10 text-yellow-400/70 hover:text-yellow-400 transition-colors",
|
|
2277
|
+
"aria-label": "Reintentar transcripci\xF3n",
|
|
2278
|
+
children: /* @__PURE__ */ jsx11(RotateCcw2, { className: "w-3.5 h-3.5" })
|
|
2279
|
+
}
|
|
2280
|
+
),
|
|
2281
|
+
artifact.state === "transcribed" && onArchive && /* @__PURE__ */ jsx11(
|
|
2282
|
+
"button",
|
|
2283
|
+
{
|
|
2284
|
+
onClick: () => onArchive(artifact.id),
|
|
2285
|
+
className: "fi-audio-item-archive p-1.5 rounded-md hover:bg-white/10 text-emerald-400/60 hover:text-emerald-400 transition-colors",
|
|
2286
|
+
"aria-label": "Marcar como enviado al chat",
|
|
2287
|
+
title: "Marcar como enviado al chat",
|
|
2288
|
+
children: /* @__PURE__ */ jsx11(CheckCheck, { className: "w-3.5 h-3.5" })
|
|
2289
|
+
}
|
|
2290
|
+
),
|
|
2291
|
+
onDelete && artifact.state !== "recording" && artifact.state !== "paused" && /* @__PURE__ */ jsx11(
|
|
2292
|
+
"button",
|
|
2293
|
+
{
|
|
2294
|
+
onClick: () => onDelete(artifact.id),
|
|
2295
|
+
disabled: isBusy,
|
|
2296
|
+
className: "p-1.5 rounded-md hover:bg-white/10 text-white/30 hover:text-red-400 transition-colors",
|
|
2297
|
+
"aria-label": "Eliminar audio",
|
|
2298
|
+
children: /* @__PURE__ */ jsx11(Trash2, { className: "w-3.5 h-3.5" })
|
|
2299
|
+
}
|
|
2300
|
+
)
|
|
2301
|
+
] })
|
|
2302
|
+
]
|
|
2303
|
+
}
|
|
2304
|
+
);
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
// src/voice/AudioQueuePanel.tsx
|
|
2308
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
2309
|
+
var DEFAULT_PRIVACY_NOTICE = "Tu audio se guarda localmente hasta que lo transcribas o elimines. No se env\xEDa al servidor hasta que lo solicites.";
|
|
2310
|
+
var DEFAULT_PRIVACY_NOTICE_MS = 35e3;
|
|
2311
|
+
function AudioQueuePanel({
|
|
2312
|
+
queue,
|
|
2313
|
+
className = "",
|
|
2314
|
+
privacyNotice = DEFAULT_PRIVACY_NOTICE,
|
|
2315
|
+
privacyNoticeMs = DEFAULT_PRIVACY_NOTICE_MS,
|
|
2316
|
+
maxVisible = 6,
|
|
2317
|
+
excludeIds = []
|
|
2318
|
+
}) {
|
|
2319
|
+
const {
|
|
2320
|
+
artifacts,
|
|
2321
|
+
isLoading,
|
|
2322
|
+
transcribeArtifact,
|
|
2323
|
+
retryTranscription,
|
|
2324
|
+
deleteArtifact,
|
|
2325
|
+
archiveArtifact,
|
|
2326
|
+
clearTranscribed,
|
|
2327
|
+
getPlaybackUrl
|
|
2328
|
+
} = queue;
|
|
2329
|
+
const [showNotice, setShowNotice] = useState8(true);
|
|
2330
|
+
useEffect7(() => {
|
|
2331
|
+
if (!privacyNoticeMs) return;
|
|
2332
|
+
const t = setTimeout(() => setShowNotice(false), privacyNoticeMs);
|
|
2333
|
+
return () => clearTimeout(t);
|
|
2334
|
+
}, [privacyNoticeMs]);
|
|
2335
|
+
const visible = artifacts.filter(
|
|
2336
|
+
(a) => a.state !== "deleted" && a.state !== "archived" && // used/sent — hidden, kept until cleared
|
|
2337
|
+
!excludeIds.includes(a.id)
|
|
2338
|
+
);
|
|
2339
|
+
const hasTranscribed = visible.some((a) => a.state === "transcribed");
|
|
2340
|
+
const visibleBytes = visible.reduce((s, a) => s + a.size, 0);
|
|
2341
|
+
if (isLoading) {
|
|
2342
|
+
return /* @__PURE__ */ jsx12("div", { className: `flex items-center justify-center p-4 ${className}`, children: /* @__PURE__ */ jsx12(Loader29, { className: "w-4 h-4 text-white/40 animate-spin" }) });
|
|
2343
|
+
}
|
|
2344
|
+
if (visible.length === 0) return null;
|
|
2345
|
+
return /* @__PURE__ */ jsxs8("div", { className: `space-y-2 ${className}`, children: [
|
|
2346
|
+
showNotice && /* @__PURE__ */ jsxs8("div", { className: "fi-audio-queue-notice flex items-start gap-2 px-3 py-2 rounded-lg bg-blue-500/10 border border-blue-500/20", children: [
|
|
2347
|
+
/* @__PURE__ */ jsx12(Info, { className: "w-3.5 h-3.5 text-blue-400 shrink-0 mt-0.5" }),
|
|
2348
|
+
/* @__PURE__ */ jsx12("p", { className: "text-[11px] text-blue-200/70 leading-relaxed", children: privacyNotice })
|
|
2349
|
+
] }),
|
|
2350
|
+
/* @__PURE__ */ jsxs8("div", { className: "flex items-center justify-between px-1", children: [
|
|
2351
|
+
/* @__PURE__ */ jsxs8("span", { className: "text-xs text-white/50", children: [
|
|
2352
|
+
visible.length,
|
|
2353
|
+
" audio",
|
|
2354
|
+
visible.length !== 1 ? "s" : "",
|
|
2355
|
+
" \xB7 ",
|
|
2356
|
+
formatArtifactSize(visibleBytes)
|
|
2357
|
+
] }),
|
|
2358
|
+
hasTranscribed && /* @__PURE__ */ jsxs8(
|
|
2359
|
+
"button",
|
|
2360
|
+
{
|
|
2361
|
+
onClick: clearTranscribed,
|
|
2362
|
+
className: "flex items-center gap-1 text-xs text-white/40 hover:text-white/70 transition-colors",
|
|
2363
|
+
children: [
|
|
2364
|
+
/* @__PURE__ */ jsx12(Trash22, { className: "w-3 h-3" }),
|
|
2365
|
+
"Limpiar transcritos"
|
|
2366
|
+
]
|
|
2367
|
+
}
|
|
2368
|
+
)
|
|
2369
|
+
] }),
|
|
2370
|
+
/* @__PURE__ */ jsx12(
|
|
2371
|
+
"div",
|
|
2372
|
+
{
|
|
2373
|
+
className: "space-y-1.5 overflow-y-auto",
|
|
2374
|
+
style: { maxHeight: `${maxVisible * 68}px` },
|
|
2375
|
+
children: visible.map((artifact) => /* @__PURE__ */ jsx12(
|
|
2376
|
+
AudioQueueItem,
|
|
2377
|
+
{
|
|
2378
|
+
artifact,
|
|
2379
|
+
onTranscribe: transcribeArtifact,
|
|
2380
|
+
onRetry: retryTranscription,
|
|
2381
|
+
onDelete: deleteArtifact,
|
|
2382
|
+
onArchive: archiveArtifact,
|
|
2383
|
+
onGetPlaybackUrl: getPlaybackUrl
|
|
2384
|
+
},
|
|
2385
|
+
artifact.id
|
|
2386
|
+
))
|
|
2387
|
+
}
|
|
2388
|
+
)
|
|
2389
|
+
] });
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
// src/voice/AudioDraftPlayer.tsx
|
|
2393
|
+
import { useState as useState9, useEffect as useEffect8 } from "react";
|
|
2394
|
+
import { Play as Play5, Trash2 as Trash23, Loader2 as Loader210, RotateCcw as RotateCcw3, ArrowUp } from "lucide-react";
|
|
2395
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
2396
|
+
function AudioDraftPlayer({
|
|
2397
|
+
artifact,
|
|
2398
|
+
onGetPlaybackUrl,
|
|
2399
|
+
onPrimary,
|
|
2400
|
+
onDiscard,
|
|
2401
|
+
onRetry,
|
|
2402
|
+
onResume,
|
|
2403
|
+
pausedPreview = null,
|
|
2404
|
+
primaryActionLabel = "Transcribir",
|
|
2405
|
+
className = ""
|
|
2406
|
+
}) {
|
|
2407
|
+
const isPaused = artifact.state === "paused";
|
|
2408
|
+
const isSaving = artifact.state === "stopping";
|
|
2409
|
+
const isBusy = artifact.state === "transcribing" || artifact.state === "uploading";
|
|
2410
|
+
const isFailed = artifact.state === "failed";
|
|
2411
|
+
const hasBlob = artifact.size > 0 && !isSaving && !isPaused;
|
|
2412
|
+
const [playbackUrl, setPlaybackUrl] = useState9(null);
|
|
2413
|
+
useEffect8(() => {
|
|
2414
|
+
if (!onGetPlaybackUrl || !hasBlob) {
|
|
2415
|
+
setPlaybackUrl(null);
|
|
2416
|
+
return;
|
|
2417
|
+
}
|
|
2418
|
+
let cancelled = false;
|
|
2419
|
+
let url = null;
|
|
2420
|
+
void onGetPlaybackUrl(artifact.id).then((resolved) => {
|
|
2421
|
+
if (cancelled) {
|
|
2422
|
+
if (resolved) URL.revokeObjectURL(resolved);
|
|
2423
|
+
return;
|
|
2424
|
+
}
|
|
2425
|
+
url = resolved;
|
|
2426
|
+
setPlaybackUrl(resolved);
|
|
2427
|
+
});
|
|
2428
|
+
return () => {
|
|
2429
|
+
cancelled = true;
|
|
2430
|
+
if (url) URL.revokeObjectURL(url);
|
|
2431
|
+
setPlaybackUrl(null);
|
|
2432
|
+
};
|
|
2433
|
+
}, [artifact.id, hasBlob, onGetPlaybackUrl]);
|
|
2434
|
+
return /* @__PURE__ */ jsxs9(
|
|
2435
|
+
"div",
|
|
2436
|
+
{
|
|
2437
|
+
className: `fi-audio-draft flex items-center gap-3 px-4 py-3 rounded-2xl bg-white/[0.07] border border-white/[0.14] backdrop-blur-xl shadow-lg shadow-black/30 ${className}`,
|
|
2438
|
+
role: "group",
|
|
2439
|
+
"aria-label": "Audio grabado",
|
|
2440
|
+
children: [
|
|
2441
|
+
isPaused && pausedPreview ? (
|
|
2442
|
+
// Paused with the recorded-so-far WAV in hand: play it back through
|
|
2443
|
+
// the SAME primitive the TTS player uses. The pulsing dot keeps
|
|
2444
|
+
// signalling that the recording session is still open.
|
|
2445
|
+
/* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [
|
|
2446
|
+
/* @__PURE__ */ jsx13(
|
|
2447
|
+
"span",
|
|
2448
|
+
{
|
|
2449
|
+
className: "fi-audio-draft-pauseddot shrink-0 w-2.5 h-2.5 rounded-full bg-amber-400 animate-pulse",
|
|
2450
|
+
"aria-hidden": "true"
|
|
2451
|
+
}
|
|
2452
|
+
),
|
|
2453
|
+
/* @__PURE__ */ jsx13(
|
|
2454
|
+
RichAudioPlayer,
|
|
2455
|
+
{
|
|
2456
|
+
source: pausedPreview,
|
|
2457
|
+
className: "fi-audio-draft-player flex items-center gap-1 flex-1 min-w-0",
|
|
2458
|
+
buttonClassName: "p-2 rounded-xl text-white/80 hover:text-white hover:bg-white/10 disabled:opacity-35 disabled:cursor-not-allowed transition-colors",
|
|
2459
|
+
iconClassName: "w-4 h-4",
|
|
2460
|
+
progressClassName: "flex-1 min-w-0 h-1 accent-amber-400 cursor-pointer disabled:cursor-not-allowed"
|
|
2461
|
+
}
|
|
2462
|
+
),
|
|
2463
|
+
/* @__PURE__ */ jsx13("span", { className: "hidden sm:inline text-xs font-medium text-amber-300/80 shrink-0", children: "En pausa" })
|
|
2464
|
+
] })
|
|
2465
|
+
) : isPaused ? (
|
|
2466
|
+
// Paused but the preview WAV is still being spliced (or the consumer
|
|
2467
|
+
// didn't wire one): honest status, never a dead play control.
|
|
2468
|
+
/* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-2.5 flex-1 min-w-0", children: [
|
|
2469
|
+
/* @__PURE__ */ jsx13(
|
|
2470
|
+
"span",
|
|
2471
|
+
{
|
|
2472
|
+
className: "fi-audio-draft-pauseddot shrink-0 w-2.5 h-2.5 rounded-full bg-amber-400 animate-pulse",
|
|
2473
|
+
"aria-hidden": "true"
|
|
2474
|
+
}
|
|
2475
|
+
),
|
|
2476
|
+
/* @__PURE__ */ jsx13("span", { className: "text-sm tabular-nums text-white/80", children: formatArtifactDuration(artifact.durationMs) }),
|
|
2477
|
+
/* @__PURE__ */ jsx13("span", { className: "text-xs font-medium text-amber-300/80", children: "Grabaci\xF3n en pausa" })
|
|
2478
|
+
] })
|
|
2479
|
+
) : /* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-2 flex-1 min-w-0", children: [
|
|
2480
|
+
/* @__PURE__ */ jsx13(
|
|
2481
|
+
RichAudioPlayer,
|
|
2482
|
+
{
|
|
2483
|
+
source: playbackUrl ? { url: playbackUrl } : null,
|
|
2484
|
+
className: "fi-audio-draft-player flex items-center gap-1 flex-1 min-w-0",
|
|
2485
|
+
buttonClassName: "p-2 rounded-xl text-white/80 hover:text-white hover:bg-white/10 disabled:opacity-35 disabled:cursor-not-allowed transition-colors",
|
|
2486
|
+
iconClassName: "w-4 h-4",
|
|
2487
|
+
progressClassName: "flex-1 min-w-0 h-1 accent-emerald-400 cursor-pointer disabled:cursor-not-allowed"
|
|
2488
|
+
}
|
|
2489
|
+
),
|
|
2490
|
+
/* @__PURE__ */ jsxs9("div", { className: "hidden sm:flex items-center gap-1.5 shrink-0 text-xs text-white/45", children: [
|
|
2491
|
+
artifact.size > 0 && /* @__PURE__ */ jsx13("span", { children: formatArtifactSize(artifact.size) }),
|
|
2492
|
+
isSaving && /* @__PURE__ */ jsxs9("span", { className: "inline-flex items-center gap-1 text-amber-400/70", children: [
|
|
2493
|
+
/* @__PURE__ */ jsx13(Loader210, { className: "w-3.5 h-3.5 animate-spin", "aria-hidden": true }),
|
|
2494
|
+
"Guardando\u2026"
|
|
2495
|
+
] }),
|
|
2496
|
+
isBusy && /* @__PURE__ */ jsx13("span", { className: "text-blue-400/70", children: "Transcribiendo\u2026" })
|
|
2497
|
+
] }),
|
|
2498
|
+
isFailed && artifact.errorMessage && /* @__PURE__ */ jsx13("span", { role: "alert", className: "text-xs text-red-400/80 truncate shrink min-w-0", children: artifact.errorMessage })
|
|
2499
|
+
] }),
|
|
2500
|
+
/* @__PURE__ */ jsxs9("div", { className: "flex items-center gap-1 shrink-0", children: [
|
|
2501
|
+
onDiscard && !isBusy && /* @__PURE__ */ jsx13(
|
|
2502
|
+
"button",
|
|
2503
|
+
{
|
|
2504
|
+
type: "button",
|
|
2505
|
+
onClick: () => onDiscard(artifact.id),
|
|
2506
|
+
"aria-label": "Descartar grabaci\xF3n",
|
|
2507
|
+
className: "fi-audio-draft-discard p-2 rounded-xl text-white/35 hover:text-red-400 hover:bg-white/10 transition-colors",
|
|
2508
|
+
children: /* @__PURE__ */ jsx13(Trash23, { className: "w-4 h-4" })
|
|
2509
|
+
}
|
|
2510
|
+
),
|
|
2511
|
+
onResume ? /* @__PURE__ */ jsxs9(
|
|
2512
|
+
"button",
|
|
2513
|
+
{
|
|
2514
|
+
type: "button",
|
|
2515
|
+
onClick: onResume,
|
|
2516
|
+
"aria-label": "Reanudar grabaci\xF3n",
|
|
2517
|
+
className: "fi-audio-draft-resume flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-semibold bg-amber-500/20 hover:bg-amber-500/30 text-amber-300 transition-all active:scale-95",
|
|
2518
|
+
children: [
|
|
2519
|
+
/* @__PURE__ */ jsx13(Play5, { className: "w-3.5 h-3.5 ml-0.5" }),
|
|
2520
|
+
"Reanudar"
|
|
2521
|
+
]
|
|
2522
|
+
}
|
|
2523
|
+
) : isFailed && onRetry ? /* @__PURE__ */ jsx13(
|
|
2524
|
+
"button",
|
|
2525
|
+
{
|
|
2526
|
+
type: "button",
|
|
2527
|
+
onClick: () => onRetry(artifact.id),
|
|
2528
|
+
"aria-label": "Reintentar",
|
|
2529
|
+
className: "fi-audio-draft-retry p-2 rounded-xl text-amber-400/80 hover:text-amber-400 hover:bg-white/10 transition-colors",
|
|
2530
|
+
children: /* @__PURE__ */ jsx13(RotateCcw3, { className: "w-4 h-4" })
|
|
2531
|
+
}
|
|
2532
|
+
) : onPrimary && /* @__PURE__ */ jsxs9(
|
|
2533
|
+
"button",
|
|
2534
|
+
{
|
|
2535
|
+
type: "button",
|
|
2536
|
+
onClick: () => onPrimary(artifact.id),
|
|
2537
|
+
disabled: isSaving || isBusy,
|
|
2538
|
+
className: "fi-audio-draft-primary flex items-center gap-1.5 px-3 py-2 rounded-xl text-xs font-semibold bg-emerald-500/20 hover:bg-emerald-500/30 text-emerald-300 disabled:opacity-40 disabled:cursor-not-allowed transition-all active:scale-95",
|
|
2539
|
+
children: [
|
|
2540
|
+
/* @__PURE__ */ jsx13(ArrowUp, { className: "w-3.5 h-3.5" }),
|
|
2541
|
+
primaryActionLabel
|
|
2542
|
+
]
|
|
2543
|
+
}
|
|
2544
|
+
)
|
|
2545
|
+
] })
|
|
2546
|
+
]
|
|
2547
|
+
}
|
|
2548
|
+
);
|
|
2549
|
+
}
|
|
2550
|
+
export {
|
|
2551
|
+
AUDIO_QUEUE_DEFAULTS,
|
|
2552
|
+
AudioDraftPlayer,
|
|
2553
|
+
AudioPlayer,
|
|
2554
|
+
AudioQueueItem,
|
|
2555
|
+
AudioQueuePanel,
|
|
2556
|
+
AudioQueueStore,
|
|
2557
|
+
AudioVisualizer,
|
|
2558
|
+
BUTTON_SIZES,
|
|
2559
|
+
COLOR_THEMES,
|
|
2560
|
+
ComposerMicSlot,
|
|
2561
|
+
PulseRings,
|
|
2562
|
+
RecordingButton,
|
|
2563
|
+
RecordingTimer,
|
|
2564
|
+
RichAudioPlayer,
|
|
2565
|
+
STATUS_TEXT_EN,
|
|
2566
|
+
STATUS_TEXT_ES,
|
|
2567
|
+
SpeakButton,
|
|
2568
|
+
StatusText,
|
|
2569
|
+
VoiceMicButton,
|
|
2570
|
+
artifactLabel,
|
|
2571
|
+
createAudioPlayer,
|
|
2572
|
+
formatArtifactDuration,
|
|
2573
|
+
formatArtifactSize,
|
|
2574
|
+
formatPlaybackTime,
|
|
2575
|
+
formatRecordingTime,
|
|
2576
|
+
isPending,
|
|
2577
|
+
isTerminal,
|
|
2578
|
+
makeArtifactId,
|
|
2579
|
+
makeRecorder,
|
|
2580
|
+
mergeWavBlobs,
|
|
2581
|
+
normalizeLevels,
|
|
2582
|
+
resampleLevels,
|
|
2583
|
+
useAudioAnalysis,
|
|
2584
|
+
useAudioPlayer,
|
|
2585
|
+
useAudioQueue,
|
|
2586
|
+
useDictation,
|
|
2587
|
+
useDurableRecording,
|
|
2588
|
+
useRecorder,
|
|
2589
|
+
useVoice
|
|
2590
|
+
};
|
|
2591
|
+
//# sourceMappingURL=index.js.map
|