@siteed/expo-audio-stream 1.0.3 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/README.md +26 -175
  2. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
  3. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
  4. package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
  5. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
  6. package/build/index.js +8 -7
  7. package/ios/AudioProcessor.swift +7 -5
  8. package/ios/AudioStreamManager.swift +1 -0
  9. package/ios/ExpoAudioStream.podspec +1 -1
  10. package/ios/ExpoAudioStreamModule.swift +36 -0
  11. package/ios/RecordingResult.swift +1 -0
  12. package/package.json +95 -65
  13. package/src/AudioAnalysis/AudioAnalysis.types.ts +59 -60
  14. package/src/AudioAnalysis/extractAudioAnalysis.ts +132 -121
  15. package/src/AudioAnalysis/extractWaveform.ts +18 -18
  16. package/src/AudioRecorder.provider.tsx +53 -53
  17. package/src/ExpoAudioStream.native.ts +2 -2
  18. package/src/ExpoAudioStream.types.ts +59 -53
  19. package/src/ExpoAudioStream.web.ts +231 -205
  20. package/src/ExpoAudioStreamModule.ts +22 -15
  21. package/src/WebRecorder.web.ts +407 -390
  22. package/src/constants.ts +11 -11
  23. package/src/events.ts +27 -13
  24. package/src/index.ts +17 -15
  25. package/src/logger.ts +15 -19
  26. package/src/useAudioRecorder.tsx +394 -389
  27. package/src/utils/BlobFix.ts +550 -0
  28. package/src/utils/concatenateBuffers.ts +24 -0
  29. package/src/utils/convertPCMToFloat32.ts +72 -45
  30. package/src/utils/encodingToBitDepth.ts +14 -14
  31. package/src/utils/getWavFileInfo.ts +106 -99
  32. package/src/utils/writeWavHeader.ts +50 -45
  33. package/src/workers/InlineFeaturesExtractor.web.tsx +296 -286
  34. package/src/workers/inlineAudioWebWorker.web.tsx +230 -222
  35. package/.eslintrc.js +0 -2
  36. package/.size-limit.json +0 -6
  37. package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  39. package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
  40. package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
  41. package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
  42. package/android/.gradle/8.1.1/gc.properties +0 -0
  43. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  44. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  45. package/android/.gradle/vcs-1/gc.properties +0 -0
  46. package/app.plugin.js +0 -1
  47. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -76
  48. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  49. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  50. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  51. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -4
  52. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  53. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -101
  54. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  55. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  56. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  57. package/build/AudioAnalysis/extractWaveform.js +0 -14
  58. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  59. package/build/AudioRecorder.provider.d.ts +0 -23
  60. package/build/AudioRecorder.provider.d.ts.map +0 -1
  61. package/build/AudioRecorder.provider.js +0 -36
  62. package/build/AudioRecorder.provider.js.map +0 -1
  63. package/build/ExpoAudioStream.native.d.ts +0 -3
  64. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  65. package/build/ExpoAudioStream.native.js +0 -6
  66. package/build/ExpoAudioStream.native.js.map +0 -1
  67. package/build/ExpoAudioStream.types.d.ts +0 -60
  68. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  69. package/build/ExpoAudioStream.types.js +0 -2
  70. package/build/ExpoAudioStream.types.js.map +0 -1
  71. package/build/ExpoAudioStream.web.d.ts +0 -42
  72. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  73. package/build/ExpoAudioStream.web.js +0 -185
  74. package/build/ExpoAudioStream.web.js.map +0 -1
  75. package/build/ExpoAudioStreamModule.d.ts +0 -3
  76. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  77. package/build/ExpoAudioStreamModule.js +0 -18
  78. package/build/ExpoAudioStreamModule.js.map +0 -1
  79. package/build/WebRecorder.web.d.ts +0 -51
  80. package/build/WebRecorder.web.d.ts.map +0 -1
  81. package/build/WebRecorder.web.js +0 -288
  82. package/build/WebRecorder.web.js.map +0 -1
  83. package/build/constants.d.ts +0 -11
  84. package/build/constants.d.ts.map +0 -1
  85. package/build/constants.js +0 -14
  86. package/build/constants.js.map +0 -1
  87. package/build/events.d.ts +0 -6
  88. package/build/events.d.ts.map +0 -1
  89. package/build/events.js +0 -15
  90. package/build/events.js.map +0 -1
  91. package/build/index.d.ts +0 -10
  92. package/build/index.d.ts.map +0 -1
  93. package/build/index.js.map +0 -1
  94. package/build/logger.d.ts +0 -9
  95. package/build/logger.d.ts.map +0 -1
  96. package/build/logger.js +0 -17
  97. package/build/logger.js.map +0 -1
  98. package/build/useAudioRecorder.d.ts +0 -37
  99. package/build/useAudioRecorder.d.ts.map +0 -1
  100. package/build/useAudioRecorder.js +0 -271
  101. package/build/useAudioRecorder.js.map +0 -1
  102. package/build/utils/convertPCMToFloat32.d.ts +0 -11
  103. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  104. package/build/utils/convertPCMToFloat32.js +0 -41
  105. package/build/utils/convertPCMToFloat32.js.map +0 -1
  106. package/build/utils/encodingToBitDepth.d.ts +0 -5
  107. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  108. package/build/utils/encodingToBitDepth.js +0 -13
  109. package/build/utils/encodingToBitDepth.js.map +0 -1
  110. package/build/utils/getWavFileInfo.d.ts +0 -25
  111. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  112. package/build/utils/getWavFileInfo.js +0 -89
  113. package/build/utils/getWavFileInfo.js.map +0 -1
  114. package/build/utils/writeWavHeader.d.ts +0 -9
  115. package/build/utils/writeWavHeader.d.ts.map +0 -1
  116. package/build/utils/writeWavHeader.js +0 -41
  117. package/build/utils/writeWavHeader.js.map +0 -1
  118. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  119. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  120. package/build/workers/InlineFeaturesExtractor.web.js +0 -303
  121. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  122. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  123. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  124. package/build/workers/inlineAudioWebWorker.web.js +0 -243
  125. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  126. package/expo-module.config.json +0 -18
  127. package/plugin/build/index.d.ts +0 -5
  128. package/plugin/build/index.js +0 -28
  129. package/plugin/src/index.ts +0 -53
  130. package/plugin/tsconfig.json +0 -14
  131. package/publish.sh +0 -8
  132. package/tsconfig.json +0 -9
