@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.
- package/README.md +21 -5
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
- package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
- package/build/index.js +3 -2
- package/ios/AudioProcessor.swift +7 -5
- package/ios/ExpoAudioStream.podspec +1 -1
- package/ios/ExpoAudioStreamModule.swift +35 -0
- package/package.json +26 -3
- package/src/ExpoAudioStream.types.ts +3 -0
- package/src/ExpoAudioStream.web.ts +0 -1
- package/src/ExpoAudioStreamModule.ts +8 -2
- package/src/index.ts +3 -1
- package/src/logger.ts +0 -1
- package/src/utils/writeWavHeader.ts +5 -0
- package/src/workers/InlineFeaturesExtractor.web.tsx +295 -285
- package/src/workers/inlineAudioWebWorker.web.tsx +229 -221
- package/.eslintrc.js +0 -2
- package/.size-limit.json +0 -6
- package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/app.plugin.js +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -74
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -20
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.js +0 -88
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
- package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
- package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
- package/build/AudioAnalysis/extractWaveform.js +0 -14
- package/build/AudioAnalysis/extractWaveform.js.map +0 -1
- package/build/AudioRecorder.provider.d.ts +0 -23
- package/build/AudioRecorder.provider.d.ts.map +0 -1
- package/build/AudioRecorder.provider.js +0 -36
- package/build/AudioRecorder.provider.js.map +0 -1
- package/build/ExpoAudioStream.native.d.ts +0 -3
- package/build/ExpoAudioStream.native.d.ts.map +0 -1
- package/build/ExpoAudioStream.native.js +0 -6
- package/build/ExpoAudioStream.native.js.map +0 -1
- package/build/ExpoAudioStream.types.d.ts +0 -62
- package/build/ExpoAudioStream.types.d.ts.map +0 -1
- package/build/ExpoAudioStream.types.js +0 -2
- package/build/ExpoAudioStream.types.js.map +0 -1
- package/build/ExpoAudioStream.web.d.ts +0 -42
- package/build/ExpoAudioStream.web.d.ts.map +0 -1
- package/build/ExpoAudioStream.web.js +0 -203
- package/build/ExpoAudioStream.web.js.map +0 -1
- package/build/ExpoAudioStreamModule.d.ts +0 -3
- package/build/ExpoAudioStreamModule.d.ts.map +0 -1
- package/build/ExpoAudioStreamModule.js +0 -19
- package/build/ExpoAudioStreamModule.js.map +0 -1
- package/build/WebRecorder.web.d.ts +0 -51
- package/build/WebRecorder.web.d.ts.map +0 -1
- package/build/WebRecorder.web.js +0 -298
- package/build/WebRecorder.web.js.map +0 -1
- package/build/constants.d.ts +0 -11
- package/build/constants.d.ts.map +0 -1
- package/build/constants.js +0 -14
- package/build/constants.js.map +0 -1
- package/build/events.d.ts +0 -18
- package/build/events.d.ts.map +0 -1
- package/build/events.js +0 -15
- package/build/events.js.map +0 -1
- package/build/index.d.ts +0 -10
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/build/logger.d.ts +0 -9
- package/build/logger.d.ts.map +0 -1
- package/build/logger.js +0 -13
- package/build/logger.js.map +0 -1
- package/build/useAudioRecorder.d.ts +0 -20
- package/build/useAudioRecorder.d.ts.map +0 -1
- package/build/useAudioRecorder.js +0 -271
- package/build/useAudioRecorder.js.map +0 -1
- package/build/utils/BlobFix.d.ts +0 -9
- package/build/utils/BlobFix.d.ts.map +0 -1
- package/build/utils/BlobFix.js +0 -494
- package/build/utils/BlobFix.js.map +0 -1
- package/build/utils/concatenateBuffers.d.ts +0 -8
- package/build/utils/concatenateBuffers.d.ts.map +0 -1
- package/build/utils/concatenateBuffers.js +0 -21
- package/build/utils/concatenateBuffers.js.map +0 -1
- package/build/utils/convertPCMToFloat32.d.ts +0 -11
- package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
- package/build/utils/convertPCMToFloat32.js +0 -54
- package/build/utils/convertPCMToFloat32.js.map +0 -1
- package/build/utils/encodingToBitDepth.d.ts +0 -5
- package/build/utils/encodingToBitDepth.d.ts.map +0 -1
- package/build/utils/encodingToBitDepth.js +0 -13
- package/build/utils/encodingToBitDepth.js.map +0 -1
- package/build/utils/getWavFileInfo.d.ts +0 -26
- package/build/utils/getWavFileInfo.d.ts.map +0 -1
- package/build/utils/getWavFileInfo.js +0 -92
- package/build/utils/getWavFileInfo.js.map +0 -1
- package/build/utils/writeWavHeader.d.ts +0 -9
- package/build/utils/writeWavHeader.d.ts.map +0 -1
- package/build/utils/writeWavHeader.js +0 -41
- package/build/utils/writeWavHeader.js.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
- package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.js +0 -303
- package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
- package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.js +0 -243
- package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
- package/expo-module.config.json +0 -9
- package/plugin/build/index.d.ts +0 -5
- package/plugin/build/index.js +0 -28
- package/plugin/src/index.ts +0 -53
- package/plugin/tsconfig.json +0 -9
- package/publish.sh +0 -8
- 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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
140
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
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
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
243
|
+
this.recordedBuffers.length = 0 // Clear the buffers after extraction
|
|
236
244
|
|
|
237
|
-
|
|
238
|
-
|
|
245
|
+
return finalBuffer
|
|
246
|
+
}
|
|
239
247
|
}
|
|
240
248
|
|
|
241
|
-
registerProcessor(
|
|
249
|
+
registerProcessor('recorder-processor', RecorderProcessor)
|
|
242
250
|
`
|
package/.eslintrc.js
DELETED
package/.size-limit.json
DELETED
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
Binary file
|
|
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 +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"}
|