@siteed/expo-audio-stream 1.0.5 → 1.1.2

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 (123) hide show
  1. package/README.md +21 -5
  2. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
  3. package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
  4. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
  5. package/build/index.js +3 -2
  6. package/ios/AudioProcessor.swift +7 -5
  7. package/ios/ExpoAudioStream.podspec +1 -1
  8. package/ios/ExpoAudioStreamModule.swift +35 -0
  9. package/package.json +26 -3
  10. package/src/ExpoAudioStream.types.ts +3 -0
  11. package/src/ExpoAudioStream.web.ts +0 -1
  12. package/src/ExpoAudioStreamModule.ts +8 -2
  13. package/src/index.ts +3 -1
  14. package/src/logger.ts +0 -1
  15. package/src/utils/writeWavHeader.ts +5 -0
  16. package/src/workers/InlineFeaturesExtractor.web.tsx +295 -285
  17. package/src/workers/inlineAudioWebWorker.web.tsx +229 -221
  18. package/.eslintrc.js +0 -2
  19. package/.size-limit.json +0 -6
  20. package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
  21. package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  22. package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
  23. package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
  24. package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
  25. package/android/.gradle/8.1.1/gc.properties +0 -0
  26. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  27. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  28. package/android/.gradle/vcs-1/gc.properties +0 -0
  29. package/app.plugin.js +0 -1
  30. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -74
  31. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  32. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  33. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  34. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -20
  35. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  36. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -88
  37. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  38. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  39. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  40. package/build/AudioAnalysis/extractWaveform.js +0 -14
  41. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  42. package/build/AudioRecorder.provider.d.ts +0 -23
  43. package/build/AudioRecorder.provider.d.ts.map +0 -1
  44. package/build/AudioRecorder.provider.js +0 -36
  45. package/build/AudioRecorder.provider.js.map +0 -1
  46. package/build/ExpoAudioStream.native.d.ts +0 -3
  47. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  48. package/build/ExpoAudioStream.native.js +0 -6
  49. package/build/ExpoAudioStream.native.js.map +0 -1
  50. package/build/ExpoAudioStream.types.d.ts +0 -62
  51. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  52. package/build/ExpoAudioStream.types.js +0 -2
  53. package/build/ExpoAudioStream.types.js.map +0 -1
  54. package/build/ExpoAudioStream.web.d.ts +0 -42
  55. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  56. package/build/ExpoAudioStream.web.js +0 -203
  57. package/build/ExpoAudioStream.web.js.map +0 -1
  58. package/build/ExpoAudioStreamModule.d.ts +0 -3
  59. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  60. package/build/ExpoAudioStreamModule.js +0 -19
  61. package/build/ExpoAudioStreamModule.js.map +0 -1
  62. package/build/WebRecorder.web.d.ts +0 -51
  63. package/build/WebRecorder.web.d.ts.map +0 -1
  64. package/build/WebRecorder.web.js +0 -298
  65. package/build/WebRecorder.web.js.map +0 -1
  66. package/build/constants.d.ts +0 -11
  67. package/build/constants.d.ts.map +0 -1
  68. package/build/constants.js +0 -14
  69. package/build/constants.js.map +0 -1
  70. package/build/events.d.ts +0 -18
  71. package/build/events.d.ts.map +0 -1
  72. package/build/events.js +0 -15
  73. package/build/events.js.map +0 -1
  74. package/build/index.d.ts +0 -10
  75. package/build/index.d.ts.map +0 -1
  76. package/build/index.js.map +0 -1
  77. package/build/logger.d.ts +0 -9
  78. package/build/logger.d.ts.map +0 -1
  79. package/build/logger.js +0 -13
  80. package/build/logger.js.map +0 -1
  81. package/build/useAudioRecorder.d.ts +0 -20
  82. package/build/useAudioRecorder.d.ts.map +0 -1
  83. package/build/useAudioRecorder.js +0 -271
  84. package/build/useAudioRecorder.js.map +0 -1
  85. package/build/utils/BlobFix.d.ts +0 -9
  86. package/build/utils/BlobFix.d.ts.map +0 -1
  87. package/build/utils/BlobFix.js +0 -494
  88. package/build/utils/BlobFix.js.map +0 -1
  89. package/build/utils/concatenateBuffers.d.ts +0 -8
  90. package/build/utils/concatenateBuffers.d.ts.map +0 -1
  91. package/build/utils/concatenateBuffers.js +0 -21
  92. package/build/utils/concatenateBuffers.js.map +0 -1
  93. package/build/utils/convertPCMToFloat32.d.ts +0 -11
  94. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  95. package/build/utils/convertPCMToFloat32.js +0 -54
  96. package/build/utils/convertPCMToFloat32.js.map +0 -1
  97. package/build/utils/encodingToBitDepth.d.ts +0 -5
  98. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  99. package/build/utils/encodingToBitDepth.js +0 -13
  100. package/build/utils/encodingToBitDepth.js.map +0 -1
  101. package/build/utils/getWavFileInfo.d.ts +0 -26
  102. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  103. package/build/utils/getWavFileInfo.js +0 -92
  104. package/build/utils/getWavFileInfo.js.map +0 -1
  105. package/build/utils/writeWavHeader.d.ts +0 -9
  106. package/build/utils/writeWavHeader.d.ts.map +0 -1
  107. package/build/utils/writeWavHeader.js +0 -41
  108. package/build/utils/writeWavHeader.js.map +0 -1
  109. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  110. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  111. package/build/workers/InlineFeaturesExtractor.web.js +0 -303
  112. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  113. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  114. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  115. package/build/workers/inlineAudioWebWorker.web.js +0 -243
  116. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  117. package/expo-module.config.json +0 -9
  118. package/plugin/build/index.d.ts +0 -5
  119. package/plugin/build/index.js +0 -28
  120. package/plugin/src/index.ts +0 -53
  121. package/plugin/tsconfig.json +0 -9
  122. package/publish.sh +0 -8
  123. package/tsconfig.json +0 -14