@@ -1,51 +0,0 @@
1
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
2
- import { RecordingConfig } from "./ExpoAudioStream.types";
3
- import { EmitAudioAnalysisFunction, EmitAudioEventFunction } from "./ExpoAudioStream.web";
4
- interface AudioFeaturesEvent {
5
- data: {
6
- command: string;
7
- result: AudioAnalysisData;
8
- };
9
- }
10
- export declare class WebRecorder {
11
- private audioContext;
12
- private audioWorkletNode;
13
- private featureExtractorWorker?;
14
- private source;
15
- private audioWorkletUrl;
16
- private emitAudioEventCallback;
17
- private emitAudioAnalysisCallback;
18
- private config;
19
- private position;
20
- private numberOfChannels;
21
- private bitDepth;
22
- private exportBitDepth;
23
- private buffers;
24
- private audioAnalysisData;
25
- constructor({ audioContext, source, recordingConfig, featuresExtratorUrl, audioWorkletUrl, emitAudioEventCallback, emitAudioAnalysisCallback, }: {
26
- audioContext: AudioContext;
27
- source: MediaStreamAudioSourceNode;
28
- recordingConfig: RecordingConfig;
29
- featuresExtratorUrl: string;
30
- audioWorkletUrl: string;
31
- emitAudioEventCallback: EmitAudioEventFunction;
32
- emitAudioAnalysisCallback: EmitAudioAnalysisFunction;
33
- });
34
- init(): Promise<void>;
35
- initFeatureExtractorWorker(featuresExtratorUrl?: string): void;
36
- initFallbackWorker(): void;
37
- handleWorkerError(error: ErrorEvent): void;
38
- handleFeatureExtractorMessage(event: AudioFeaturesEvent): void;
39
- start(): void;
40
- stop(): Promise<unknown>;
41
- pause(): void;
42
- stopMediaStreamTracks(): void;
43
- playRecordedData({ recordedData, }: {
44
- recordedData: ArrayBuffer;
45
- mimeType?: string;
46
- }): Promise<void>;
47
- private checkAudioContextFormat;
48
- resume(): void;
49
- }
50
- export {};
51
- //# sourceMappingURL=WebRecorder.web.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"WebRecorder.web.d.ts","sourceRoot":"","sources":["../src/WebRecorder.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAc/B,UAAU,kBAAkB;IAC1B,IAAI,EAAE;QACJ,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,iBAAiB,CAAC;KAC3B,CAAC;CACH;AAUD,qBAAa,WAAW;IACtB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,sBAAsB,CAAC,CAAS;IACxC,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,sBAAsB,CAAyB;IACvD,OAAO,CAAC,yBAAyB,CAA4B;IAC7D,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,gBAAgB,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,OAAO,CAAgB;IAC/B,OAAO,CAAC,iBAAiB,CAAoB;gBAEjC,EACV,YAAY,EACZ,MAAM,EACN,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,sBAAsB,EACtB,yBAAyB,GAC1B,EAAE;QACD,YAAY,EAAE,YAAY,CAAC;QAC3B,MAAM,EAAE,0BAA0B,CAAC;QACnC,eAAe,EAAE,eAAe,CAAC;QACjC,mBAAmB,EAAE,MAAM,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;QACxB,sBAAsB,EAAE,sBAAsB,CAAC;QAC/C,yBAAyB,EAAE,yBAAyB,CAAC;KACtD;IA+CK,IAAI;IA8FV,0BAA0B,CAAC,mBAAmB,CAAC,EAAE,MAAM;IAyBvD,kBAAkB;IAqBlB,iBAAiB,CAAC,KAAK,EAAE,UAAU;IAInC,6BAA6B,CAAC,KAAK,EAAE,kBAAkB;IA6BvD,KAAK;IAKL,IAAI;IA4DJ,KAAK;IAML,qBAAqB;IAMf,gBAAgB,CAAC,EACrB,YAAY,GACb,EAAE;QACD,YAAY,EAAE,WAAW,CAAC;QAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAqBD,OAAO,CAAC,uBAAuB;IAoB/B,MAAM;CAKP"}
@@ -1,288 +0,0 @@
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
- const DEFAULT_WEB_BITDEPTH = 32;
6
- const DEFAULT_WEB_POINTS_PER_SECOND = 10;
7
- const DEFAULT_WEB_INTERVAL = 500;
8
- const DEFAULT_WEB_NUMBER_OF_CHANNELS = 1;
9
- const TAG = "WebRecorder";
10
- const logger = getLogger(TAG);
11
- export class WebRecorder {
12
- audioContext;
13
- audioWorkletNode;
14
- featureExtractorWorker;
15
- source;
16
- audioWorkletUrl;
17
- emitAudioEventCallback;
18
- emitAudioAnalysisCallback;
19
- config;
20
- position; // Track the cumulative position
21
- numberOfChannels; // Number of audio channels
22
- bitDepth; // Bit depth of the audio
23
- exportBitDepth; // Bit depth of the audio
24
- buffers; // Array to store the buffers
25
- audioAnalysisData; // Keep updating the full audio analysis data with latest events
26
- constructor({ audioContext, source, recordingConfig, featuresExtratorUrl, audioWorkletUrl, emitAudioEventCallback, emitAudioAnalysisCallback, }) {
27
- this.audioContext = audioContext;
28
- this.source = source;
29
- this.audioWorkletUrl = audioWorkletUrl;
30
- this.emitAudioEventCallback = emitAudioEventCallback;
31
- this.emitAudioAnalysisCallback = emitAudioAnalysisCallback;
32
- this.config = recordingConfig;
33
- this.position = 0;
34
- this.buffers = []; // Initialize the buffers array
35
- const audioContextFormat = this.checkAudioContextFormat({
36
- sampleRate: this.audioContext.sampleRate,
37
- });
38
- logger.debug("Initialized WebRecorder with config:", {
39
- sampleRate: audioContextFormat.sampleRate,
40
- bitDepth: audioContextFormat.bitDepth,
41
- numberOfChannels: audioContextFormat.numberOfChannels,
42
- });
43
- this.bitDepth = audioContextFormat.bitDepth;
44
- this.numberOfChannels =
45
- audioContextFormat.numberOfChannels || DEFAULT_WEB_NUMBER_OF_CHANNELS; // Default to 1 if not available
46
- this.exportBitDepth =
47
- encodingToBitDepth({
48
- encoding: recordingConfig.encoding ?? "pcm_32bit",
49
- }) ||
50
- audioContextFormat.bitDepth ||
51
- DEFAULT_WEB_BITDEPTH;
52
- this.audioAnalysisData = {
53
- amplitudeRange: { min: 0, max: 0 },
54
- dataPoints: [],
55
- durationMs: 0,
56
- samples: 0,
57
- bitDepth: this.bitDepth,
58
- numberOfChannels: this.numberOfChannels,
59
- sampleRate: this.config.sampleRate || this.audioContext.sampleRate,
60
- pointsPerSecond: this.config.pointsPerSecond || DEFAULT_WEB_POINTS_PER_SECOND,
61
- speakerChanges: [],
62
- };
63
- if (recordingConfig.enableProcessing) {
64
- this.initFeatureExtractorWorker();
65
- }
66
- }
67
- async init() {
68
- try {
69
- if (!this.audioWorkletUrl) {
70
- const blob = new Blob([InlineAudioWebWorker], {
71
- type: "application/javascript",
72
- });
73
- const url = URL.createObjectURL(blob);
74
- await this.audioContext.audioWorklet.addModule(url);
75
- }
76
- else {
77
- await this.audioContext.audioWorklet.addModule(this.audioWorkletUrl);
78
- }
79
- this.audioWorkletNode = new AudioWorkletNode(this.audioContext, "recorder-processor");
80
- this.audioWorkletNode.port.onmessage = async (event) => {
81
- const command = event.data.command;
82
- if (command !== "newData") {
83
- return;
84
- }
85
- // 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) {
89
- return;
90
- }
91
- this.buffers.push(pcmBuffer); // Store the buffer
92
- 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}`);
101
- this.emitAudioEventCallback({
102
- data: pcmBuffer,
103
- position: this.position,
104
- });
105
- this.position += duration; // Update position
106
- 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",
112
- bitDepth: this.bitDepth,
113
- fullAudioDurationMs: this.position * 1000,
114
- numberOfChannels: this.numberOfChannels,
115
- features: this.config.features,
116
- }, []);
117
- };
118
- logger.debug(`WebRecorder initialized -- recordSampleRate=${this.audioContext.sampleRate}`, this.config);
119
- this.audioWorkletNode.port.postMessage({
120
- command: "init",
121
- recordSampleRate: this.audioContext.sampleRate, // Pass the original sample rate
122
- exportSampleRate: this.config.sampleRate ?? this.audioContext.sampleRate,
123
- bitDepth: this.bitDepth,
124
- exportBitDepth: this.exportBitDepth,
125
- channels: this.numberOfChannels,
126
- interval: this.config.interval ?? DEFAULT_WEB_INTERVAL,
127
- });
128
- // Connect the source to the AudioWorkletNode and start recording
129
- this.source.connect(this.audioWorkletNode);
130
- this.audioWorkletNode.connect(this.audioContext.destination);
131
- }
132
- catch (error) {
133
- console.error(`[${TAG}] Failed to initialize WebRecorder`, error);
134
- }
135
- }
136
- initFeatureExtractorWorker(featuresExtratorUrl) {
137
- try {
138
- if (featuresExtratorUrl) {
139
- // Initialize the feature extractor worker
140
- //TODO: create audio feature extractor from a Blob instead of url since we cannot include the url directly in the library
141
- // We keep the url during dev and use the blob in production.
142
- this.featureExtractorWorker = new Worker(new URL(featuresExtratorUrl, window.location.href));
143
- this.featureExtractorWorker.onmessage =
144
- this.handleFeatureExtractorMessage.bind(this);
145
- this.featureExtractorWorker.onerror = this.handleWorkerError.bind(this);
146
- }
147
- else {
148
- // Fallback to the inline worker if the URL is not provided
149
- this.initFallbackWorker();
150
- }
151
- }
152
- catch (error) {
153
- console.error(`[${TAG}] Failed to initialize feature extractor worker`, error);
154
- this.initFallbackWorker();
155
- }
156
- }
157
- initFallbackWorker() {
158
- try {
159
- const blob = new Blob([InlineFeaturesExtractor], {
160
- type: "application/javascript",
161
- });
162
- const url = URL.createObjectURL(blob);
163
- this.featureExtractorWorker = new Worker(url);
164
- this.featureExtractorWorker.onmessage =
165
- this.handleFeatureExtractorMessage.bind(this);
166
- this.featureExtractorWorker.onerror = (error) => {
167
- console.error(`[${TAG}] Default Inline worker failed`, error);
168
- };
169
- logger.log("Inline worker initialized successfully");
170
- }
171
- catch (error) {
172
- console.error(`[${TAG}] Failed to initialize Inline Feature Extractor worker`, error);
173
- }
174
- }
175
- handleWorkerError(error) {
176
- console.error(`[${TAG}] Feature extractor worker error:`, error);
177
- }
178
- handleFeatureExtractorMessage(event) {
179
- if (event.data.command === "features") {
180
- const segmentResult = event.data.result;
181
- // Merge the segment result with the full audio analysis data
182
- this.audioAnalysisData.dataPoints.push(...segmentResult.dataPoints);
183
- this.audioAnalysisData.speakerChanges?.push(...(segmentResult.speakerChanges ?? []));
184
- this.audioAnalysisData.durationMs = segmentResult.durationMs;
185
- if (segmentResult.amplitudeRange) {
186
- this.audioAnalysisData.amplitudeRange = {
187
- min: Math.min(this.audioAnalysisData.amplitudeRange.min, segmentResult.amplitudeRange.min),
188
- max: Math.max(this.audioAnalysisData.amplitudeRange.max, segmentResult.amplitudeRange.max),
189
- };
190
- }
191
- // 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);
194
- this.emitAudioAnalysisCallback(segmentResult);
195
- }
196
- }
197
- start() {
198
- this.source.connect(this.audioWorkletNode);
199
- this.audioWorkletNode.connect(this.audioContext.destination);
200
- }
201
- stop() {
202
- return new Promise((resolve, reject) => {
203
- try {
204
- if (this.audioWorkletNode) {
205
- // this.source.disconnect(this.audioWorkletNode);
206
- // this.audioWorkletNode.disconnect(this.audioContext.destination);
207
- this.audioWorkletNode.port.postMessage({ command: "stop" });
208
- // Set a timeout to reject the promise if no message is received within 5 seconds
209
- const timeout = setTimeout(() => {
210
- this.audioWorkletNode.port.removeEventListener("message", onMessage);
211
- reject(new Error("Timeout error, audioWorkletNode didn't complete."));
212
- }, 5000);
213
- // Listen for the recordedData message to confirm stopping
214
- const onMessage = async (event) => {
215
- const command = event.data.command;
216
- if (command === "recordedData") {
217
- clearTimeout(timeout); // Clear the timeout
218
- const rawPCMDataFull = event.data.recordedData?.slice(0);
219
- // Compute duration of the recorded data
220
- const duration = rawPCMDataFull.byteLength /
221
- (this.audioContext.sampleRate *
222
- (this.exportBitDepth / this.numberOfChannels));
223
- 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}`);
225
- // 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
228
- }
229
- };
230
- this.audioWorkletNode.port.addEventListener("message", onMessage);
231
- }
232
- // Stop all media stream tracks to stop the browser recording
233
- this.stopMediaStreamTracks();
234
- }
235
- catch (error) {
236
- reject(error);
237
- }
238
- });
239
- }
240
- pause() {
241
- this.source.disconnect(this.audioWorkletNode); // Disconnect the source from the AudioWorkletNode
242
- this.audioWorkletNode.disconnect(this.audioContext.destination); // Disconnect the AudioWorkletNode from the destination
243
- this.audioWorkletNode.port.postMessage({ command: "pause" });
244
- }
245
- stopMediaStreamTracks() {
246
- // Stop all audio tracks to stop the recording icon
247
- const tracks = this.source.mediaStream.getTracks();
248
- tracks.forEach((track) => track.stop());
249
- }
250
- async playRecordedData({ recordedData, }) {
251
- try {
252
- const blob = new Blob([recordedData]);
253
- const url = URL.createObjectURL(blob);
254
- const response = await fetch(url);
255
- const arrayBuffer = await response.arrayBuffer();
256
- // Decode the audio data
257
- const audioBuffer = await this.audioContext.decodeAudioData(arrayBuffer);
258
- // Create a buffer source node and play the audio
259
- const bufferSource = this.audioContext.createBufferSource();
260
- bufferSource.buffer = audioBuffer;
261
- bufferSource.connect(this.audioContext.destination);
262
- bufferSource.start();
263
- logger.debug("Playing recorded data", recordedData);
264
- }
265
- catch (error) {
266
- console.error(`[${TAG}] Failed to play recorded data:`, error);
267
- }
268
- }
269
- checkAudioContextFormat({ sampleRate }) {
270
- // Create a silent AudioBuffer
271
- const frameCount = sampleRate * 1.0; // 1 second buffer
272
- const audioBuffer = this.audioContext.createBuffer(1, frameCount, sampleRate);
273
- // Check the format
274
- const channelData = audioBuffer.getChannelData(0);
275
- const bitDepth = channelData.BYTES_PER_ELEMENT * 8; // 4 bytes per element means 32-bit
276
- return {
277
- sampleRate: audioBuffer.sampleRate,
278
- bitDepth,
279
- numberOfChannels: audioBuffer.numberOfChannels,
280
- };
281
- }
282
- resume() {
283
- this.source.connect(this.audioWorkletNode);
284
- this.audioWorkletNode.connect(this.audioContext.destination);
285
- this.audioWorkletNode.port.postMessage({ command: "resume" });
286
- }
287
- }
288
- //# sourceMappingURL=WebRecorder.web.js.map
@@ -1 +0,0 @@
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,CAA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AK,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,EAAE,UAAU,EAA0B;QACpE,8BAA8B;QAC9B,MAAM,UAAU,GAAG,UAAU,GAAG,GAAG,CAAC,CAAC,kBAAkB;QACvD,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAChD,CAAC,EACD,UAAU,EACV,UAAU,CACX,CAAC;QAEF,mBAAmB;QACnB,MAAM,WAAW,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAG,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,11 +0,0 @@
1
- import { BitDepth, SampleRate } from "./ExpoAudioStream.types";
2
- export declare const isWeb: boolean;
3
- export declare const DEBUG_NAMESPACE = "expo-audio-stream";
4
- export declare const RIFF_HEADER = 1380533830;
5
- export declare const WAVE_HEADER = 1463899717;
6
- export declare const FMT_CHUNK_ID = 1718449184;
7
- export declare const DATA_CHUNK_ID = 1684108385;
8
- export declare const INFO_CHUNK_ID = 1229866575;
9
- export declare const DEFAULT_SAMPLE_RATE: SampleRate;
10
- export declare const DEFAULT_BIT_DEPTH: BitDepth;
11
- //# sourceMappingURL=constants.d.ts.map
@@ -1 +0,0 @@
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,14 +0,0 @@
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";
5
- // Constants for identifying chunks in a WAV file
6
- export const RIFF_HEADER = 0x52494646; // "RIFF"
7
- export const WAVE_HEADER = 0x57415645; // "WAVE"
8
- export const FMT_CHUNK_ID = 0x666d7420; // "fmt "
9
- export const DATA_CHUNK_ID = 0x64617461; // "data"
10
- export const INFO_CHUNK_ID = 0x494e464f; // "INFO"
11
- // Default values
12
- export const DEFAULT_SAMPLE_RATE = 16000;
13
- export const DEFAULT_BIT_DEPTH = 32;
14
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
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"]}
package/build/events.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { type Subscription } from "expo-modules-core";
2
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
3
- import { AudioEventPayload } from "./ExpoAudioStream.types";
4
- export declare function addAudioEventListener(listener: (event: AudioEventPayload) => Promise<void>): Subscription;
5
- export declare function addAudioAnalysisListener(listener: (event: AudioAnalysisData) => Promise<void>): Subscription;
6
- //# sourceMappingURL=events.d.ts.map
@@ -1 +0,0 @@
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"}
package/build/events.js DELETED
@@ -1,15 +0,0 @@
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";
5
- const emitter = new EventEmitter(ExpoAudioStreamModule);
6
- const logger = getLogger("events");
7
- export function addAudioEventListener(listener) {
8
- logger.log("Adding listener for AudioData event");
9
- return emitter.addListener("AudioData", listener);
10
- }
11
- export function addAudioAnalysisListener(listener) {
12
- logger.log("Adding listener for AudioAnalysis event");
13
- return emitter.addListener("AudioAnalysis", listener);
14
- }
15
- //# sourceMappingURL=events.js.map
@@ -1 +0,0 @@
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"]}
package/build/index.d.ts DELETED
@@ -1,10 +0,0 @@
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
- export { AudioRecorderProvider, extractAudioAnalysis, useAudioRecorder, useSharedAudioRecorder, };
8
- export type * from "./AudioAnalysis/AudioAnalysis.types";
9
- export type * from "./ExpoAudioStream.types";
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
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 +0,0 @@
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"]}
package/build/logger.d.ts DELETED
@@ -1,9 +0,0 @@
1
- type ConsoleLike = {
2
- log: (message: string, ...args: unknown[]) => void;
3
- debug: (message: string, ...args: unknown[]) => void;
4
- };
5
- export declare const getLogger: (tag: string) => ConsoleLike;
6
- export declare const enableAllLoggers: () => void;
7
- export declare const disableAllLoggers: () => void;
8
- export {};
9
- //# sourceMappingURL=logger.d.ts.map
@@ -1 +0,0 @@
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"}
package/build/logger.js DELETED
@@ -1,17 +0,0 @@
1
- // packages/expo-audio-stream/src/logger.ts
2
- import createDebug from "debug";
3
- import { DEBUG_NAMESPACE } from "./constants";
4
- export const getLogger = (tag) => {
5
- const baseLogger = createDebug(`${DEBUG_NAMESPACE}:${tag}`);
6
- return {
7
- log: (...args) => baseLogger(...args),
8
- debug: (...args) => baseLogger(...args),
9
- };
10
- };
11
- export const enableAllLoggers = () => {
12
- createDebug.enable(`${DEBUG_NAMESPACE}:*`);
13
- };
14
- export const disableAllLoggers = () => {
15
- createDebug.disable();
16
- };
17
- //# sourceMappingURL=logger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,OAAO,WAAW,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAO9C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,GAAW,EAAe,EAAE;IACpD,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,eAAe,IAAI,GAAG,EAAE,CAAC,CAAC;IAE5D,OAAO;QACL,GAAG,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,UAAU,CAAC,GAAI,IAAkB,CAAC;QAC/D,KAAK,EAAE,CAAC,GAAG,IAAe,EAAE,EAAE,CAAC,UAAU,CAAC,GAAI,IAAkB,CAAC;KAClE,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,WAAW,CAAC,MAAM,CAAC,GAAG,eAAe,IAAI,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,EAAE;IACpC,WAAW,CAAC,OAAO,EAAE,CAAC;AACxB,CAAC,CAAC","sourcesContent":["// packages/expo-audio-stream/src/logger.ts\nimport createDebug from \"debug\";\n\nimport { DEBUG_NAMESPACE } from \"./constants\";\n\ntype ConsoleLike = {\n log: (message: string, ...args: unknown[]) => void;\n debug: (message: string, ...args: unknown[]) => void;\n};\n\nexport const getLogger = (tag: string): ConsoleLike => {\n const baseLogger = createDebug(`${DEBUG_NAMESPACE}:${tag}`);\n\n return {\n log: (...args: unknown[]) => baseLogger(...(args as [unknown])),\n debug: (...args: unknown[]) => baseLogger(...(args as [unknown])),\n };\n};\n\nexport const enableAllLoggers = () => {\n createDebug.enable(`${DEBUG_NAMESPACE}:*`);\n};\n\nexport const disableAllLoggers = () => {\n createDebug.disable();\n};\n"]}
@@ -1,37 +0,0 @@
1
- import { AudioAnalysisData, AudioFeaturesOptions } from "./AudioAnalysis/AudioAnalysis.types";
2
- import { AudioRecordingResult, RecordingConfig, StartRecordingResult } from "./ExpoAudioStream.types";
3
- import { WavFileInfo } from "./utils/getWavFileInfo";
4
- export interface ExtractMetadataProps {
5
- fileUri?: string;
6
- wavMetadata?: WavFileInfo;
7
- arrayBuffer?: ArrayBuffer;
8
- bitDepth?: number;
9
- skipWavHeader?: boolean;
10
- durationMs?: number;
11
- sampleRate?: number;
12
- numberOfChannels?: number;
13
- algorithm?: "peak" | "rms";
14
- position?: number;
15
- length?: number;
16
- pointsPerSecond?: number;
17
- features?: AudioFeaturesOptions;
18
- featuresExtratorUrl?: string;
19
- }
20
- export interface UseAudioRecorderProps {
21
- debug?: boolean;
22
- audioWorkletUrl?: string;
23
- featuresExtratorUrl?: string;
24
- }
25
- export interface UseAudioRecorderState {
26
- startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
27
- stopRecording: () => Promise<AudioRecordingResult | null>;
28
- pauseRecording: () => void;
29
- resumeRecording: () => void;
30
- isRecording: boolean;
31
- isPaused: boolean;
32
- durationMs: number;
33
- size: number;
34
- analysisData?: AudioAnalysisData;
35
- }
36
- export declare function useAudioRecorder({ debug, audioWorkletUrl, featuresExtratorUrl, }?: UseAudioRecorderProps): UseAudioRecorderState;
37
- //# sourceMappingURL=useAudioRecorder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAudioRecorder.d.ts","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAIA,OAAO,EACL,iBAAiB,EAEjB,oBAAoB,EACrB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAGL,oBAAoB,EAEpB,eAAe,EACf,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAKrD,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,gBAAg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