sera-ai 1.0.26 → 1.0.27

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/dist/index.js CHANGED
@@ -420,10 +420,141 @@ var useAudioRecovery = (reprocessSession) => {
420
420
  const DB_NAME = "AudioSessionDB";
421
421
  const STORE_NAME = "audioSessions";
422
422
  const DB_VERSION = 1;
423
+ const createAudioEncodingWorker = () => {
424
+ const workerCode = `
425
+ console.log("Audio encoding worker loaded");
426
+
427
+ self.onmessage = function (e) {
428
+ const { command, data, id } = e.data;
429
+
430
+ try {
431
+ switch (command) {
432
+ case "encodeFloat32ToBase64": {
433
+ const { audioData } = data;
434
+
435
+ self.postMessage({
436
+ type: "progress",
437
+ id,
438
+ message: "Converting audio data...",
439
+ });
440
+
441
+ const float32Array =
442
+ audioData instanceof Float32Array ? audioData : new Float32Array(audioData);
443
+
444
+ console.log("Worker encoding audio:", {
445
+ length: float32Array.length,
446
+ firstSamples: Array.from(float32Array.slice(0, 10)),
447
+ hasValidData: Array.from(float32Array).some((sample) => sample !== 0),
448
+ });
449
+
450
+ const buffer = new ArrayBuffer(float32Array.length * 4);
451
+ const view = new Float32Array(buffer);
452
+ view.set(float32Array);
453
+
454
+ const bytes = new Uint8Array(buffer);
455
+ const chunkSize = 8192;
456
+ let binary = "";
457
+
458
+ for (let i = 0; i < bytes.length; i += chunkSize) {
459
+ const chunk = bytes.slice(i, i + chunkSize);
460
+ binary += String.fromCharCode.apply(null, Array.from(chunk));
461
+
462
+ if (i % (chunkSize * 10) === 0 && i > 0) {
463
+ const progress = Math.round((i / bytes.length) * 100);
464
+ self.postMessage({
465
+ type: "progress",
466
+ id,
467
+ progress,
468
+ message: "Encoding... " + progress + "%",
469
+ });
470
+ }
471
+ }
472
+
473
+ const base64 = btoa(binary);
474
+
475
+ self.postMessage({
476
+ type: "complete",
477
+ id,
478
+ result: base64,
479
+ });
480
+ break;
481
+ }
482
+
483
+ case "decodeBase64ToFloat32": {
484
+ const { base64Data } = data;
485
+
486
+ self.postMessage({
487
+ type: "progress",
488
+ id,
489
+ message: "Decoding audio data...",
490
+ });
491
+
492
+ try {
493
+ const binary = atob(base64Data);
494
+
495
+ const bytes = new Uint8Array(binary.length);
496
+ for (let i = 0; i < binary.length; i++) {
497
+ bytes[i] = binary.charCodeAt(i);
498
+ }
499
+
500
+ const float32Result = new Float32Array(bytes.buffer);
501
+
502
+ console.log("Worker decoded audio:", {
503
+ length: float32Result.length,
504
+ firstSamples: Array.from(float32Result.slice(0, 10)),
505
+ hasValidData: Array.from(float32Result).some((sample) => sample !== 0),
506
+ });
507
+
508
+ self.postMessage({
509
+ type: "complete",
510
+ id,
511
+ result: Array.from(float32Result),
512
+ });
513
+ } catch (decodeError) {
514
+ self.postMessage({
515
+ type: "error",
516
+ id,
517
+ error: "Decode failed: " + decodeError.message,
518
+ });
519
+ }
520
+ break;
521
+ }
522
+
523
+ default:
524
+ self.postMessage({
525
+ type: "error",
526
+ id,
527
+ error: "Unknown command: " + command,
528
+ });
529
+ }
530
+ } catch (error) {
531
+ console.error("Worker error:", error);
532
+ self.postMessage({
533
+ type: "error",
534
+ id,
535
+ error: error.message,
536
+ stack: error.stack,
537
+ });
538
+ }
539
+ };
540
+
541
+ self.onerror = function (error) {
542
+ console.error("Worker script error:", error);
543
+ self.postMessage({
544
+ type: "error",
545
+ error: error.message || "Unknown worker error",
546
+ });
547
+ };
548
+ `;
549
+ const blob = new Blob([workerCode], { type: "application/javascript" });
550
+ return URL.createObjectURL(blob);
551
+ };
423
552
  const initWorker = React3.useCallback(() => {
424
553
  if (!workerRef.current) {
425
554
  try {
426
- workerRef.current = new Worker("/audio-encoding-worker.js");
555
+ const workerUrl = createAudioEncodingWorker();
556
+ workerRef.current = new Worker(workerUrl);
557
+ URL.revokeObjectURL(workerUrl);
427
558
  workerRef.current.onmessage = (e) => {
428
559
  const { type, id, result, error, progress, message } = e.data;
429
560
  const operation = pendingOperations.current.get(id);