@@ -1,242 +1,250 @@
1
1
  export const InlineAudioWebWorker = `
2
- const DEFAULT_BIT_DEPTH = 32;
3
- const DEFAULT_SAMPLE_RATE = 44100;
2
+ const DEFAULT_BIT_DEPTH = 32
3
+ const DEFAULT_SAMPLE_RATE = 44100
4
4
 
5
5
  class RecorderProcessor extends AudioWorkletProcessor {
6
- constructor() {
7
- super();
8
- this.recordedBuffers = []; // Float32Array
9
- this.newRecBuffer = []; // Float32Array
10
- this.resampledBuffer = []; // Float32Array
11
- this.exportIntervalSamples = 0;
12
- this.samplesSinceLastExport = 0;
13
- this.recordSampleRate = DEFAULT_SAMPLE_RATE; // To be overwritten
14
- this.exportSampleRate = DEFAULT_SAMPLE_RATE; // To be overwritten
15
- this.recordBitDepth = DEFAULT_BIT_DEPTH; // Default to 32-bit depth
16
- this.exportBitDepth = DEFAULT_BIT_DEPTH; // To be overwritten
17
- this.numberOfChannels = 1; // Default to 1 channel (mono)
18
- this.isRecording = true;
19
- this.port.onmessage = this.handleMessage.bind(this);
20
- }
21
-
22
- handleMessage(event) {
23
- switch (event.data.command) {
24
- case "init":
25
- this.recordSampleRate = event.data.recordSampleRate;
26
- this.exportSampleRate =
27
- event.data.exportSampleRate || event.data.recordSampleRate;
28
- this.exportIntervalSamples =
29
- this.recordSampleRate * (event.data.interval / 1000);
30
- if (event.data.numberOfChannels) {
31
- this.numberOfChannels = event.data.numberOfChannels;
32
- }
33
- if (event.data.recordBitDepth) {
34
- this.recordBitDepth = event.data.recordBitDepth;
35
- }
36
- this.exportBitDepth =
37
- event.data.exportBitDepth || this.recordBitDepth || DEFAULT_BIT_DEPTH;
38
- break;
39
- case "stop":
40
- this.isRecording = false;
41
- this.getAllRecordedData()
42
- .then((fullRecordedData) => {
43
- this.port.postMessage({
44
- command: "recordedData",
45
- recordedData: fullRecordedData,
46
- bitDepth: this.exportBitDepth,
47
- sampleRate: this.exportSampleRate,
48
- });
49
- return fullRecordedData;
50
- })
51
- .catch((error) => {
52
- console.error("Error extracting recorded data:", error);
53
- });
54
- break;
55
- }
56
- }
57
-
58
- process(inputs, outputs, parameters) {
59
- if (!this.isRecording) return true;
60
- const input = inputs[0];
61
- if (input.length > 0) {
62
- const newBuffer = new Float32Array(input[0]);
63
- this.newRecBuffer.push(newBuffer);
64
- this.recordedBuffers.push(newBuffer);
65
- this.samplesSinceLastExport += newBuffer.length;
66
-
67
- if (this.samplesSinceLastExport >= this.exportIntervalSamples) {
68
- this.exportNewData();
69
- this.samplesSinceLastExport = 0;
70
- }
6
+ constructor() {
7
+ super()
8
+ this.recordedBuffers = [] // Float32Array
9
+ this.newRecBuffer = [] // Float32Array
10
+ this.resampledBuffer = [] // Float32Array
11
+ this.exportIntervalSamples = 0
12
+ this.samplesSinceLastExport = 0
13
+ this.recordSampleRate = DEFAULT_SAMPLE_RATE // To be overwritten
14
+ this.exportSampleRate = DEFAULT_SAMPLE_RATE // To be overwritten
15
+ this.recordBitDepth = DEFAULT_BIT_DEPTH // Default to 32-bit depth
16
+ this.exportBitDepth = DEFAULT_BIT_DEPTH // To be overwritten
17
+ this.numberOfChannels = 1 // Default to 1 channel (mono)
18
+ this.isRecording = true
19
+ this.port.onmessage = this.handleMessage.bind(this)
71
20
  }
72
- return true;
73
- }
74
-
75
- mergeBuffers(bufferArray, recLength) {
76
- const result = new Float32Array(recLength);
77
- let offset = 0;
78
- for (let i = 0; i < bufferArray.length; i++) {
79
- result.set(bufferArray[i], offset);
80
- offset += bufferArray[i].length;
81
- }
82
- return result;
83
- }
84
-
85
- floatTo16BitPCM(input) {
86
- const output = new Int16Array(input.length);
87
- for (let i = 0; i < input.length; i++) {
88
- const s = Math.max(-1, Math.min(1, input[i]));
89
- output[i] = s < 0 ? s * 0x8000 : s * 0x7fff;
21
+
22
+ handleMessage(event) {
23
+ switch (event.data.command) {
24
+ case 'init':
25
+ this.recordSampleRate = event.data.recordSampleRate
26
+ this.exportSampleRate =
27
+ event.data.exportSampleRate || event.data.recordSampleRate
28
+ this.exportIntervalSamples =
29
+ this.recordSampleRate * (event.data.interval / 1000)
30
+ if (event.data.numberOfChannels) {
31
+ this.numberOfChannels = event.data.numberOfChannels
32
+ }
33
+ if (event.data.recordBitDepth) {
34
+ this.recordBitDepth = event.data.recordBitDepth
35
+ }
36
+ this.exportBitDepth =
37
+ event.data.exportBitDepth ||
38
+ this.recordBitDepth ||
39
+ DEFAULT_BIT_DEPTH
40
+ break
41
+ case 'stop':
42
+ this.isRecording = false
43
+ this.getAllRecordedData()
44
+ .then((fullRecordedData) => {
45
+ this.port.postMessage({
46
+ command: 'recordedData',
47
+ recordedData: fullRecordedData,
48
+ bitDepth: this.exportBitDepth,
49
+ sampleRate: this.exportSampleRate,
50
+ })
51
+ return fullRecordedData
52
+ })
53
+ .catch((error) => {
54
+ console.error(
55
+ 'RecorderProcessor Error extracting recorded data:',
56
+ error
57
+ )
58
+ })
59
+ break
60
+ }
90
61
  }
91
- console.debug(
92
- "Float to 16-bit PCM conversion complete. Output byte length:",
93
- output.byteLength,
94
- );
95
- return output;
96
- }
97
-
98
- floatTo32BitPCM(input) {
99
- const output = new Int32Array(input.length);
100
- for (let i = 0; i < input.length; i++) {
101
- const s = Math.max(-1, Math.min(1, input[i]));
102
- output[i] = s < 0 ? s * 0x80000000 : s * 0x7fffffff;
62
+
63
+ process(inputs, _outputs, _parameters) {
64
+ if (!this.isRecording) return true
65
+ const input = inputs[0]
66
+ if (input.length > 0) {
67
+ const newBuffer = new Float32Array(input[0])
68
+ this.newRecBuffer.push(newBuffer)
69
+ this.recordedBuffers.push(newBuffer)
70
+ this.samplesSinceLastExport += newBuffer.length
71
+
72
+ if (this.samplesSinceLastExport >= this.exportIntervalSamples) {
73
+ this.exportNewData()
74
+ this.samplesSinceLastExport = 0
75
+ }
76
+ }
77
+ return true
103
78
  }
104
- console.debug(
105
- "Float to 32-bit PCM conversion complete. Output byte length:",
106
- output.byteLength,
107
- );
108
- return output;
109
- }
110
-
111
- resample(samples, targetSampleRate) {
112
- if (this.recordSampleRate === targetSampleRate) {
113
- return samples;
79
+
80
+ mergeBuffers(bufferArray, recLength) {
81
+ const result = new Float32Array(recLength)
82
+ let offset = 0
83
+ for (let i = 0; i < bufferArray.length; i++) {
84
+ result.set(bufferArray[i], offset)
85
+ offset += bufferArray[i].length
86
+ }
87
+ return result
114
88
  }
115
- const resampledBuffer = new Float32Array(
116
- (samples.length * targetSampleRate) / this.recordSampleRate,
117
- );
118
- const ratio = this.recordSampleRate / targetSampleRate;
119
- let offset = 0;
120
- for (let i = 0; i < resampledBuffer.length; i++) {
121
- const nextOffset = Math.floor((i + 1) * ratio);
122
- let accum = 0;
123
- let count = 0;
124
- for (let j = offset; j < nextOffset && j < samples.length; j++) {
125
- accum += samples[j];
126
- count++;
127
- }
128
- resampledBuffer[i] = accum / count;
129
- offset = nextOffset;
89
+
90
+ floatTo16BitPCM(input) {
91
+ const output = new Int16Array(input.length)
92
+ for (let i = 0; i < input.length; i++) {
93
+ const s = Math.max(-1, Math.min(1, input[i]))
94
+ output[i] = s < 0 ? s * 0x8000 : s * 0x7fff
95
+ }
96
+ console.debug(
97
+ 'RecorderProcessor Float to 16-bit PCM conversion complete. Output byte length:',
98
+ output.byteLength
99
+ )
100
+ return output
130
101
  }
131
- return resampledBuffer;
132
- }
133
102
 
134
- async resampleBuffer(buffer, targetSampleRate) {
135
- if (typeof OfflineAudioContext === "undefined") {
136
- return this.resample(buffer, targetSampleRate);
103
+ floatTo32BitPCM(input) {
104
+ const output = new Int32Array(input.length)
105
+ for (let i = 0; i < input.length; i++) {
106
+ const s = Math.max(-1, Math.min(1, input[i]))
107
+ output[i] = s < 0 ? s * 0x80000000 : s * 0x7fffffff
108
+ }
109
+ console.debug(
110
+ 'RecorderProcessor Float to 32-bit PCM conversion complete. Output byte length:',
111
+ output.byteLength
112
+ )
113
+ return output
137
114
  }
138
115
 
139
- if (this.recordSampleRate === targetSampleRate) {
140
- return buffer;
116
+ resample(samples, targetSampleRate) {
117
+ if (this.recordSampleRate === targetSampleRate) {
118
+ return samples
119
+ }
120
+ const resampledBuffer = new Float32Array(
121
+ (samples.length * targetSampleRate) / this.recordSampleRate
122
+ )
123
+ const ratio = this.recordSampleRate / targetSampleRate
124
+ let offset = 0
125
+ for (let i = 0; i < resampledBuffer.length; i++) {
126
+ const nextOffset = Math.floor((i + 1) * ratio)
127
+ let accum = 0
128
+ let count = 0
129
+ for (let j = offset; j < nextOffset && j < samples.length; j++) {
130
+ accum += samples[j]
131
+ count++
132
+ }
133
+ resampledBuffer[i] = accum / count
134
+ offset = nextOffset
135
+ }
136
+ return resampledBuffer
141
137
  }
142
- const offlineContext = new OfflineAudioContext(
143
- this.numberOfChannels,
144
- buffer.length,
145
- this.recordSampleRate,
146
- );
147
- const sourceBuffer = offlineContext.createBuffer(
148
- this.numberOfChannels,
149
- buffer.length,
150
- this.recordSampleRate,
151
- );
152
- sourceBuffer.copyToChannel(buffer, 0);
153
-
154
- const bufferSource = offlineContext.createBufferSource();
155
- bufferSource.buffer = sourceBuffer;
156
- bufferSource.connect(offlineContext.destination);
157
- bufferSource.start();
158
-
159
- const renderedBuffer = await offlineContext.startRendering();
160
-
161
- const resampledBuffer = new Float32Array(renderedBuffer.length);
162
- renderedBuffer.copyFromChannel(resampledBuffer, 0);
163
-
164
- return resampledBuffer;
165
- }
166
-
167
- async exportNewData() {
168
- // Calculate the total length of the new recorded buffers
169
- const length = this.newRecBuffer.reduce(
170
- (acc, buffer) => acc + buffer.length,
171
- 0,
172
- );
173
-
174
- // Merge all new recorded buffers into a single buffer
175
- const mergedBuffer = this.mergeBuffers(this.newRecBuffer, length);
176
-
177
- const resampledBuffer = await this.resampleBuffer(
178
- mergedBuffer,
179
- this.exportSampleRate,
180
- );
181
-
182
- let finalBuffer = resampledBuffer; // Float32Array
183
- if (this.recordBitDepth !== this.exportBitDepth) {
184
- if (this.exportBitDepth === 16) {
185
- finalBuffer = this.floatTo16BitPCM(resampledBuffer);
186
- } else if (this.exportBitDepth === 32) {
187
- finalBuffer = this.floatTo32BitPCM(resampledBuffer);
188
- }
138
+
139
+ async resampleBuffer(buffer, targetSampleRate) {
140
+ if (typeof OfflineAudioContext === 'undefined') {
141
+ return this.resample(buffer, targetSampleRate)
142
+ }
143
+
144
+ if (this.recordSampleRate === targetSampleRate) {
145
+ return buffer
146
+ }
147
+ const offlineContext = new OfflineAudioContext(
148
+ this.numberOfChannels,
149
+ buffer.length,
150
+ this.recordSampleRate
151
+ )
152
+ const sourceBuffer = offlineContext.createBuffer(
153
+ this.numberOfChannels,
154
+ buffer.length,
155
+ this.recordSampleRate
156
+ )
157
+ sourceBuffer.copyToChannel(buffer, 0)
158
+
159
+ const bufferSource = offlineContext.createBufferSource()
160
+ bufferSource.buffer = sourceBuffer
161
+ bufferSource.connect(offlineContext.destination)
162
+ bufferSource.start()
163
+
164
+ const renderedBuffer = await offlineContext.startRendering()
165
+
166
+ const resampledBuffer = new Float32Array(renderedBuffer.length)
167
+ renderedBuffer.copyFromChannel(resampledBuffer, 0)
168
+
169
+ return resampledBuffer
189
170
  }
190
171
 
191
- const originalSize = mergedBuffer.byteLength;
192
- const resampledSize = resampledBuffer.byteLength;
193
- const finalSize = finalBuffer.byteLength;
194
-
195
- // Clear the new recorded buffers after they have been processed
196
- this.newRecBuffer.length = 0;
197
-
198
- // Post the message to the main thread
199
- // The first argument is the message data, containing the encoded WAV buffer
200
- // The second argument is the transfer list, which transfers ownership of the ArrayBuffer
201
- // to the main thread, avoiding the need to copy the buffer and improving performance
202
- // this.port.postMessage({ recordedData: encodedWav.buffer, sampleRate: this.recordSampleRate }, [encodedWav.buffer]);
203
- this.port.postMessage({
204
- command: "newData",
205
- recordedData: finalBuffer.buffer,
206
- sampleRate: this.exportSampleRate,
207
- bitDepth: this.exportBitDepth,
208
- });
209
- }
210
-
211
- async getAllRecordedData() {
212
- const length = this.recordedBuffers.reduce(
213
- (acc, buffer) => acc + buffer.length,
214
- 0,
215
- );
216
- const mergedBuffer = this.mergeBuffers(this.recordedBuffers, length);
217
- const resampledBuffer = await this.resampleBuffer(
218
- mergedBuffer,
219
- this.exportSampleRate,
220
- );
221
- // Convert to the desired bit depth if necessary
222
- let finalBuffer = resampledBuffer;
223
- if (this.recordBitDepth !== this.exportBitDepth) {
224
- if (this.exportBitDepth === 16) {
225
- finalBuffer = this.floatTo16BitPCM(resampledBuffer);
226
- } else if (this.exportBitDepth === 32) {
227
- finalBuffer = this.floatTo32BitPCM(resampledBuffer);
228
- }
172
+ async exportNewData() {
173
+ // Calculate the total length of the new recorded buffers
174
+ const length = this.newRecBuffer.reduce(
175
+ (acc, buffer) => acc + buffer.length,
176
+ 0
177
+ )
178
+
179
+ // Merge all new recorded buffers into a single buffer
180
+ const mergedBuffer = this.mergeBuffers(this.newRecBuffer, length)
181
+
182
+ const resampledBuffer = await this.resampleBuffer(
183
+ mergedBuffer,
184
+ this.exportSampleRate
185
+ )
186
+
187
+ let finalBuffer = resampledBuffer // Float32Array
188
+ if (this.recordBitDepth !== this.exportBitDepth) {
189
+ if (this.exportBitDepth === 16) {
190
+ finalBuffer = this.floatTo16BitPCM(resampledBuffer)
191
+ } else if (this.exportBitDepth === 32) {
192
+ finalBuffer = this.floatTo32BitPCM(resampledBuffer)
193
+ }
194
+ }
195
+
196
+ const originalSize = mergedBuffer.byteLength
197
+ const resampledSize = resampledBuffer.byteLength
198
+ const finalSize = finalBuffer.byteLength
199
+
200
+ // Clear the new recorded buffers after they have been processed
201
+ this.newRecBuffer.length = 0
202
+
203
+ // Post the message to the main thread
204
+ // The first argument is the message data, containing the encoded WAV buffer
205
+ // The second argument is the transfer list, which transfers ownership of the ArrayBuffer
206
+ // to the main thread, avoiding the need to copy the buffer and improving performance
207
+ // this.port.postMessage({ recordedData: encodedWav.buffer, sampleRate: this.recordSampleRate }, [encodedWav.buffer]);
208
+ this.port.postMessage(
209
+ {
210
+ command: 'newData',
211
+ recordedData: finalBuffer,
212
+ sampleRate: this.exportSampleRate,
213
+ bitDepth: this.exportBitDepth,
214
+ },
215
+ []
216
+ )
229
217
  }
230
218
 
231
- const originalSize = mergedBuffer.byteLength;
232
- const resampledSize = resampledBuffer.byteLength;
233
- const finalSize = finalBuffer.byteLength;
219
+ async getAllRecordedData() {
220
+ const length = this.recordedBuffers.reduce(
221
+ (acc, buffer) => acc + buffer.length,
222
+ 0
223
+ )
224
+ const mergedBuffer = this.mergeBuffers(this.recordedBuffers, length)
225
+ const resampledBuffer = await this.resampleBuffer(
226
+ mergedBuffer,
227
+ this.exportSampleRate
228
+ )
229
+ // Convert to the desired bit depth if necessary
230
+ let finalBuffer = resampledBuffer
231
+ if (this.recordBitDepth !== this.exportBitDepth) {
232
+ if (this.exportBitDepth === 16) {
233
+ finalBuffer = this.floatTo16BitPCM(resampledBuffer)
234
+ } else if (this.exportBitDepth === 32) {
235
+ finalBuffer = this.floatTo32BitPCM(resampledBuffer)
236
+ }
237
+ }
238
+
239
+ const originalSize = mergedBuffer.byteLength
240
+ const resampledSize = resampledBuffer.byteLength
241
+ const finalSize = finalBuffer.byteLength
234
242
 
235
- this.recordedBuffers.length = 0; // Clear the buffers after extraction
243
+ this.recordedBuffers.length = 0 // Clear the buffers after extraction
236
244
 
237
- return finalBuffer.buffer;
238
- }
245
+ return finalBuffer
246
+ }
239
247
  }
240
248
 
241
- registerProcessor("recorder-processor", RecorderProcessor);
249
+ registerProcessor('recorder-processor', RecorderProcessor)
242
250
  `
