@siteed/expo-audio-stream 1.0.3 → 1.0.5

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.
Files changed (114) hide show
  1. package/.size-limit.json +4 -4
  2. package/README.md +18 -176
  3. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
  4. package/app.plugin.js +1 -1
  5. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +3 -5
  6. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -1
  7. package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -1
  8. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +19 -3
  9. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -1
  10. package/build/AudioAnalysis/extractAudioAnalysis.js +14 -27
  11. package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -1
  12. package/build/AudioAnalysis/extractWaveform.d.ts.map +1 -1
  13. package/build/AudioAnalysis/extractWaveform.js +3 -3
  14. package/build/AudioAnalysis/extractWaveform.js.map +1 -1
  15. package/build/AudioRecorder.provider.d.ts +6 -6
  16. package/build/AudioRecorder.provider.d.ts.map +1 -1
  17. package/build/AudioRecorder.provider.js +9 -9
  18. package/build/AudioRecorder.provider.js.map +1 -1
  19. package/build/ExpoAudioStream.native.d.ts.map +1 -1
  20. package/build/ExpoAudioStream.native.js +2 -2
  21. package/build/ExpoAudioStream.native.js.map +1 -1
  22. package/build/ExpoAudioStream.types.d.ts +20 -18
  23. package/build/ExpoAudioStream.types.d.ts.map +1 -1
  24. package/build/ExpoAudioStream.types.js.map +1 -1
  25. package/build/ExpoAudioStream.web.d.ts +8 -8
  26. package/build/ExpoAudioStream.web.d.ts.map +1 -1
  27. package/build/ExpoAudioStream.web.js +40 -22
  28. package/build/ExpoAudioStream.web.js.map +1 -1
  29. package/build/ExpoAudioStreamModule.d.ts.map +1 -1
  30. package/build/ExpoAudioStreamModule.js +8 -7
  31. package/build/ExpoAudioStreamModule.js.map +1 -1
  32. package/build/WebRecorder.web.d.ts +8 -8
  33. package/build/WebRecorder.web.d.ts.map +1 -1
  34. package/build/WebRecorder.web.js +60 -50
  35. package/build/WebRecorder.web.js.map +1 -1
  36. package/build/constants.d.ts +1 -1
  37. package/build/constants.d.ts.map +1 -1
  38. package/build/constants.js +3 -3
  39. package/build/constants.js.map +1 -1
  40. package/build/events.d.ts +16 -4
  41. package/build/events.d.ts.map +1 -1
  42. package/build/events.js +8 -8
  43. package/build/events.js.map +1 -1
  44. package/build/index.d.ts +8 -8
  45. package/build/index.d.ts.map +1 -1
  46. package/build/index.js +6 -6
  47. package/build/index.js.map +1 -1
  48. package/build/logger.d.ts +2 -2
  49. package/build/logger.d.ts.map +1 -1
  50. package/build/logger.js +7 -11
  51. package/build/logger.js.map +1 -1
  52. package/build/useAudioRecorder.d.ts +4 -21
  53. package/build/useAudioRecorder.d.ts.map +1 -1
  54. package/build/useAudioRecorder.js +33 -33
  55. package/build/useAudioRecorder.js.map +1 -1
  56. package/build/utils/BlobFix.d.ts +9 -0
  57. package/build/utils/BlobFix.d.ts.map +1 -0
  58. package/build/utils/BlobFix.js +494 -0
  59. package/build/utils/BlobFix.js.map +1 -0
  60. package/build/utils/concatenateBuffers.d.ts +8 -0
  61. package/build/utils/concatenateBuffers.d.ts.map +1 -0
  62. package/build/utils/concatenateBuffers.js +21 -0
  63. package/build/utils/concatenateBuffers.js.map +1 -0
  64. package/build/utils/convertPCMToFloat32.d.ts +2 -2
  65. package/build/utils/convertPCMToFloat32.d.ts.map +1 -1
  66. package/build/utils/convertPCMToFloat32.js +49 -36
  67. package/build/utils/convertPCMToFloat32.js.map +1 -1
  68. package/build/utils/encodingToBitDepth.d.ts +1 -1
  69. package/build/utils/encodingToBitDepth.d.ts.map +1 -1
  70. package/build/utils/encodingToBitDepth.js +3 -3
  71. package/build/utils/encodingToBitDepth.js.map +1 -1
  72. package/build/utils/getWavFileInfo.d.ts +4 -3
  73. package/build/utils/getWavFileInfo.d.ts.map +1 -1
  74. package/build/utils/getWavFileInfo.js +18 -15
  75. package/build/utils/getWavFileInfo.js.map +1 -1
  76. package/build/utils/writeWavHeader.d.ts.map +1 -1
  77. package/build/utils/writeWavHeader.js +4 -4
  78. package/build/utils/writeWavHeader.js.map +1 -1
  79. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -1
  80. package/build/workers/InlineFeaturesExtractor.web.js.map +1 -1
  81. package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -1
  82. package/build/workers/inlineAudioWebWorker.web.js.map +1 -1
  83. package/expo-module.config.json +8 -17
  84. package/ios/AudioStreamManager.swift +1 -0
  85. package/ios/ExpoAudioStreamModule.swift +1 -0
  86. package/ios/RecordingResult.swift +1 -0
  87. package/package.json +72 -65
  88. package/plugin/build/index.d.ts +1 -1
  89. package/plugin/build/index.js +7 -7
  90. package/plugin/src/index.ts +47 -47
  91. package/plugin/tsconfig.json +8 -13
  92. package/src/AudioAnalysis/AudioAnalysis.types.ts +59 -60
  93. package/src/AudioAnalysis/extractAudioAnalysis.ts +132 -121
  94. package/src/AudioAnalysis/extractWaveform.ts +18 -18
  95. package/src/AudioRecorder.provider.tsx +53 -53
  96. package/src/ExpoAudioStream.native.ts +2 -2
  97. package/src/ExpoAudioStream.types.ts +56 -53
  98. package/src/ExpoAudioStream.web.ts +232 -205
  99. package/src/ExpoAudioStreamModule.ts +17 -16
  100. package/src/WebRecorder.web.ts +407 -390
  101. package/src/constants.ts +11 -11
  102. package/src/events.ts +27 -13
  103. package/src/index.ts +15 -15
  104. package/src/logger.ts +15 -18
  105. package/src/useAudioRecorder.tsx +394 -389
  106. package/src/utils/BlobFix.ts +550 -0
  107. package/src/utils/concatenateBuffers.ts +24 -0
  108. package/src/utils/convertPCMToFloat32.ts +72 -45
  109. package/src/utils/encodingToBitDepth.ts +14 -14
  110. package/src/utils/getWavFileInfo.ts +106 -99
  111. package/src/utils/writeWavHeader.ts +45 -45
  112. package/src/workers/InlineFeaturesExtractor.web.tsx +1 -1
  113. package/src/workers/inlineAudioWebWorker.web.tsx +1 -1
  114. package/tsconfig.json +12 -7
@@ -1,12 +1,13 @@
1
- import { getLogger } from "./logger";
2
- import { encodingToBitDepth } from "./utils/encodingToBitDepth";
3
- import { InlineFeaturesExtractor } from "./workers/InlineFeaturesExtractor.web";
4
- import { InlineAudioWebWorker } from "./workers/inlineAudioWebWorker.web";
1
+ import { getLogger } from './logger';
2
+ import { encodingToBitDepth } from './utils/encodingToBitDepth';
3
+ import { InlineFeaturesExtractor } from './workers/InlineFeaturesExtractor.web';
4
+ import { InlineAudioWebWorker } from './workers/inlineAudioWebWorker.web';
5
5
  const DEFAULT_WEB_BITDEPTH = 32;
6
6
  const DEFAULT_WEB_POINTS_PER_SECOND = 10;
7
7
  const DEFAULT_WEB_INTERVAL = 500;
8
8
  const DEFAULT_WEB_NUMBER_OF_CHANNELS = 1;
9
- const TAG = "WebRecorder";
9
+ const DEFAULT_ALGORITHM = 'rms';
10
+ const TAG = 'WebRecorder';
10
11
  const logger = getLogger(TAG);
