@siteed/expo-audio-studio 2.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.
- package/CHANGELOG.md +210 -0
- package/LICENSE +21 -0
- package/README.md +269 -0
- package/android/build.gradle +105 -0
- package/android/src/main/AndroidManifest.xml +27 -0
- package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +166 -0
- package/android/src/main/java/net/siteed/audiostream/AudioDataEncoder.kt +9 -0
- package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +131 -0
- package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +103 -0
- package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +435 -0
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +2235 -0
- package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1437 -0
- package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +166 -0
- package/android/src/main/java/net/siteed/audiostream/AudioTrimmer.kt +1099 -0
- package/android/src/main/java/net/siteed/audiostream/Constants.kt +21 -0
- package/android/src/main/java/net/siteed/audiostream/EventSender.kt +7 -0
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +739 -0
- package/android/src/main/java/net/siteed/audiostream/FFT.kt +99 -0
- package/android/src/main/java/net/siteed/audiostream/Features.kt +98 -0
- package/android/src/main/java/net/siteed/audiostream/NotificationConfig.kt +70 -0
- package/android/src/main/java/net/siteed/audiostream/PermissionUtils.kt +59 -0
- package/android/src/main/java/net/siteed/audiostream/RecordingActionReceiver.kt +59 -0
- package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +205 -0
- package/android/src/main/java/net/siteed/audiostream/WaveformConfig.kt +19 -0
- package/android/src/main/java/net/siteed/audiostream/WaveformRenderer.kt +159 -0
- package/android/src/main/res/drawable/ic_default_action_icon.xml +16 -0
- package/android/src/main/res/drawable/ic_microphone.xml +13 -0
- package/android/src/main/res/drawable/ic_pause.xml +10 -0
- package/android/src/main/res/drawable/ic_play.xml +10 -0
- package/android/src/main/res/drawable/ic_stop.xml +10 -0
- package/android/src/main/res/layout/notification_recording.xml +37 -0
- package/android/src/main/test/java/net/siteed/audiostream/AudioProcessorTest.kt +56 -0
- package/app.plugin.js +1 -0
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +179 -0
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
- package/build/AudioAnalysis/AudioAnalysis.types.js +3 -0
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +68 -0
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
- package/build/AudioAnalysis/extractAudioAnalysis.js +203 -0
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
- package/build/AudioAnalysis/extractAudioData.d.ts +3 -0
- package/build/AudioAnalysis/extractAudioData.d.ts.map +1 -0
- package/build/AudioAnalysis/extractAudioData.js +5 -0
- package/build/AudioAnalysis/extractAudioData.js.map +1 -0
- package/build/AudioAnalysis/extractMelSpectrogram.d.ts +14 -0
- package/build/AudioAnalysis/extractMelSpectrogram.d.ts.map +1 -0
- package/build/AudioAnalysis/extractMelSpectrogram.js +85 -0
- package/build/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
- package/build/AudioAnalysis/extractPreview.d.ts +11 -0
- package/build/AudioAnalysis/extractPreview.d.ts.map +1 -0
- package/build/AudioAnalysis/extractPreview.js +25 -0
- package/build/AudioAnalysis/extractPreview.js.map +1 -0
- package/build/AudioAnalysis/extractWaveform.d.ts +8 -0
- package/build/AudioAnalysis/extractWaveform.d.ts.map +1 -0
- package/build/AudioAnalysis/extractWaveform.js +11 -0
- package/build/AudioAnalysis/extractWaveform.js.map +1 -0
- package/build/AudioRecorder.provider.d.ts +11 -0
- package/build/AudioRecorder.provider.d.ts.map +1 -0
- package/build/AudioRecorder.provider.js +37 -0
- package/build/AudioRecorder.provider.js.map +1 -0
- package/build/ExpoAudioStream.native.d.ts +3 -0
- package/build/ExpoAudioStream.native.d.ts.map +1 -0
- package/build/ExpoAudioStream.native.js +6 -0
- package/build/ExpoAudioStream.native.js.map +1 -0
- package/build/ExpoAudioStream.types.d.ts +532 -0
- package/build/ExpoAudioStream.types.d.ts.map +1 -0
- package/build/ExpoAudioStream.types.js +2 -0
- package/build/ExpoAudioStream.types.js.map +1 -0
- package/build/ExpoAudioStream.web.d.ts +59 -0
- package/build/ExpoAudioStream.web.d.ts.map +1 -0
- package/build/ExpoAudioStream.web.js +285 -0
- package/build/ExpoAudioStream.web.js.map +1 -0
- package/build/ExpoAudioStreamModule.d.ts +3 -0
- package/build/ExpoAudioStreamModule.d.ts.map +1 -0
- package/build/ExpoAudioStreamModule.js +693 -0
- package/build/ExpoAudioStreamModule.js.map +1 -0
- package/build/WebRecorder.web.d.ts +119 -0
- package/build/WebRecorder.web.d.ts.map +1 -0
- package/build/WebRecorder.web.js +436 -0
- package/build/WebRecorder.web.js.map +1 -0
- package/build/constants.d.ts +11 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +14 -0
- package/build/constants.js.map +1 -0
- package/build/events.d.ts +26 -0
- package/build/events.d.ts.map +1 -0
- package/build/events.js +21 -0
- package/build/events.js.map +1 -0
- package/build/index.d.ts +15 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +14 -0
- package/build/index.js.map +1 -0
- package/build/trimAudio.d.ts +25 -0
- package/build/trimAudio.d.ts.map +1 -0
- package/build/trimAudio.js +67 -0
- package/build/trimAudio.js.map +1 -0
- package/build/useAudioRecorder.d.ts +21 -0
- package/build/useAudioRecorder.d.ts.map +1 -0
- package/build/useAudioRecorder.js +427 -0
- package/build/useAudioRecorder.js.map +1 -0
- package/build/utils/BlobFix.d.ts +9 -0
- package/build/utils/BlobFix.d.ts.map +1 -0
- package/build/utils/BlobFix.js +498 -0
- package/build/utils/BlobFix.js.map +1 -0
- package/build/utils/audioProcessing.d.ts +24 -0
- package/build/utils/audioProcessing.d.ts.map +1 -0
- package/build/utils/audioProcessing.js +133 -0
- package/build/utils/audioProcessing.js.map +1 -0
- package/build/utils/concatenateBuffers.d.ts +8 -0
- package/build/utils/concatenateBuffers.d.ts.map +1 -0
- package/build/utils/concatenateBuffers.js +21 -0
- package/build/utils/concatenateBuffers.js.map +1 -0
- package/build/utils/convertPCMToFloat32.d.ts +13 -0
- package/build/utils/convertPCMToFloat32.d.ts.map +1 -0
- package/build/utils/convertPCMToFloat32.js +120 -0
- package/build/utils/convertPCMToFloat32.js.map +1 -0
- package/build/utils/encodingToBitDepth.d.ts +5 -0
- package/build/utils/encodingToBitDepth.d.ts.map +1 -0
- package/build/utils/encodingToBitDepth.js +13 -0
- package/build/utils/encodingToBitDepth.js.map +1 -0
- package/build/utils/getWavFileInfo.d.ts +26 -0
- package/build/utils/getWavFileInfo.d.ts.map +1 -0
- package/build/utils/getWavFileInfo.js +92 -0
- package/build/utils/getWavFileInfo.js.map +1 -0
- package/build/utils/writeWavHeader.d.ts +49 -0
- package/build/utils/writeWavHeader.d.ts.map +1 -0
- package/build/utils/writeWavHeader.js +91 -0
- package/build/utils/writeWavHeader.js.map +1 -0
- package/build/workers/InlineFeaturesExtractor.web.d.ts +2 -0
- package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
- package/build/workers/InlineFeaturesExtractor.web.js +828 -0
- package/build/workers/InlineFeaturesExtractor.web.js.map +1 -0
- package/build/workers/inlineAudioWebWorker.web.d.ts +2 -0
- package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
- package/build/workers/inlineAudioWebWorker.web.js +157 -0
- package/build/workers/inlineAudioWebWorker.web.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/AudioAnalysisData.swift +74 -0
- package/ios/AudioNotificationManager.swift +135 -0
- package/ios/AudioProcessingHelpers.swift +743 -0
- package/ios/AudioProcessor.swift +1313 -0
- package/ios/AudioStreamError.swift +7 -0
- package/ios/AudioStreamManager.swift +1708 -0
- package/ios/AudioStreamManagerDelegate.swift +16 -0
- package/ios/DataPoint.swift +54 -0
- package/ios/DecodingConfig.swift +47 -0
- package/ios/ExpoAudioStream.podspec +27 -0
- package/ios/ExpoAudioStreamModule.swift +805 -0
- package/ios/FFT.swift +62 -0
- package/ios/Features.swift +95 -0
- package/ios/Logger.swift +7 -0
- package/ios/NotificationExtension.swift +15 -0
- package/ios/RecordingResult.swift +22 -0
- package/ios/RecordingSettings.swift +265 -0
- package/ios/WaveformExtractor.swift +105 -0
- package/package.json +128 -0
- package/plugin/build/index.d.ts +21 -0
- package/plugin/build/index.js +192 -0
- package/plugin/src/index.ts +279 -0
- package/plugin/tsconfig.json +10 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/src/AudioAnalysis/AudioAnalysis.types.ts +202 -0
- package/src/AudioAnalysis/extractAudioAnalysis.ts +333 -0
- package/src/AudioAnalysis/extractAudioData.ts +6 -0
- package/src/AudioAnalysis/extractMelSpectrogram.ts +144 -0
- package/src/AudioAnalysis/extractPreview.ts +34 -0
- package/src/AudioAnalysis/extractWaveform.ts +22 -0
- package/src/AudioRecorder.provider.tsx +54 -0
- package/src/ExpoAudioStream.native.ts +6 -0
- package/src/ExpoAudioStream.types.ts +641 -0
- package/src/ExpoAudioStream.web.ts +359 -0
- package/src/ExpoAudioStreamModule.ts +967 -0
- package/src/WebRecorder.web.ts +580 -0
- package/src/constants.ts +18 -0
- package/src/events.ts +60 -0
- package/src/index.ts +36 -0
- package/src/trimAudio.ts +90 -0
- package/src/useAudioRecorder.tsx +620 -0
- package/src/utils/BlobFix.ts +559 -0
- package/src/utils/audioProcessing.ts +205 -0
- package/src/utils/concatenateBuffers.ts +24 -0
- package/src/utils/convertPCMToFloat32.ts +170 -0
- package/src/utils/encodingToBitDepth.ts +18 -0
- package/src/utils/getWavFileInfo.ts +132 -0
- package/src/utils/writeWavHeader.ts +114 -0
- package/src/workers/InlineFeaturesExtractor.web.tsx +827 -0
- package/src/workers/inlineAudioWebWorker.web.tsx +156 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// packages/expo-audio-stream/src/workers/inlineAudioWebWorker.web.tsx
|
|
2
|
+
export const InlineAudioWebWorker = `
|
|
3
|
+
const DEFAULT_BIT_DEPTH = 32
|
|
4
|
+
const DEFAULT_SAMPLE_RATE = 44100
|
|
5
|
+
|
|
6
|
+
class RecorderProcessor extends AudioWorkletProcessor {
|
|
7
|
+
constructor() {
|
|
8
|
+
super()
|
|
9
|
+
this.currentChunk = [] // Float32Array
|
|
10
|
+
this.samplesSinceLastExport = 0
|
|
11
|
+
this.recordSampleRate = DEFAULT_SAMPLE_RATE
|
|
12
|
+
this.exportSampleRate = DEFAULT_SAMPLE_RATE
|
|
13
|
+
this.recordBitDepth = DEFAULT_BIT_DEPTH
|
|
14
|
+
this.exportBitDepth = DEFAULT_BIT_DEPTH
|
|
15
|
+
this.numberOfChannels = 1
|
|
16
|
+
this.isRecording = true
|
|
17
|
+
this.port.onmessage = this.handleMessage.bind(this)
|
|
18
|
+
this.enableLogging = false
|
|
19
|
+
this.exportIntervalSamples = 0
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
handleMessage(event) {
|
|
23
|
+
switch (event.data.command) {
|
|
24
|
+
case 'init':
|
|
25
|
+
this.enableLogging = event.data.enableLogging || false
|
|
26
|
+
this.recordSampleRate = event.data.recordSampleRate
|
|
27
|
+
this.exportSampleRate =
|
|
28
|
+
event.data.exportSampleRate || event.data.recordSampleRate
|
|
29
|
+
this.exportIntervalSamples =
|
|
30
|
+
this.recordSampleRate * (event.data.interval / 1000)
|
|
31
|
+
if (event.data.numberOfChannels) {
|
|
32
|
+
this.numberOfChannels = event.data.numberOfChannels
|
|
33
|
+
}
|
|
34
|
+
if (event.data.recordBitDepth) {
|
|
35
|
+
this.recordBitDepth = event.data.recordBitDepth
|
|
36
|
+
}
|
|
37
|
+
this.exportBitDepth =
|
|
38
|
+
event.data.exportBitDepth || this.recordBitDepth
|
|
39
|
+
break
|
|
40
|
+
|
|
41
|
+
case 'stop':
|
|
42
|
+
this.isRecording = false
|
|
43
|
+
if (this.currentChunk.length > 0) {
|
|
44
|
+
this.processChunk()
|
|
45
|
+
}
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
process(inputs, _outputs, _parameters) {
|
|
51
|
+
if (!this.isRecording) return true
|
|
52
|
+
const input = inputs[0]
|
|
53
|
+
if (input.length > 0) {
|
|
54
|
+
const newBuffer = new Float32Array(input[0])
|
|
55
|
+
this.currentChunk.push(newBuffer)
|
|
56
|
+
this.samplesSinceLastExport += newBuffer.length
|
|
57
|
+
|
|
58
|
+
if (this.samplesSinceLastExport >= this.exportIntervalSamples) {
|
|
59
|
+
this.processChunk()
|
|
60
|
+
this.samplesSinceLastExport = 0
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
mergeBuffers(bufferArray, recLength) {
|
|
67
|
+
const result = new Float32Array(recLength)
|
|
68
|
+
let offset = 0
|
|
69
|
+
for (let i = 0; i < bufferArray.length; i++) {
|
|
70
|
+
result.set(bufferArray[i], offset)
|
|
71
|
+
offset += bufferArray[i].length
|
|
72
|
+
}
|
|
73
|
+
return result
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Keep basic resampling for sample rate conversion
|
|
77
|
+
resample(samples, targetSampleRate) {
|
|
78
|
+
if (this.recordSampleRate === targetSampleRate) {
|
|
79
|
+
return samples
|
|
80
|
+
}
|
|
81
|
+
const resampledBuffer = new Float32Array(
|
|
82
|
+
Math.ceil(
|
|
83
|
+
(samples.length * targetSampleRate) / this.recordSampleRate
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
const ratio = this.recordSampleRate / targetSampleRate
|
|
87
|
+
let offset = 0
|
|
88
|
+
for (let i = 0; i < resampledBuffer.length; i++) {
|
|
89
|
+
const nextOffset = Math.floor((i + 1) * ratio)
|
|
90
|
+
let accum = 0
|
|
91
|
+
let count = 0
|
|
92
|
+
for (let j = offset; j < nextOffset && j < samples.length; j++) {
|
|
93
|
+
accum += samples[j]
|
|
94
|
+
count++
|
|
95
|
+
}
|
|
96
|
+
resampledBuffer[i] = count > 0 ? accum / count : 0
|
|
97
|
+
offset = nextOffset
|
|
98
|
+
}
|
|
99
|
+
return resampledBuffer
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Keep bit depth conversion if needed
|
|
103
|
+
convertBitDepth(input, targetBitDepth) {
|
|
104
|
+
if (targetBitDepth === 32) {
|
|
105
|
+
const output = new Int32Array(input.length)
|
|
106
|
+
for (let i = 0; i < input.length; i++) {
|
|
107
|
+
const s = Math.max(-1, Math.min(1, input[i]))
|
|
108
|
+
output[i] = s < 0 ? s * 0x80000000 : s * 0x7fffffff
|
|
109
|
+
}
|
|
110
|
+
return output
|
|
111
|
+
} else if (targetBitDepth === 16) {
|
|
112
|
+
const output = new Int16Array(input.length)
|
|
113
|
+
for (let i = 0; i < input.length; i++) {
|
|
114
|
+
const s = Math.max(-1, Math.min(1, input[i]))
|
|
115
|
+
output[i] = s < 0 ? s * 0x8000 : s * 0x7fff
|
|
116
|
+
}
|
|
117
|
+
return output
|
|
118
|
+
}
|
|
119
|
+
return input
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
processChunk() {
|
|
123
|
+
if (this.currentChunk.length === 0) return
|
|
124
|
+
|
|
125
|
+
// Merge buffers
|
|
126
|
+
const chunkLength = this.currentChunk.reduce(
|
|
127
|
+
(acc, buf) => acc + buf.length,
|
|
128
|
+
0
|
|
129
|
+
)
|
|
130
|
+
const mergedChunk = this.mergeBuffers(this.currentChunk, chunkLength)
|
|
131
|
+
|
|
132
|
+
// Resample if needed
|
|
133
|
+
const resampledChunk = this.resample(mergedChunk, this.exportSampleRate)
|
|
134
|
+
|
|
135
|
+
// Convert bit depth if needed
|
|
136
|
+
const finalBuffer =
|
|
137
|
+
this.recordBitDepth !== this.exportBitDepth
|
|
138
|
+
? this.convertBitDepth(resampledChunk, this.exportBitDepth)
|
|
139
|
+
: resampledChunk
|
|
140
|
+
|
|
141
|
+
// Send processed chunk
|
|
142
|
+
this.port.postMessage({
|
|
143
|
+
command: 'newData',
|
|
144
|
+
recordedData: finalBuffer,
|
|
145
|
+
sampleRate: this.exportSampleRate,
|
|
146
|
+
bitDepth: this.exportBitDepth,
|
|
147
|
+
numberOfChannels: this.numberOfChannels,
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
// Clear the current chunk
|
|
151
|
+
this.currentChunk = []
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
registerProcessor('recorder-processor', RecorderProcessor)
|
|
156
|
+
`
|