package/.eslintrc.js DELETED
@@ -1,2 +0,0 @@
1
- // @generated by expo-module-scripts
2
- module.exports = require('expo-module-scripts/eslintrc.base.js');
package/.size-limit.json DELETED
@@ -1,6 +0,0 @@
1
- [
2
- {
3
- "path": "./build/index.js",
4
- "limit": "100000 ms"
5
- }
6
- ]
File without changes
@@ -1,2 +0,0 @@
1
- #Sat Apr 20 14:30:49 HKT 2024
2
- gradle.version=8.1.1
File without changes
package/app.plugin.js DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./plugin/build')
@@ -1,74 +0,0 @@
1
- /**
2
- * Represents various audio features extracted from an audio signal.
3
- */
4
- export interface AudioFeatures {
5
- energy: number;
6
- mfcc: number[];
7
- rms: number;
8
- minAmplitude: number;
9
- maxAmplitude: number;
10
- zcr: number;
11
- spectralCentroid: number;
12
- spectralFlatness: number;
13
- spectralRolloff: number;
14
- spectralBandwidth: number;
15
- chromagram: number[];
16
- tempo: number;
17
- hnr: number;
18
- }
19
- /**
20
- * Options to specify which audio features to extract.
21
- */
22
- export interface AudioFeaturesOptions {
23
- energy?: boolean;
24
- mfcc?: boolean;
25
- rms?: boolean;
26
- zcr?: boolean;
27
- spectralCentroid?: boolean;
28
- spectralFlatness?: boolean;
29
- spectralRolloff?: boolean;
30
- spectralBandwidth?: boolean;
31
- chromagram?: boolean;
32
- tempo?: boolean;
33
- hnr?: boolean;
34
- }
35
- /**
36
- * Represents a single data point in the audio analysis.
37
- */
38
- export interface DataPoint {
39
- id: number;
40
- amplitude: number;
41
- activeSpeech?: boolean;
42
- dB?: number;
43
- silent?: boolean;
44
- features?: AudioFeatures;
45
- startTime?: number;
46
- endTime?: number;
47
- startPosition?: number;
48
- endPosition?: number;
49
- samples?: number;
50
- speaker?: number;
51
- }
52
- export type AmplitudeAlgorithm = 'peak' | 'rms';
53
- /**
54
- * Represents the complete data from the audio analysis.
55
- */
56
- export interface AudioAnalysis {
57
- pointsPerSecond: number;
58
- durationMs: number;
59
- bitDepth: number;
60
- samples: number;
61
- numberOfChannels: number;
62
- sampleRate: number;
63
- dataPoints: DataPoint[];
64
- amplitudeAlgorithm: AmplitudeAlgorithm;
65
- amplitudeRange: {
66
- min: number;
67
- max: number;
68
- };
69
- speakerChanges?: {
70
- timestamp: number;
71
- speaker: number;
72
- }[];
73
- }
74
- //# sourceMappingURL=AudioAnalysis.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudioAnalysis.types.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,YAAY,EAAE,MAAM,CAAA;IACpB,GAAG,EAAE,MAAM,CAAA;IACX,gBAAgB,EAAE,MAAM,CAAA;IACxB,gBAAgB,EAAE,MAAM,CAAA;IACxB,eAAe,EAAE,MAAM,CAAA;IACvB,iBAAiB,EAAE,MAAM,CAAA;IACzB,UAAU,EAAE,MAAM,EAAE,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;CACd;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACjC,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,OAAO,CAAA;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,SAAS,EAAE,MAAM,CAAA;IACjB,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,QAAQ,CAAC,EAAE,aAAa,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,CAAA;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACd,CAAA;IAED,cAAc,CAAC,EAAE;QACb,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;KAClB,EAAE,CAAA;CACN"}
@@ -1,3 +0,0 @@
1
- // packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts
2
- export {};
3
- //# sourceMappingURL=AudioAnalysis.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude: number // Minimum amplitude value in the audio signal.\n maxAmplitude: number // Maximum amplitude value in the audio signal.\n zcr: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number\n activeSpeech?: boolean\n dB?: number\n silent?: boolean\n features?: AudioFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n // TODO: speaker detection\n speaker?: number\n}\n\nexport type AmplitudeAlgorithm = 'peak' | 'rms'\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n pointsPerSecond: number // How many consolidated value per second\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeAlgorithm: AmplitudeAlgorithm // Algorithm used to calculate amplitude values.\n amplitudeRange: {\n min: number\n max: number\n }\n // TODO: speaker detection\n speakerChanges?: {\n timestamp: number // Timestamp of the speaker change in milliseconds.\n speaker: number // Speaker identifier.\n }[]\n}\n\n"]}
@@ -1,20 +0,0 @@
1
- import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions } from './AudioAnalysis.types';
2
- import { WavFileInfo } from '../utils/getWavFileInfo';
3
- export interface ExtractAudioAnalysisProps {
4
- fileUri?: string;
5
- wavMetadata?: WavFileInfo;
6
- arrayBuffer?: ArrayBuffer;
7
- bitDepth?: number;
8
- skipWavHeader?: boolean;
9
- durationMs?: number;
10
- sampleRate?: number;
11
- numberOfChannels?: number;
12
- algorithm?: AmplitudeAlgorithm;
13
- position?: number;
14
- length?: number;
15
- pointsPerSecond?: number;
16
- features?: AudioFeaturesOptions;
17
- featuresExtratorUrl?: string;
18
- }
19
- export declare const extractAudioAnalysis: ({ fileUri, pointsPerSecond, arrayBuffer, bitDepth, skipWavHeader, durationMs, sampleRate, numberOfChannels, algorithm, features, featuresExtratorUrl, }: ExtractAudioAnalysisProps) => Promise<AudioAnalysis>;
20
- //# sourceMappingURL=extractAudioAnalysis.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractAudioAnalysis.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":"AACA,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACvB,MAAM,uBAAuB,CAAA;AAK9B,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAKrE,MAAM,WAAW,yBAAyB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,kBAAkB,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,eAAO,MAAM,oBAAoB,4JAY9B,yBAAyB,KAAG,OAAO,CAAC,aAAa,CAsGnD,CAAA"}