11
12
  export class WebRecorder {
12
13
  audioContext;
@@ -21,9 +22,10 @@ export class WebRecorder {
21
22
  numberOfChannels; // Number of audio channels
22
23
  bitDepth; // Bit depth of the audio
23
24
  exportBitDepth; // Bit depth of the audio
24
- buffers; // Array to store the buffers
25
+ buffer; // Single buffer to store the audio data
26
+ bufferSize; // Keep track of the buffer size
25
27
  audioAnalysisData; // Keep updating the full audio analysis data with latest events
26
- constructor({ audioContext, source, recordingConfig, featuresExtratorUrl, audioWorkletUrl, emitAudioEventCallback, emitAudioAnalysisCallback, }) {
28
+ constructor({ audioContext, source, recordingConfig, audioWorkletUrl, emitAudioEventCallback, emitAudioAnalysisCallback, }) {
27
29
  this.audioContext = audioContext;
28
30
  this.source = source;
29
31
  this.audioWorkletUrl = audioWorkletUrl;
@@ -31,21 +33,23 @@ export class WebRecorder {
31
33
  this.emitAudioAnalysisCallback = emitAudioAnalysisCallback;
32
34
  this.config = recordingConfig;
33
35
  this.position = 0;
34
- this.buffers = []; // Initialize the buffers array
36
+ this.bufferSize = 0;
37
+ this.buffer = new Float32Array(0); // Initialize the buffer
35
38
  const audioContextFormat = this.checkAudioContextFormat({
36
39
  sampleRate: this.audioContext.sampleRate,
37
40
  });
38
- logger.debug("Initialized WebRecorder with config:", {
41
+ logger.debug('Initialized WebRecorder with config:', {
39
42
  sampleRate: audioContextFormat.sampleRate,
40
43
  bitDepth: audioContextFormat.bitDepth,
41
44
  numberOfChannels: audioContextFormat.numberOfChannels,
42
45
  });
43
46
  this.bitDepth = audioContextFormat.bitDepth;
44
47
  this.numberOfChannels =
45
- audioContextFormat.numberOfChannels || DEFAULT_WEB_NUMBER_OF_CHANNELS; // Default to 1 if not available
48
+ audioContextFormat.numberOfChannels ||
49
+ DEFAULT_WEB_NUMBER_OF_CHANNELS; // Default to 1 if not available
46
50
  this.exportBitDepth =
47
51
  encodingToBitDepth({
48
- encoding: recordingConfig.encoding ?? "pcm_32bit",
52
+ encoding: recordingConfig.encoding ?? 'pcm_32bit',
49
53
  }) ||
50
54
  audioContextFormat.bitDepth ||
51
55
  DEFAULT_WEB_BITDEPTH;
@@ -54,6 +58,7 @@ export class WebRecorder {
54
58
  dataPoints: [],
55
59
  durationMs: 0,
56
60
  samples: 0,
61
+ amplitudeAlgorithm: recordingConfig.algorithm || DEFAULT_ALGORITHM,
57
62
  bitDepth: this.bitDepth,
58
63
  numberOfChannels: this.numberOfChannels,
59
64
  sampleRate: this.config.sampleRate || this.audioContext.sampleRate,
@@ -68,7 +73,7 @@ export class WebRecorder {
68
73
  try {
69
74
  if (!this.audioWorkletUrl) {
70
75
  const blob = new Blob([InlineAudioWebWorker], {
71
- type: "application/javascript",
76
+ type: 'application/javascript',
72
77
  });
73
78
  const url = URL.createObjectURL(blob);
74
79
  await this.audioContext.audioWorklet.addModule(url);
@@ -76,39 +81,38 @@ export class WebRecorder {
76
81
  else {
77
82
  await this.audioContext.audioWorklet.addModule(this.audioWorkletUrl);
78
83
  }
79
- this.audioWorkletNode = new AudioWorkletNode(this.audioContext, "recorder-processor");
84
+ this.audioWorkletNode = new AudioWorkletNode(this.audioContext, 'recorder-processor');
80
85
  this.audioWorkletNode.port.onmessage = async (event) => {
81
86
  const command = event.data.command;
82
- if (command !== "newData") {
87
+ if (command !== 'newData') {
83
88
  return;
84
89
  }
85
90
  // Handle the audio blob (e.g., send it to the server or process it further)
86
- logger.debug("Received audio blob from processor", event);
87
- const pcmBuffer = event.data.recordedData;
88
- if (!pcmBuffer) {
91
+ logger.debug('Received audio blob from processor', event);
92
+ const pcmBufferFloat = event.data.recordedData;
93
+ if (!pcmBufferFloat) {
89
94
  return;
90
95
  }
91
- this.buffers.push(pcmBuffer); // Store the buffer
96
+ // Concatenate the incoming Float32Array to the existing buffer
97
+ const newBuffer = new Float32Array(this.bufferSize + pcmBufferFloat.length);
98
+ newBuffer.set(this.buffer, 0);
99
+ newBuffer.set(pcmBufferFloat, this.bufferSize);
100
+ this.buffer = newBuffer;
101
+ this.bufferSize += pcmBufferFloat.length;
92
102
  const sampleRate = event.data.sampleRate ?? this.audioContext.sampleRate;
93
- const otherSampleRate = this.audioContext.sampleRate;
94
- // Pass the intermediary buffer to the feature extractor worker
95
- const pcmBufferCopy = pcmBuffer.slice(0);
96
- const channelData = new Float32Array(pcmBufferCopy);
97
- const duration = channelData.length / sampleRate; // Calculate duration of the current buffer
98
- const otherDuration = pcmBuffer.byteLength /
99
- (otherSampleRate * (this.exportBitDepth / this.numberOfChannels)); // Calculate duration of the current buffer
100
- logger.debug(`sampleRate=${sampleRate} Duration: ${duration} -- otherSampleRate=${otherSampleRate} Other duration: ${otherDuration}`);
103
+ const duration = pcmBufferFloat.length / sampleRate; // Calculate duration of the current buffer
101
104
  this.emitAudioEventCallback({
102
- data: pcmBuffer,
105
+ data: pcmBufferFloat,
103
106
  position: this.position,
104
107
  });
105
108
  this.position += duration; // Update position
106
109
  this.featureExtractorWorker?.postMessage({
107
- command: "process",
108
- channelData,
109
- sampleRate: this.audioContext.sampleRate,
110
- pointsPerSecond: this.config.pointsPerSecond || DEFAULT_WEB_POINTS_PER_SECOND,
111
- algorithm: this.config.algorithm || "rms",
110
+ command: 'process',
111
+ channelData: pcmBufferFloat,
112
+ sampleRate,
113
+ pointsPerSecond: this.config.pointsPerSecond ||
114
+ DEFAULT_WEB_POINTS_PER_SECOND,
115
+ algorithm: this.config.algorithm || 'rms',
112
116
  bitDepth: this.bitDepth,
113
117
  fullAudioDurationMs: this.position * 1000,
114
118
  numberOfChannels: this.numberOfChannels,
@@ -117,7 +121,7 @@ export class WebRecorder {
117
121
  };
118
122
  logger.debug(`WebRecorder initialized -- recordSampleRate=${this.audioContext.sampleRate}`, this.config);
119
123
  this.audioWorkletNode.port.postMessage({
120
- command: "init",
124
+ command: 'init',
121
125
  recordSampleRate: this.audioContext.sampleRate, // Pass the original sample rate
122
126
  exportSampleRate: this.config.sampleRate ?? this.audioContext.sampleRate,
123
127
  bitDepth: this.bitDepth,
@@ -142,7 +146,8 @@ export class WebRecorder {
142
146
  this.featureExtractorWorker = new Worker(new URL(featuresExtratorUrl, window.location.href));
143
147
  this.featureExtractorWorker.onmessage =
144
148
  this.handleFeatureExtractorMessage.bind(this);
145
- this.featureExtractorWorker.onerror = this.handleWorkerError.bind(this);
149
+ this.featureExtractorWorker.onerror =
150
+ this.handleWorkerError.bind(this);
146
151
  }
147
152
  else {
148
153
  // Fallback to the inline worker if the URL is not provided
@@ -157,7 +162,7 @@ export class WebRecorder {
157
162
  initFallbackWorker() {
158
163
  try {
159
164
  const blob = new Blob([InlineFeaturesExtractor], {
160
- type: "application/javascript",
165
+ type: 'application/javascript',
161
166
  });
162
167
  const url = URL.createObjectURL(blob);
163
168
  this.featureExtractorWorker = new Worker(url);
@@ -166,7 +171,7 @@ export class WebRecorder {
166
171
  this.featureExtractorWorker.onerror = (error) => {
167
172
  console.error(`[${TAG}] Default Inline worker failed`, error);
168
173
  };
169
- logger.log("Inline worker initialized successfully");
174
+ logger.log('Inline worker initialized successfully');
170
175
  }
171
176
  catch (error) {
172
177
  console.error(`[${TAG}] Failed to initialize Inline Feature Extractor worker`, error);
@@ -176,7 +181,7 @@ export class WebRecorder {
176
181
  console.error(`[${TAG}] Feature extractor worker error:`, error);
177
182
  }
178
183
  handleFeatureExtractorMessage(event) {
179
- if (event.data.command === "features") {
184
+ if (event.data.command === 'features') {
180
185
  const segmentResult = event.data.result;
181
186
  // Merge the segment result with the full audio analysis data
182
187
  this.audioAnalysisData.dataPoints.push(...segmentResult.dataPoints);
@@ -189,8 +194,8 @@ export class WebRecorder {
189
194
  };
190
195
  }
191
196
  // Handle the extracted features (e.g., emit an event or log them)
192
- logger.debug("features event segmentResult", segmentResult);
193
- logger.debug("features event audioAnalysisData", this.audioAnalysisData);
197
+ logger.debug('features event segmentResult', segmentResult);
198
+ logger.debug('features event audioAnalysisData', this.audioAnalysisData);
194
199
  this.emitAudioAnalysisCallback(segmentResult);
195
200
  }
196
201
  }
@@ -204,30 +209,35 @@ export class WebRecorder {
204
209
  if (this.audioWorkletNode) {
205
210
  // this.source.disconnect(this.audioWorkletNode);
206
211
  // this.audioWorkletNode.disconnect(this.audioContext.destination);
207
- this.audioWorkletNode.port.postMessage({ command: "stop" });
212
+ this.audioWorkletNode.port.postMessage({ command: 'stop' });
208
213
  // Set a timeout to reject the promise if no message is received within 5 seconds
209
214
  const timeout = setTimeout(() => {
210
- this.audioWorkletNode.port.removeEventListener("message", onMessage);
215
+ this.audioWorkletNode.port.removeEventListener('message', onMessage);
211
216
  reject(new Error("Timeout error, audioWorkletNode didn't complete."));
212
217
  }, 5000);
213
218
  // Listen for the recordedData message to confirm stopping
214
219
  const onMessage = async (event) => {
215
220
  const command = event.data.command;
216
- if (command === "recordedData") {
221
+ if (command === 'recordedData') {
217
222
  clearTimeout(timeout); // Clear the timeout
218
223
  const rawPCMDataFull = event.data.recordedData?.slice(0);
224
+ if (!rawPCMDataFull) {
225
+ reject(new Error('Failed to get recorded data'));
226
+ return;
227
+ }
219
228
  // Compute duration of the recorded data
220
229
  const duration = rawPCMDataFull.byteLength /
221
230
  (this.audioContext.sampleRate *
222
- (this.exportBitDepth / this.numberOfChannels));
231
+ (this.exportBitDepth /
232
+ this.numberOfChannels));
223
233
  logger.debug(`Received recorded data -- Duration: ${duration} vs ${rawPCMDataFull.byteLength / this.audioContext.sampleRate} seconds`);
224
- logger.debug(`recordedData.length=${rawPCMDataFull.byteLength} vs transmittedData.length=${this.buffers[0].byteLength}`);
234
+ logger.debug(`recordedData.length=${rawPCMDataFull.byteLength} vs transmittedData.length=${this.bufferSize}`);
225
235
  // Remove the event listener after receiving the final data
226
- this.audioWorkletNode.port.removeEventListener("message", onMessage);
227
- resolve(this.buffers); // Resolve the promise with the collected buffers
236
+ this.audioWorkletNode.port.removeEventListener('message', onMessage);
237
+ resolve(this.buffer); // Resolve the promise with the collected buffers
228
238
  }
229
239
  };
230
- this.audioWorkletNode.port.addEventListener("message", onMessage);
240
+ this.audioWorkletNode.port.addEventListener('message', onMessage);
231
241
  }
232
242
  // Stop all media stream tracks to stop the browser recording
233
243
  this.stopMediaStreamTracks();
@@ -240,7 +250,7 @@ export class WebRecorder {
240
250
  pause() {
241
251
  this.source.disconnect(this.audioWorkletNode); // Disconnect the source from the AudioWorkletNode
242
252
  this.audioWorkletNode.disconnect(this.audioContext.destination); // Disconnect the AudioWorkletNode from the destination
243
- this.audioWorkletNode.port.postMessage({ command: "pause" });
253
+ this.audioWorkletNode.port.postMessage({ command: 'pause' });
244
254
  }
245
255
  stopMediaStreamTracks() {
246
256
  // Stop all audio tracks to stop the recording icon
@@ -260,7 +270,7 @@ export class WebRecorder {
260
270
  bufferSource.buffer = audioBuffer;
261
271
  bufferSource.connect(this.audioContext.destination);
262
272
  bufferSource.start();
263
- logger.debug("Playing recorded data", recordedData);
273
+ logger.debug('Playing recorded data', recordedData);
264
274
  }
265
275
  catch (error) {
266
276
  console.error(`[${TAG}] Failed to play recorded data:`, error);
@@ -282,7 +292,7 @@ export class WebRecorder {
282
292
  resume() {
283
293
  this.source.connect(this.audioWorkletNode);
284
294
  this.audioWorkletNode.connect(this.audioContext.destination);
285
- this.audioWorkletNode.port.postMessage({ command: "resume" });
295
+ this.audioWorkletNode.port.postMessage({ command: 'resume' });
286
296
  }
287
297
  }
288
298
  //# sourceMappingURL=WebRecorder.web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"WebRecorder.web.js","sourceRoot":"","sources":["../src/WebRecorder.web.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAiB1E,MAAM,oBAAoB,GAAG,EAAE,CAAC;AAChC,MAAM,6BAA6B,GAAG,EAAE,CAAC;AACzC,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,MAAM,8BAA8B,GAAG,CAAC,CAAC;AAEzC,MAAM,GAAG,GAAG,aAAa,CAAC;AAC1B,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC;AAE9B,MAAM,OAAO,WAAW;IACd,YAAY,CAAe;IAC3B,gBAAgB,CAAoB;IACpC,sBAAsB,CAAU;IAChC,MAAM,CAA6B;IACnC,eAAe,CAAS;IACxB,sBAAsB,CAAyB;IAC/C,yBAAyB,CAA4B;IACrD,MAAM,CAAkB;IACxB,QAAQ,CAAS,CAAC,gCAAgC;IAClD,gBAAgB,CAAS,CAAC,2BAA2B;IACrD,QAAQ,CAAS,CAAC,yBAAyB;IAC3C,cAAc,CAAS,CAAC,yBAAyB;IACjD,OAAO,CAAgB,CAAC,6BAA6B;IACrD,iBAAiB,CAAoB,CAAC,gEAAgE;IAE9G,YAAY,EACV,YAAY,EACZ,MAAM,EACN,eAAe,EACf,mBAAmB,EACnB,eA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,WAAW,CAAC,iBAAiB,GAAG,CAAC,CAAC,CAAC,mCAAmC;QAEvF,OAAO;YACL,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,QAAQ;YACR,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;SAC/C,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC3C,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;QAC7D,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAChE,CAAC;CACF","sourcesContent":["// src/WebRecorder.ts\nimport { AudioAnalysisData } from \"./AudioAnalysis/AudioAnalysis.types\";\nimport { RecordingConfig } from \"./ExpoAudioStream.types\";\nimport {\n EmitAudioAnalysisFunction,\n EmitAudioEventFunction,\n} from \"./ExpoAudioStream.web\";\nimport { getLogger } from \"./logger\";\nimport { encodingToBitDepth } from \"./utils/encodingToBitDepth\";\nimport { InlineFeaturesExtractor } from \"./workers/InlineFeaturesExtractor.web\";\nimport { InlineAudioWebWorker } from \"./workers/inlineAudioWebWorker.web\";\n\ninterface AudioWorkletEvent {\n data: {\n command: string;\n recordedData?: ArrayBuffer;\n sampleRate?: number;\n };\n}\n\ninterface AudioFeaturesEvent {\n data: {\n command: string;\n result: AudioAnalysisData;\n };\n}\n\nconst DEFAULT_WEB_BITDEPTH = 32;\nconst DEFAULT_WEB_POINTS_PER_SECOND = 10;\nconst DEFAULT_WEB_INTERVAL = 500;\nconst DEFAULT_WEB_NUMBER_OF_CHANNELS = 1;\n\nconst TAG = \"WebRecorder\";\nconst logger = getLogger(TAG);\n\nexport class WebRecorder {\n private audioContext: AudioContext;\n private audioWorkletNode!: AudioWorkletNode;\n private featureExtractorWorker?: Worker;\n private source: MediaStreamAudioSourceNode;\n private audioWorkletUrl: string;\n private emitAudioEventCallback: EmitAudioEventFunction;\n private emitAudioAnalysisCallback: EmitAudioAnalysisFunction;\n private config: RecordingConfig;\n private position: number; // Track the cumulative position\n private numberOfChannels: number; // Number of audio channels\n private bitDepth: number; // Bit depth of the audio\n private exportBitDepth: number; // Bit depth of the audio\n private buffers: ArrayBuffer[]; // Array to store the buffers\n private audioAnalysisData: AudioAnalysisData; // Keep updating the full audio analysis data with latest events\n\n constructor({\n audioContext,\n source,\n recordingConfig,\n featuresExtratorUrl,\n audioWorkletUrl,\n emitAudioEventCallback,\n emitAudioAnalysisCallback,\n }: {\n audioContext: AudioContext;\n source: MediaStreamAudioSourceNode;\n recordingConfig: RecordingConfig;\n featuresExtratorUrl: string;\n audioWorkletUrl: string;\n emitAudioEventCallback: EmitAudioEventFunction;\n emitAudioAnalysisCallback: EmitAudioAnalysisFunction;\n }) {\n this.audioContext = audioContext;\n this.source = source;\n this.audioWorkletUrl = audioWorkletUrl;\n this.emitAudioEventCallback = emitAudioEventCallback;\n this.emitAudioAnalysisCallback = emitAudioAnalysisCallback;\n this.config = recordingConfig;\n this.position = 0;\n this.buffers = []; // Initialize the buffers array\n\n const audioContextFormat = this.checkAudioContextFormat({\n sampleRate: this.audioContext.sampleRate,\n });\n logger.debug(\"Initialized WebRecorder with config:\", {\n sampleRate: audioContextFormat.sampleRate,\n bitDepth: audioContextFormat.bitDepth,\n numberOfChannels: audioContextFormat.numberOfChannels,\n });\n\n this.bitDepth = audioContextFormat.bitDepth;\n this.numberOfChannels =\n audioContextFormat.numberOfChannels || DEFAULT_WEB_NUMBER_OF_CHANNELS; // Default to 1 if not available\n this.exportBitDepth =\n encodingToBitDepth({\n encoding: recordingConfig.encoding ?? \"pcm_32bit\",\n }) ||\n audioContextFormat.bitDepth ||\n DEFAULT_WEB_BITDEPTH;\n\n this.audioAnalysisData = {\n amplitudeRange: { min: 0, max: 0 },\n dataPoints: [],\n durationMs: 0,\n samples: 0,\n bitDepth: this.bitDepth,\n numberOfChannels: this.numberOfChannels,\n sampleRate: this.config.sampleRate || this.audioContext.sampleRate,\n pointsPerSecond:\n this.config.pointsPerSecond || DEFAULT_WEB_POINTS_PER_SECOND,\n speakerChanges: [],\n };\n\n if (recordingConfig.enableProcessing) {\n this.initFeatureExtractorWorker();\n }\n }\n\n async init() {\n try {\n if (!this.audioWorkletUrl) {\n const blob = new Blob([InlineAudioWebWorker], {\n type: \"application/javascript\",\n });\n const url = URL.createObjectURL(blob);\n await this.audioContext.audioWorklet.addModule(url);\n } else {\n await this.audioContext.audioWorklet.addModule(this.audioWorkletUrl);\n }\n this.audioWorkletNode = new AudioWorkletNode(\n this.audioContext,\n \"recorder-processor\",\n );\n\n this.audioWorkletNode.port.onmessage = async (\n event: AudioWorkletEvent,\n ) => {\n const command = event.data.command;\n if (command !== \"newData\") {\n return;\n }\n // Handle the audio blob (e.g., send it to the server or process it further)\n logger.debug(\"Received audio blob from processor\", event);\n const pcmBuffer = event.data.recordedData;\n\n if (!pcmBuffer) {\n return;\n }\n\n this.buffers.push(pcmBuffer); // Store the buffer\n const sampleRate =\n event.data.sampleRate ?? this.audioContext.sampleRate;\n const otherSampleRate = this.audioContext.sampleRate;\n\n // Pass the intermediary buffer to the feature extractor worker\n const pcmBufferCopy = pcmBuffer.slice(0);\n const channelData = new Float32Array(pcmBufferCopy);\n\n const duration = channelData.length / sampleRate; // Calculate duration of the current buffer\n const otherDuration =\n pcmBuffer.byteLength /\n (otherSampleRate * (this.exportBitDepth / this.numberOfChannels)); // Calculate duration of the current buffer\n logger.debug(\n `sampleRate=${sampleRate} Duration: ${duration} -- otherSampleRate=${otherSampleRate} Other duration: ${otherDuration}`,\n );\n\n this.emitAudioEventCallback({\n data: pcmBuffer,\n position: this.position,\n });\n this.position += duration; // Update position\n\n this.featureExtractorWorker?.postMessage(\n {\n command: \"process\",\n channelData,\n sampleRate: this.audioContext.sampleRate,\n pointsPerSecond:\n this.config.pointsPerSecond || DEFAULT_WEB_POINTS_PER_SECOND,\n algorithm: this.config.algorithm || \"rms\",\n bitDepth: this.bitDepth,\n fullAudioDurationMs: this.position * 1000,\n numberOfChannels: this.numberOfChannels,\n features: this.config.features,\n },\n [],\n );\n };\n\n logger.debug(\n `WebRecorder initialized -- recordSampleRate=${this.audioContext.sampleRate}`,\n this.config,\n );\n this.audioWorkletNode.port.postMessage({\n command: \"init\",\n recordSampleRate: this.audioContext.sampleRate, // Pass the original sample rate\n exportSampleRate:\n this.config.sampleRate ?? this.audioContext.sampleRate,\n bitDepth: this.bitDepth,\n exportBitDepth: this.exportBitDepth,\n channels: this.numberOfChannels,\n interval: this.config.interval ?? DEFAULT_WEB_INTERVAL,\n });\n\n // Connect the source to the AudioWorkletNode and start recording\n this.source.connect(this.audioWorkletNode);\n this.audioWorkletNode.connect(this.audioContext.destination);\n } catch (error) {\n console.error(`[${TAG}] Failed to initialize WebRecorder`, error);\n }\n }\n\n initFeatureExtractorWorker(featuresExtratorUrl?: string) {\n try {\n if (featuresExtratorUrl) {\n // Initialize the feature extractor worker\n //TODO: create audio feature extractor from a Blob instead of url since we cannot include the url directly in the library\n // We keep the url during dev and use the blob in production.\n this.featureExtractorWorker = new Worker(\n new URL(featuresExtratorUrl, window.location.href),\n );\n this.featureExtractorWorker.onmessage =\n this.handleFeatureExtractorMessage.bind(this);\n this.featureExtractorWorker.onerror = this.handleWorkerError.bind(this);\n } else {\n // Fallback to the inline worker if the URL is not provided\n this.initFallbackWorker();\n }\n } catch (error) {\n console.error(\n `[${TAG}] Failed to initialize feature extractor worker`,\n error,\n );\n this.initFallbackWorker();\n }\n }\n\n initFallbackWorker() {\n try {\n const blob = new Blob([InlineFeaturesExtractor], {\n type: \"application/javascript\",\n });\n const url = URL.createObjectURL(blob);\n this.featureExtractorWorker = new Worker(url);\n this.featureExtractorWorker.onmessage =\n this.handleFeatureExtractorMessage.bind(this);\n this.featureExtractorWorker.onerror = (error) => {\n console.error(`[${TAG}] Default Inline worker failed`, error);\n };\n logger.log(\"Inline worker initialized successfully\");\n } catch (error) {\n console.error(\n `[${TAG}] Failed to initialize Inline Feature Extractor worker`,\n error,\n );\n }\n }\n\n handleWorkerError(error: ErrorEvent) {\n console.error(`[${TAG}] Feature extractor worker error:`, error);\n }\n\n handleFeatureExtractorMessage(event: AudioFeaturesEvent) {\n if (event.data.command === \"features\") {\n const segmentResult = event.data.result;\n\n // Merge the segment result with the full audio analysis data\n this.audioAnalysisData.dataPoints.push(...segmentResult.dataPoints);\n this.audioAnalysisData.speakerChanges?.push(\n ...(segmentResult.speakerChanges ?? []),\n );\n this.audioAnalysisData.durationMs = segmentResult.durationMs;\n if (segmentResult.amplitudeRange) {\n this.audioAnalysisData.amplitudeRange = {\n min: Math.min(\n this.audioAnalysisData.amplitudeRange.min,\n segmentResult.amplitudeRange.min,\n ),\n max: Math.max(\n this.audioAnalysisData.amplitudeRange.max,\n segmentResult.amplitudeRange.max,\n ),\n };\n }\n // Handle the extracted features (e.g., emit an event or log them)\n logger.debug(\"features event segmentResult\", segmentResult);\n logger.debug(\"features event audioAnalysisData\", this.audioAnalysisData);\n this.emitAudioAnalysisCallback(segmentResult);\n }\n }\n\n start() {\n this.source.connect(this.audioWorkletNode);\n this.audioWorkletNode.connect(this.audioContext.destination);\n }\n\n stop() {\n return new Promise((resolve, reject) => {\n try {\n if (this.audioWorkletNode) {\n // this.source.disconnect(this.audioWorkletNode);\n // this.audioWorkletNode.disconnect(this.audioContext.destination);\n this.audioWorkletNode.port.postMessage({ command: \"stop\" });\n\n // Set a timeout to reject the promise if no message is received within 5 seconds\n const timeout = setTimeout(() => {\n this.audioWorkletNode.port.removeEventListener(\n \"message\",\n onMessage,\n );\n reject(\n new Error(\"Timeout error, audioWorkletNode didn't complete.\"),\n );\n }, 5000);\n\n // Listen for the recordedData message to confirm stopping\n const onMessage = async (event: AudioWorkletEvent) => {\n const command = event.data.command;\n if (command === \"recordedData\") {\n clearTimeout(timeout); // Clear the timeout\n\n const rawPCMDataFull = event.data.recordedData?.slice(\n 0,\n ) as ArrayBuffer;\n\n // Compute duration of the recorded data\n const duration =\n rawPCMDataFull.byteLength /\n (this.audioContext.sampleRate *\n (this.exportBitDepth / this.numberOfChannels));\n logger.debug(\n `Received recorded data -- Duration: ${duration} vs ${rawPCMDataFull.byteLength / this.audioContext.sampleRate} seconds`,\n );\n logger.debug(\n `recordedData.length=${rawPCMDataFull.byteLength} vs transmittedData.length=${this.buffers[0].byteLength}`,\n );\n\n // Remove the event listener after receiving the final data\n this.audioWorkletNode.port.removeEventListener(\n \"message\",\n onMessage,\n );\n resolve(this.buffers); // Resolve the promise with the collected buffers\n }\n };\n this.audioWorkletNode.port.addEventListener(\"message\", onMessage);\n }\n\n // Stop all media stream tracks to stop the browser recording\n this.stopMediaStreamTracks();\n } catch (error) {\n reject(error);\n }\n });\n }\n\n pause() {\n this.source.disconnect(this.audioWorkletNode); // Disconnect the source from the AudioWorkletNode\n this.audioWorkletNode.disconnect(this.audioContext.destination); // Disconnect the AudioWorkletNode from the destination\n this.audioWorkletNode.port.postMessage({ command: \"pause\" });\n }\n\n stopMediaStreamTracks() {\n // Stop all audio tracks to stop the recording icon\n const tracks = this.source.mediaStream.getTracks();\n tracks.forEach((track) => track.stop());\n }\n\n async playRecordedData({\n recordedData,\n }: {\n recordedData: ArrayBuffer;\n mimeType?: string;\n }) {\n try {\n const blob = new Blob([recordedData]);\n const url = URL.createObjectURL(blob);\n const response = await fetch(url);\n const arrayBuffer = await response.arrayBuffer();\n\n // Decode the audio data\n const audioBuffer = await this.audioContext.decodeAudioData(arrayBuffer);\n\n // Create a buffer source node and play the audio\n const bufferSource = this.audioContext.createBufferSource();\n bufferSource.buffer = audioBuffer;\n bufferSource.connect(this.audioContext.destination);\n bufferSource.start();\n logger.debug(\"Playing recorded data\", recordedData);\n } catch (error) {\n console.error(`[${TAG}] Failed to play recorded data:`, error);\n }\n }\n\n private checkAudioContextFormat({ sampleRate }: { sampleRate: number }) {\n // Create a silent AudioBuffer\n const frameCount = sampleRate * 1.0; // 1 second buffer\n const audioBuffer = this.audioContext.createBuffer(\n 1,\n frameCount,\n sampleRate,\n );\n\n // Check the format\n const channelData = audioBuffer.getChannelData(0);\n const bitDepth = channelData.BYTES_PER_ELEMENT * 8; // 4 bytes per element means 32-bit\n\n return {\n sampleRate: audioBuffer.sampleRate,\n bitDepth,\n numberOfChannels: audioBuffer.numberOfChannels,\n };\n }\n\n resume() {\n this.source.connect(this.audioWorkletNode);\n this.audioWorkletNode.connect(this.audioContext.destination);\n this.audioWorkletNode.port.postMessage({ command: \"resume\" });\n }\n}\n"]}
1
+ {"version":3,"file":"WebRecorder.web.js","sourceRoot":"","sources":["../src/WebRecorder.web.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AAiBzE,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAC/B,MAAM,6BAA6B,GAAG,EAAE,CAAA;AACxC,MAAM,oBAAoB,GAAG,GAAG,CAAA;AAChC,MAAM,8BAA8B,GAAG,CAAC,CAAA;AACxC,MAAM,iBAAiB,GAAG,KAAK,CAAA;AAE/B,MAAM,GAAG,GAAG,aAAa,CAAA;AACzB,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,CAAA;AAE7B,MAAM,OAAO,WAAW;IACZ,YAAY,CAAc;IAC1B,gBAAgB,CAAmB;IACnC,sBAAsB,CAAS;IAC/B,MAAM,CAA4B;IAClC,eAAe,CAAQ;IACvB,sBAAsB,CAAwB;IAC9C,yBAAyB,CAA2B;IACpD,MAAM,CAAiB;IACvB,QAAQ,CAAQ,CAAC,gCAAgC;IACjD,gBAAgB,CAAQ,CAAC,2BAA2B;IACpD,QAAQ,CAAQ,CAAC,yBAAyB;IAC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GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAC9C,CAAC,EACD,UAAU,EACV,UAAU,CACb,CAAA;QAED,mBAAmB;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAA;QACjD,MAAM,QAAQ,GAAG,WAAW,CAAC,iBAAiB,GAAG,CAAC,CAAA,CAAC,mCAAmC;QAEtF,OAAO;YACH,UAAU,EAAE,WAAW,CAAC,UAAU;YAClC,QAAQ;YACR,gBAAgB,EAAE,WAAW,CAAC,gBAAgB;SACjD,CAAA;IACL,CAAC;IAED,MAAM;QACF,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAA;QAC1C,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAA;QAC5D,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;IACjE,CAAC;CACJ","sourcesContent":["// src/WebRecorder.ts\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport { RecordingConfig } from './ExpoAudioStream.types'\nimport {\n EmitAudioAnalysisFunction,\n EmitAudioEventFunction,\n} from './ExpoAudioStream.web'\nimport { getLogger } from './logger'\nimport { encodingToBitDepth } from './utils/encodingToBitDepth'\nimport { InlineFeaturesExtractor } from './workers/InlineFeaturesExtractor.web'\nimport { InlineAudioWebWorker } from './workers/inlineAudioWebWorker.web'\n\ninterface AudioWorkletEvent {\n data: {\n command: string\n recordedData?: Float32Array\n sampleRate?: number\n }\n}\n\ninterface AudioFeaturesEvent {\n data: {\n command: string\n result: AudioAnalysis\n }\n}\n\nconst DEFAULT_WEB_BITDEPTH = 32\nconst DEFAULT_WEB_POINTS_PER_SECOND = 10\nconst DEFAULT_WEB_INTERVAL = 500\nconst DEFAULT_WEB_NUMBER_OF_CHANNELS = 1\nconst DEFAULT_ALGORITHM = 'rms'\n\nconst TAG = 'WebRecorder'\nconst logger = getLogger(TAG)\n\nexport class WebRecorder {\n private audioContext: AudioContext\n private audioWorkletNode!: AudioWorkletNode\n private featureExtractorWorker?: Worker\n private source: MediaStreamAudioSourceNode\n private audioWorkletUrl: string\n private emitAudioEventCallback: EmitAudioEventFunction\n private emitAudioAnalysisCallback: EmitAudioAnalysisFunction\n private config: RecordingConfig\n private position: number // Track the cumulative position\n private numberOfChannels: number // Number of audio channels\n private bitDepth: number // Bit depth of the audio\n private exportBitDepth: number // Bit depth of the audio\n private buffer: Float32Array // Single buffer to store the audio data\n private bufferSize: number // Keep track of the buffer size\n private audioAnalysisData: AudioAnalysis // Keep updating the full audio analysis data with latest events\n\n constructor({\n audioContext,\n source,\n recordingConfig,\n audioWorkletUrl,\n emitAudioEventCallback,\n emitAudioAnalysisCallback,\n }: {\n audioContext: AudioContext\n source: MediaStreamAudioSourceNode\n recordingConfig: RecordingConfig\n audioWorkletUrl: string\n emitAudioEventCallback: EmitAudioEventFunction\n emitAudioAnalysisCallback: EmitAudioAnalysisFunction\n }) {\n this.audioContext = audioContext\n this.source = source\n this.audioWorkletUrl = audioWorkletUrl\n this.emitAudioEventCallback = emitAudioEventCallback\n this.emitAudioAnalysisCallback = emitAudioAnalysisCallback\n this.config = recordingConfig\n this.position = 0\n this.bufferSize = 0\n this.buffer = new Float32Array(0) // Initialize the buffer\n\n const audioContextFormat = this.checkAudioContextFormat({\n sampleRate: this.audioContext.sampleRate,\n })\n logger.debug('Initialized WebRecorder with config:', {\n sampleRate: audioContextFormat.sampleRate,\n bitDepth: audioContextFormat.bitDepth,\n numberOfChannels: audioContextFormat.numberOfChannels,\n })\n\n this.bitDepth = audioContextFormat.bitDepth\n this.numberOfChannels =\n audioContextFormat.numberOfChannels ||\n DEFAULT_WEB_NUMBER_OF_CHANNELS // Default to 1 if not available\n this.exportBitDepth =\n encodingToBitDepth({\n encoding: recordingConfig.encoding ?? 'pcm_32bit',\n }) ||\n audioContextFormat.bitDepth ||\n DEFAULT_WEB_BITDEPTH\n\n this.audioAnalysisData = {\n amplitudeRange: { min: 0, max: 0 },\n dataPoints: [],\n durationMs: 0,\n samples: 0,\n amplitudeAlgorithm: recordingConfig.algorithm || DEFAULT_ALGORITHM,\n bitDepth: this.bitDepth,\n numberOfChannels: this.numberOfChannels,\n sampleRate: this.config.sampleRate || this.audioContext.sampleRate,\n pointsPerSecond:\n this.config.pointsPerSecond || DEFAULT_WEB_POINTS_PER_SECOND,\n speakerChanges: [],\n }\n\n if (recordingConfig.enableProcessing) {\n this.initFeatureExtractorWorker()\n }\n }\n\n async init() {\n try {\n if (!this.audioWorkletUrl) {\n const blob = new Blob([InlineAudioWebWorker], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n await this.audioContext.audioWorklet.addModule(url)\n } else {\n await this.audioContext.audioWorklet.addModule(\n this.audioWorkletUrl\n )\n }\n this.audioWorkletNode = new AudioWorkletNode(\n this.audioContext,\n 'recorder-processor'\n )\n\n this.audioWorkletNode.port.onmessage = async (\n event: AudioWorkletEvent\n ) => {\n const command = event.data.command\n if (command !== 'newData') {\n return\n }\n // Handle the audio blob (e.g., send it to the server or process it further)\n logger.debug('Received audio blob from processor', event)\n const pcmBufferFloat = event.data.recordedData\n\n if (!pcmBufferFloat) {\n return\n }\n\n // Concatenate the incoming Float32Array to the existing buffer\n const newBuffer = new Float32Array(\n this.bufferSize + pcmBufferFloat.length\n )\n newBuffer.set(this.buffer, 0)\n newBuffer.set(pcmBufferFloat, this.bufferSize)\n this.buffer = newBuffer\n this.bufferSize += pcmBufferFloat.length\n\n const sampleRate =\n event.data.sampleRate ?? this.audioContext.sampleRate\n const duration = pcmBufferFloat.length / sampleRate // Calculate duration of the current buffer\n\n this.emitAudioEventCallback({\n data: pcmBufferFloat,\n position: this.position,\n })\n this.position += duration // Update position\n\n this.featureExtractorWorker?.postMessage(\n {\n command: 'process',\n channelData: pcmBufferFloat,\n sampleRate,\n pointsPerSecond:\n this.config.pointsPerSecond ||\n DEFAULT_WEB_POINTS_PER_SECOND,\n algorithm: this.config.algorithm || 'rms',\n bitDepth: this.bitDepth,\n fullAudioDurationMs: this.position * 1000,\n numberOfChannels: this.numberOfChannels,\n features: this.config.features,\n },\n []\n )\n }\n\n logger.debug(\n `WebRecorder initialized -- recordSampleRate=${this.audioContext.sampleRate}`,\n this.config\n )\n this.audioWorkletNode.port.postMessage({\n command: 'init',\n recordSampleRate: this.audioContext.sampleRate, // Pass the original sample rate\n exportSampleRate:\n this.config.sampleRate ?? this.audioContext.sampleRate,\n bitDepth: this.bitDepth,\n exportBitDepth: this.exportBitDepth,\n channels: this.numberOfChannels,\n interval: this.config.interval ?? DEFAULT_WEB_INTERVAL,\n })\n\n // Connect the source to the AudioWorkletNode and start recording\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n } catch (error) {\n console.error(`[${TAG}] Failed to initialize WebRecorder`, error)\n }\n }\n\n initFeatureExtractorWorker(featuresExtratorUrl?: string) {\n try {\n if (featuresExtratorUrl) {\n // Initialize the feature extractor worker\n //TODO: create audio feature extractor from a Blob instead of url since we cannot include the url directly in the library\n // We keep the url during dev and use the blob in production.\n this.featureExtractorWorker = new Worker(\n new URL(featuresExtratorUrl, window.location.href)\n )\n this.featureExtractorWorker.onmessage =\n this.handleFeatureExtractorMessage.bind(this)\n this.featureExtractorWorker.onerror =\n this.handleWorkerError.bind(this)\n } else {\n // Fallback to the inline worker if the URL is not provided\n this.initFallbackWorker()\n }\n } catch (error) {\n console.error(\n `[${TAG}] Failed to initialize feature extractor worker`,\n error\n )\n this.initFallbackWorker()\n }\n }\n\n initFallbackWorker() {\n try {\n const blob = new Blob([InlineFeaturesExtractor], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n this.featureExtractorWorker = new Worker(url)\n this.featureExtractorWorker.onmessage =\n this.handleFeatureExtractorMessage.bind(this)\n this.featureExtractorWorker.onerror = (error) => {\n console.error(`[${TAG}] Default Inline worker failed`, error)\n }\n logger.log('Inline worker initialized successfully')\n } catch (error) {\n console.error(\n `[${TAG}] Failed to initialize Inline Feature Extractor worker`,\n error\n )\n }\n }\n\n handleWorkerError(error: ErrorEvent) {\n console.error(`[${TAG}] Feature extractor worker error:`, error)\n }\n\n handleFeatureExtractorMessage(event: AudioFeaturesEvent) {\n if (event.data.command === 'features') {\n const segmentResult = event.data.result\n\n // Merge the segment result with the full audio analysis data\n this.audioAnalysisData.dataPoints.push(...segmentResult.dataPoints)\n this.audioAnalysisData.speakerChanges?.push(\n ...(segmentResult.speakerChanges ?? [])\n )\n this.audioAnalysisData.durationMs = segmentResult.durationMs\n if (segmentResult.amplitudeRange) {\n this.audioAnalysisData.amplitudeRange = {\n min: Math.min(\n this.audioAnalysisData.amplitudeRange.min,\n segmentResult.amplitudeRange.min\n ),\n max: Math.max(\n this.audioAnalysisData.amplitudeRange.max,\n segmentResult.amplitudeRange.max\n ),\n }\n }\n // Handle the extracted features (e.g., emit an event or log them)\n logger.debug('features event segmentResult', segmentResult)\n logger.debug(\n 'features event audioAnalysisData',\n this.audioAnalysisData\n )\n this.emitAudioAnalysisCallback(segmentResult)\n }\n }\n\n start() {\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n }\n\n stop(): Promise<Float32Array> {\n return new Promise((resolve, reject) => {\n try {\n if (this.audioWorkletNode) {\n // this.source.disconnect(this.audioWorkletNode);\n // this.audioWorkletNode.disconnect(this.audioContext.destination);\n this.audioWorkletNode.port.postMessage({ command: 'stop' })\n\n // Set a timeout to reject the promise if no message is received within 5 seconds\n const timeout = setTimeout(() => {\n this.audioWorkletNode.port.removeEventListener(\n 'message',\n onMessage\n )\n reject(\n new Error(\n \"Timeout error, audioWorkletNode didn't complete.\"\n )\n )\n }, 5000)\n\n // Listen for the recordedData message to confirm stopping\n const onMessage = async (event: AudioWorkletEvent) => {\n const command = event.data.command\n if (command === 'recordedData') {\n clearTimeout(timeout) // Clear the timeout\n\n const rawPCMDataFull =\n event.data.recordedData?.slice(0)\n\n if (!rawPCMDataFull) {\n reject(new Error('Failed to get recorded data'))\n return\n }\n\n // Compute duration of the recorded data\n const duration =\n rawPCMDataFull.byteLength /\n (this.audioContext.sampleRate *\n (this.exportBitDepth /\n this.numberOfChannels))\n logger.debug(\n `Received recorded data -- Duration: ${duration} vs ${rawPCMDataFull.byteLength / this.audioContext.sampleRate} seconds`\n )\n logger.debug(\n `recordedData.length=${rawPCMDataFull.byteLength} vs transmittedData.length=${this.bufferSize}`\n )\n\n // Remove the event listener after receiving the final data\n this.audioWorkletNode.port.removeEventListener(\n 'message',\n onMessage\n )\n resolve(this.buffer) // Resolve the promise with the collected buffers\n }\n }\n this.audioWorkletNode.port.addEventListener(\n 'message',\n onMessage\n )\n }\n\n // Stop all media stream tracks to stop the browser recording\n this.stopMediaStreamTracks()\n } catch (error) {\n reject(error)\n }\n })\n }\n\n pause() {\n this.source.disconnect(this.audioWorkletNode) // Disconnect the source from the AudioWorkletNode\n this.audioWorkletNode.disconnect(this.audioContext.destination) // Disconnect the AudioWorkletNode from the destination\n this.audioWorkletNode.port.postMessage({ command: 'pause' })\n }\n\n stopMediaStreamTracks() {\n // Stop all audio tracks to stop the recording icon\n const tracks = this.source.mediaStream.getTracks()\n tracks.forEach((track) => track.stop())\n }\n\n async playRecordedData({\n recordedData,\n }: {\n recordedData: ArrayBuffer\n mimeType?: string\n }) {\n try {\n const blob = new Blob([recordedData])\n const url = URL.createObjectURL(blob)\n const response = await fetch(url)\n const arrayBuffer = await response.arrayBuffer()\n\n // Decode the audio data\n const audioBuffer =\n await this.audioContext.decodeAudioData(arrayBuffer)\n\n // Create a buffer source node and play the audio\n const bufferSource = this.audioContext.createBufferSource()\n bufferSource.buffer = audioBuffer\n bufferSource.connect(this.audioContext.destination)\n bufferSource.start()\n logger.debug('Playing recorded data', recordedData)\n } catch (error) {\n console.error(`[${TAG}] Failed to play recorded data:`, error)\n }\n }\n\n private checkAudioContextFormat({ sampleRate }: { sampleRate: number }) {\n // Create a silent AudioBuffer\n const frameCount = sampleRate * 1.0 // 1 second buffer\n const audioBuffer = this.audioContext.createBuffer(\n 1,\n frameCount,\n sampleRate\n )\n\n // Check the format\n const channelData = audioBuffer.getChannelData(0)\n const bitDepth = channelData.BYTES_PER_ELEMENT * 8 // 4 bytes per element means 32-bit\n\n return {\n sampleRate: audioBuffer.sampleRate,\n bitDepth,\n numberOfChannels: audioBuffer.numberOfChannels,\n }\n }\n\n resume() {\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n this.audioWorkletNode.port.postMessage({ command: 'resume' })\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { BitDepth, SampleRate } from "./ExpoAudioStream.types";
1
+ import { BitDepth, SampleRate } from './ExpoAudioStream.types';
2
2
  export declare const isWeb: boolean;
3
3
  export declare const DEBUG_NAMESPACE = "expo-audio-stream";
4
4
  export declare const RIFF_HEADER = 1380533830;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE/D,eAAO,MAAM,KAAK,SAAwB,CAAC;AAC3C,eAAO,MAAM,eAAe,sBAAsB,CAAC;AAGnD,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,WAAW,aAAa,CAAC;AACtC,eAAO,MAAM,YAAY,aAAa,CAAC;AACvC,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,eAAO,MAAM,aAAa,aAAa,CAAC;AAGxC,eAAO,MAAM,mBAAmB,EAAE,UAAkB,CAAC;AACrD,eAAO,MAAM,iBAAiB,EAAE,QAAa,CAAC"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAE9D,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,eAAe,sBAAsB,CAAA;AAGlD,eAAO,MAAM,WAAW,aAAa,CAAA;AACrC,eAAO,MAAM,WAAW,aAAa,CAAA;AACrC,eAAO,MAAM,YAAY,aAAa,CAAA;AACtC,eAAO,MAAM,aAAa,aAAa,CAAA;AACvC,eAAO,MAAM,aAAa,aAAa,CAAA;AAGvC,eAAO,MAAM,mBAAmB,EAAE,UAAkB,CAAA;AACpD,eAAO,MAAM,iBAAiB,EAAE,QAAa,CAAA"}
@@ -1,7 +1,7 @@
1
1
  // packages/expo-audio-stream/src/constants.ts
2
- import { Platform } from "react-native";
3
- export const isWeb = Platform.OS === "web";
4
- export const DEBUG_NAMESPACE = "expo-audio-stream";
2
+ import { Platform } from 'react-native';
3
+ export const isWeb = Platform.OS === 'web';
4
+ export const DEBUG_NAMESPACE = 'expo-audio-stream';
5
5
  // Constants for identifying chunks in a WAV file
6
6
  export const RIFF_HEADER = 0x52494646; // "RIFF"
7
7
  export const WAVE_HEADER = 0x57415645; // "WAVE"
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAIxC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAC;AAC3C,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAEnD,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,SAAS;AAChD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC,CAAC,SAAS;AAChD,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC,CAAC,SAAS;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,SAAS;AAClD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC,CAAC,SAAS;AAElD,iBAAiB;AACjB,MAAM,CAAC,MAAM,mBAAmB,GAAe,KAAK,CAAC;AACrD,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAC","sourcesContent":["// packages/expo-audio-stream/src/constants.ts\nimport { Platform } from \"react-native\";\n\nimport { BitDepth, SampleRate } from \"./ExpoAudioStream.types\";\n\nexport const isWeb = Platform.OS === \"web\";\nexport const DEBUG_NAMESPACE = \"expo-audio-stream\";\n\n// Constants for identifying chunks in a WAV file\nexport const RIFF_HEADER = 0x52494646; // \"RIFF\"\nexport const WAVE_HEADER = 0x57415645; // \"WAVE\"\nexport const FMT_CHUNK_ID = 0x666d7420; // \"fmt \"\nexport const DATA_CHUNK_ID = 0x64617461; // \"data\"\nexport const INFO_CHUNK_ID = 0x494e464f; // \"INFO\"\n\n// Default values\nexport const DEFAULT_SAMPLE_RATE: SampleRate = 16000;\nexport const DEFAULT_BIT_DEPTH: BitDepth = 32;\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIvC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAA;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,mBAAmB,CAAA;AAElD,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA,CAAC,SAAS;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA,CAAC,SAAS;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAA,CAAC,SAAS;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAA,CAAC,SAAS;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAA,CAAC,SAAS;AAEjD,iBAAiB;AACjB,MAAM,CAAC,MAAM,mBAAmB,GAAe,KAAK,CAAA;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAA","sourcesContent":["// packages/expo-audio-stream/src/constants.ts\nimport { Platform } from 'react-native'\n\nimport { BitDepth, SampleRate } from './ExpoAudioStream.types'\n\nexport const isWeb = Platform.OS === 'web'\nexport const DEBUG_NAMESPACE = 'expo-audio-stream'\n\n// Constants for identifying chunks in a WAV file\nexport const RIFF_HEADER = 0x52494646 // \"RIFF\"\nexport const WAVE_HEADER = 0x57415645 // \"WAVE\"\nexport const FMT_CHUNK_ID = 0x666d7420 // \"fmt \"\nexport const DATA_CHUNK_ID = 0x64617461 // \"data\"\nexport const INFO_CHUNK_ID = 0x494e464f // \"INFO\"\n\n// Default values\nexport const DEFAULT_SAMPLE_RATE: SampleRate = 16000\nexport const DEFAULT_BIT_DEPTH: BitDepth = 32\n"]}
package/build/events.d.ts CHANGED
@@ -1,6 +1,18 @@
1
- import { type Subscription } from "expo-modules-core";
2
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
3
- import { AudioEventPayload } from "./ExpoAudioStream.types";
1
+ import { type Subscription } from 'expo-modules-core';
2
+ import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
3
+ export interface AudioEventPayload {
4
+ encoded?: string;
5
+ buffer?: Float32Array;
6
+ fileUri: string;
7
+ lastEmittedSize: number;
8
+ position: number;
9
+ deltaSize: number;
10
+ totalSize: number;
11
+ mimeType: string;
12
+ streamUuid: string;
13
+ }
4
14
  export declare function addAudioEventListener(listener: (event: AudioEventPayload) => Promise<void>): Subscription;
5
- export declare function addAudioAnalysisListener(listener: (event: AudioAnalysisData) => Promise<void>): Subscription;
15
+ export interface AudioAnalysisEvent extends AudioAnalysis {
16
+ }
17
+ export declare function addAudioAnalysisListener(listener: (event: AudioAnalysisEvent) => Promise<void>): Subscription;
6
18
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAO5D,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,GACpD,YAAY,CAGd;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,GACpD,YAAY,CAGd"}
1
+ {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEnE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAOnE,MAAM,WAAW,iBAAiB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;CACrB;AAED,wBAAgB,qBAAqB,CACjC,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,GACtD,YAAY,CAGd;AAGD,MAAM,WAAW,kBAAmB,SAAQ,aAAa;CAAG;AAE5D,wBAAgB,wBAAwB,CACpC,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GACvD,YAAY,CAGd"}
package/build/events.js CHANGED
@@ -1,15 +1,15 @@
1
1
  // packages/expo-audio-stream/src/events.ts
2
- import { EventEmitter } from "expo-modules-core";
3
- import ExpoAudioStreamModule from "./ExpoAudioStreamModule";
4
- import { getLogger } from "./logger";
2
+ import { EventEmitter } from 'expo-modules-core';
3
+ import ExpoAudioStreamModule from './ExpoAudioStreamModule';
4
+ import { getLogger } from './logger';
5
5
  const emitter = new EventEmitter(ExpoAudioStreamModule);
6
- const logger = getLogger("events");
6
+ const logger = getLogger('events');
7
7
  export function addAudioEventListener(listener) {
8
- logger.log("Adding listener for AudioData event");
9
- return emitter.addListener("AudioData", listener);
8
+ logger.log('Adding listener for AudioData event');
9
+ return emitter.addListener('AudioData', listener);
10
10
  }
11
11
  export function addAudioAnalysisListener(listener) {
12
- logger.log("Adding listener for AudioAnalysis event");
13
- return emitter.addListener("AudioAnalysis", listener);
12
+ logger.log('Adding listener for AudioAnalysis event');
13
+ return emitter.addListener('AudioAnalysis', listener);
14
14
  }
15
15
  //# sourceMappingURL=events.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAC;AAIpE,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,qBAAqB,CAAC,CAAC;AACxD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAEnC,MAAM,UAAU,qBAAqB,CACnC,QAAqD;IAErD,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAC;IAClD,OAAO,OAAO,CAAC,WAAW,CAAoB,WAAW,EAAE,QAAQ,CAAC,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,wBAAwB,CACtC,QAAqD;IAErD,MAAM,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;IACtD,OAAO,OAAO,CAAC,WAAW,CAAoB,eAAe,EAAE,QAAQ,CAAC,CAAC;AAC3E,CAAC","sourcesContent":["// packages/expo-audio-stream/src/events.ts\n\nimport { EventEmitter, type Subscription } from \"expo-modules-core\";\n\nimport { AudioAnalysisData } from \"./AudioAnalysis/AudioAnalysis.types\";\nimport { AudioEventPayload } from \"./ExpoAudioStream.types\";\nimport ExpoAudioStreamModule from \"./ExpoAudioStreamModule\";\nimport { getLogger } from \"./logger\";\n\nconst emitter = new EventEmitter(ExpoAudioStreamModule);\nconst logger = getLogger(\"events\");\n\nexport function addAudioEventListener(\n listener: (event: AudioEventPayload) => Promise<void>,\n): Subscription {\n logger.log(\"Adding listener for AudioData event\");\n return emitter.addListener<AudioEventPayload>(\"AudioData\", listener);\n}\n\nexport function addAudioAnalysisListener(\n listener: (event: AudioAnalysisData) => Promise<void>,\n): Subscription {\n logger.log(\"Adding listener for AudioAnalysis event\");\n return emitter.addListener<AudioAnalysisData>(\"AudioAnalysis\", listener);\n}\n"]}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,YAAY,EAAqB,MAAM,mBAAmB,CAAA;AAGnE,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,MAAM,OAAO,GAAG,IAAI,YAAY,CAAC,qBAAqB,CAAC,CAAA;AACvD,MAAM,MAAM,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;AAclC,MAAM,UAAU,qBAAqB,CACjC,QAAqD;IAErD,MAAM,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;IACjD,OAAO,OAAO,CAAC,WAAW,CAAoB,WAAW,EAAE,QAAQ,CAAC,CAAA;AACxE,CAAC;AAKD,MAAM,UAAU,wBAAwB,CACpC,QAAsD;IAEtD,MAAM,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAA;IACrD,OAAO,OAAO,CAAC,WAAW,CAAqB,eAAe,EAAE,QAAQ,CAAC,CAAA;AAC7E,CAAC","sourcesContent":["// packages/expo-audio-stream/src/events.ts\n\nimport { EventEmitter, type Subscription } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\nimport { getLogger } from './logger'\n\nconst emitter = new EventEmitter(ExpoAudioStreamModule)\nconst logger = getLogger('events')\n\nexport interface AudioEventPayload {\n encoded?: string\n buffer?: Float32Array\n fileUri: string\n lastEmittedSize: number\n position: number\n deltaSize: number\n totalSize: number\n mimeType: string\n streamUuid: string\n}\n\nexport function addAudioEventListener(\n listener: (event: AudioEventPayload) => Promise<void>\n): Subscription {\n logger.log('Adding listener for AudioData event')\n return emitter.addListener<AudioEventPayload>('AudioData', listener)\n}\n\n// Only aliasing the AudioAnalysis type for the event payload\nexport interface AudioAnalysisEvent extends AudioAnalysis {}\n\nexport function addAudioAnalysisListener(\n listener: (event: AudioAnalysisEvent) => Promise<void>\n): Subscription {\n logger.log('Adding listener for AudioAnalysis event')\n return emitter.addListener<AudioAnalysisEvent>('AudioAnalysis', listener)\n}\n"]}
package/build/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { extractAudioAnalysis } from "./AudioAnalysis/extractAudioAnalysis";
2
- import { AudioRecorderProvider, useSharedAudioRecorder } from "./AudioRecorder.provider";
3
- import { useAudioRecorder } from "./useAudioRecorder";
4
- export * from "./utils/getWavFileInfo";
5
- export * from "./utils/convertPCMToFloat32";
6
- export * from "./utils/writeWavHeader";
1
+ import { extractAudioAnalysis } from './AudioAnalysis/extractAudioAnalysis';
2
+ import { AudioRecorderProvider, useSharedAudioRecorder } from './AudioRecorder.provider';
3
+ import { useAudioRecorder } from './useAudioRecorder';
4
+ export * from './utils/getWavFileInfo';
5
+ export * from './utils/convertPCMToFloat32';
6
+ export * from './utils/writeWavHeader';
7
7
  export { AudioRecorderProvider, extractAudioAnalysis, useAudioRecorder, useSharedAudioRecorder, };
8
- export type * from "./AudioAnalysis/AudioAnalysis.types";
9
- export type * from "./ExpoAudioStream.types";
8
+ export type * from './AudioAnalysis/AudioAnalysis.types';
9
+ export type * from './ExpoAudioStream.types';
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACvB,CAAC;AAEF,mBAAmB,qCAAqC,CAAC;AACzD,mBAAmB,yBAAyB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAC3E,OAAO,EACH,qBAAqB,EACrB,sBAAsB,EACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AAEtC,OAAO,EACH,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACzB,CAAA;AAED,mBAAmB,qCAAqC,CAAA;AACxD,mBAAmB,yBAAyB,CAAA"}
package/build/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // src/index.ts
2
- import { extractAudioAnalysis } from "./AudioAnalysis/extractAudioAnalysis";
3
- import { AudioRecorderProvider, useSharedAudioRecorder, } from "./AudioRecorder.provider";
4
- import { useAudioRecorder } from "./useAudioRecorder";
5
- export * from "./utils/getWavFileInfo";
6
- export * from "./utils/convertPCMToFloat32";
7
- export * from "./utils/writeWavHeader";
2
+ import { extractAudioAnalysis } from './AudioAnalysis/extractAudioAnalysis';
3
+ import { AudioRecorderProvider, useSharedAudioRecorder, } from './AudioRecorder.provider';
4
+ import { useAudioRecorder } from './useAudioRecorder';
5
+ export * from './utils/getWavFileInfo';
6
+ export * from './utils/convertPCMToFloat32';
7
+ export * from './utils/writeWavHeader';
8
8
  export { AudioRecorderProvider, extractAudioAnalysis, useAudioRecorder, useSharedAudioRecorder, };
9
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,cAAc,wBAAwB,CAAC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AAEvC,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACvB,CAAC","sourcesContent":["// src/index.ts\n\nimport { extractAudioAnalysis } from \"./AudioAnalysis/extractAudioAnalysis\";\nimport {\n AudioRecorderProvider,\n useSharedAudioRecorder,\n} from \"./AudioRecorder.provider\";\nimport { useAudioRecorder } from \"./useAudioRecorder\";\n\nexport * from \"./utils/getWavFileInfo\";\nexport * from \"./utils/convertPCMToFloat32\";\nexport * from \"./utils/writeWavHeader\";\n\nexport {\n AudioRecorderProvider,\n extractAudioAnalysis,\n useAudioRecorder,\n useSharedAudioRecorder,\n};\n\nexport type * from \"./AudioAnalysis/AudioAnalysis.types\";\nexport type * from \"./ExpoAudioStream.types\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAA;AAC3E,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,cAAc,wBAAwB,CAAA;AACtC,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AAEtC,OAAO,EACH,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,GACzB,CAAA","sourcesContent":["// src/index.ts\n\nimport { extractAudioAnalysis } from './AudioAnalysis/extractAudioAnalysis'\nimport {\n AudioRecorderProvider,\n useSharedAudioRecorder,\n} from './AudioRecorder.provider'\nimport { useAudioRecorder } from './useAudioRecorder'\n\nexport * from './utils/getWavFileInfo'\nexport * from './utils/convertPCMToFloat32'\nexport * from './utils/writeWavHeader'\n\nexport {\n AudioRecorderProvider,\n extractAudioAnalysis,\n useAudioRecorder,\n useSharedAudioRecorder,\n}\n\nexport type * from './AudioAnalysis/AudioAnalysis.types'\nexport type * from './ExpoAudioStream.types'\n"]}
package/build/logger.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  type ConsoleLike = {
2
2
  log: (message: string, ...args: unknown[]) => void;
3
3
  debug: (message: string, ...args: unknown[]) => void;
4
+ warn: (message: string, ...args: unknown[]) => void;
5
+ error: (message: string, ...args: unknown[]) => void;
4
6
  };
5
7
  export declare const getLogger: (tag: string) => ConsoleLike;
6
- export declare const enableAllLoggers: () => void;
7
- export declare const disableAllLoggers: () => void;
8
8
  export {};
9
9
  //# sourceMappingURL=logger.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACnD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACtD,CAAC;AAEF,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,WAOvC,CAAC;AAEF,eAAO,MAAM,gBAAgB,YAE5B,CAAC;AAEF,eAAO,MAAM,iBAAiB,YAE7B,CAAC"}
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,KAAK,WAAW,GAAG;IACf,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;IAClD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;IACpD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;IACnD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAA;CACvD,CAAA;AAED,eAAO,MAAM,SAAS,QAAS,MAAM,KAAG,WASvC,CAAA"}
package/build/logger.js CHANGED
@@ -1,17 +1,13 @@
1
1
  // packages/expo-audio-stream/src/logger.ts
2
- import createDebug from "debug";
3
- import { DEBUG_NAMESPACE } from "./constants";
2
+ import { getLogger as siteedGetLogger } from '@siteed/react-native-logger';
3
+ import { DEBUG_NAMESPACE } from './constants';
4
4
  export const getLogger = (tag) => {
5
- const baseLogger = createDebug(`${DEBUG_NAMESPACE}:${tag}`);
5
+ const baseLogger = siteedGetLogger(`${DEBUG_NAMESPACE}:${tag}`);
6
6
  return {
7
- log: (...args) => baseLogger(...args),
8
- debug: (...args) => baseLogger(...args),
7
+ log: (...args) => baseLogger.log(...args),
8
+ debug: (...args) => baseLogger.debug(...args),
9
+ error: (...args) => baseLogger.error(...args),
10
+ warn: (...args) => baseLogger.warn(...args),
9
11
  };
10
12
  };
11
- export const enableAllLoggers = () => {
12
- createDebug.enable(`${DEBUG_NAMESPACE}:*`);
13
- };
14
- export const disableAllLoggers = () => {
15
- createDebug.disable();
16
- };
17
13
  //# sourceMappingURL=logger.js.map