@siteed/expo-audio-stream 2.0.1 → 2.2.0

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 (166) hide show
  1. package/README.md +46 -27
  2. package/build/index.d.ts +11 -12
  3. package/build/index.js +44 -10
  4. package/package.json +49 -110
  5. package/src/index.ts +18 -33
  6. package/CHANGELOG.md +0 -195
  7. package/android/build.gradle +0 -105
  8. package/android/src/main/AndroidManifest.xml +0 -27
  9. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +0 -166
  10. package/android/src/main/java/net/siteed/audiostream/AudioDataEncoder.kt +0 -9
  11. package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +0 -131
  12. package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +0 -103
  13. package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +0 -435
  14. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +0 -1936
  15. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +0 -1437
  16. package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +0 -138
  17. package/android/src/main/java/net/siteed/audiostream/Constants.kt +0 -20
  18. package/android/src/main/java/net/siteed/audiostream/EventSender.kt +0 -7
  19. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +0 -509
  20. package/android/src/main/java/net/siteed/audiostream/FFT.kt +0 -99
  21. package/android/src/main/java/net/siteed/audiostream/Features.kt +0 -98
  22. package/android/src/main/java/net/siteed/audiostream/NotificationConfig.kt +0 -70
  23. package/android/src/main/java/net/siteed/audiostream/PermissionUtils.kt +0 -59
  24. package/android/src/main/java/net/siteed/audiostream/RecordingActionReceiver.kt +0 -59
  25. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +0 -205
  26. package/android/src/main/java/net/siteed/audiostream/WaveformConfig.kt +0 -19
  27. package/android/src/main/java/net/siteed/audiostream/WaveformRenderer.kt +0 -159
  28. package/android/src/main/res/drawable/ic_default_action_icon.xml +0 -16
  29. package/android/src/main/res/drawable/ic_microphone.xml +0 -13
  30. package/android/src/main/res/drawable/ic_pause.xml +0 -10
  31. package/android/src/main/res/drawable/ic_play.xml +0 -10
  32. package/android/src/main/res/drawable/ic_stop.xml +0 -10
  33. package/android/src/main/res/layout/notification_recording.xml +0 -37
  34. package/android/src/main/test/java/net/siteed/audiostream/AudioProcessorTest.kt +0 -56
  35. package/app.plugin.js +0 -1
  36. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -144
  37. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  38. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  39. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  40. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -78
  41. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  42. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -229
  43. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  44. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  45. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  46. package/build/AudioAnalysis/extractWaveform.js +0 -11
  47. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  48. package/build/AudioRecorder.provider.d.ts +0 -11
  49. package/build/AudioRecorder.provider.d.ts.map +0 -1
  50. package/build/AudioRecorder.provider.js +0 -37
  51. package/build/AudioRecorder.provider.js.map +0 -1
  52. package/build/ExpoAudioStream.native.d.ts +0 -3
  53. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  54. package/build/ExpoAudioStream.native.js +0 -6
  55. package/build/ExpoAudioStream.native.js.map +0 -1
  56. package/build/ExpoAudioStream.types.d.ts +0 -206
  57. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  58. package/build/ExpoAudioStream.types.js +0 -2
  59. package/build/ExpoAudioStream.types.js.map +0 -1
  60. package/build/ExpoAudioStream.web.d.ts +0 -59
  61. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  62. package/build/ExpoAudioStream.web.js +0 -285
  63. package/build/ExpoAudioStream.web.js.map +0 -1
  64. package/build/ExpoAudioStreamModule.d.ts +0 -3
  65. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  66. package/build/ExpoAudioStreamModule.js +0 -239
  67. package/build/ExpoAudioStreamModule.js.map +0 -1
  68. package/build/WebRecorder.web.d.ts +0 -119
  69. package/build/WebRecorder.web.d.ts.map +0 -1
  70. package/build/WebRecorder.web.js +0 -436
  71. package/build/WebRecorder.web.js.map +0 -1
  72. package/build/constants.d.ts +0 -11
  73. package/build/constants.d.ts.map +0 -1
  74. package/build/constants.js +0 -14
  75. package/build/constants.js.map +0 -1
  76. package/build/events.d.ts +0 -26
  77. package/build/events.d.ts.map +0 -1
  78. package/build/events.js +0 -21
  79. package/build/events.js.map +0 -1
  80. package/build/index.d.ts.map +0 -1
  81. package/build/index.js.map +0 -1
  82. package/build/useAudioRecorder.d.ts +0 -21
  83. package/build/useAudioRecorder.d.ts.map +0 -1
  84. package/build/useAudioRecorder.js +0 -427
  85. package/build/useAudioRecorder.js.map +0 -1
  86. package/build/utils/BlobFix.d.ts +0 -9
  87. package/build/utils/BlobFix.d.ts.map +0 -1
  88. package/build/utils/BlobFix.js +0 -498
  89. package/build/utils/BlobFix.js.map +0 -1
  90. package/build/utils/audioProcessing.d.ts +0 -24
  91. package/build/utils/audioProcessing.d.ts.map +0 -1
  92. package/build/utils/audioProcessing.js +0 -133
  93. package/build/utils/audioProcessing.js.map +0 -1
  94. package/build/utils/concatenateBuffers.d.ts +0 -8
  95. package/build/utils/concatenateBuffers.d.ts.map +0 -1
  96. package/build/utils/concatenateBuffers.js +0 -21
  97. package/build/utils/concatenateBuffers.js.map +0 -1
  98. package/build/utils/convertPCMToFloat32.d.ts +0 -13
  99. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  100. package/build/utils/convertPCMToFloat32.js +0 -120
  101. package/build/utils/convertPCMToFloat32.js.map +0 -1
  102. package/build/utils/encodingToBitDepth.d.ts +0 -5
  103. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  104. package/build/utils/encodingToBitDepth.js +0 -13
  105. package/build/utils/encodingToBitDepth.js.map +0 -1
  106. package/build/utils/getWavFileInfo.d.ts +0 -26
  107. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  108. package/build/utils/getWavFileInfo.js +0 -92
  109. package/build/utils/getWavFileInfo.js.map +0 -1
  110. package/build/utils/writeWavHeader.d.ts +0 -49
  111. package/build/utils/writeWavHeader.d.ts.map +0 -1
  112. package/build/utils/writeWavHeader.js +0 -91
  113. package/build/utils/writeWavHeader.js.map +0 -1
  114. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  115. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  116. package/build/workers/InlineFeaturesExtractor.web.js +0 -828
  117. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  118. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  119. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  120. package/build/workers/inlineAudioWebWorker.web.js +0 -157
  121. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  122. package/expo-module.config.json +0 -9
  123. package/ios/AudioAnalysisData.swift +0 -74
  124. package/ios/AudioNotificationManager.swift +0 -135
  125. package/ios/AudioProcessingHelpers.swift +0 -743
  126. package/ios/AudioProcessor.swift +0 -858
  127. package/ios/AudioStreamError.swift +0 -7
  128. package/ios/AudioStreamManager.swift +0 -1708
  129. package/ios/AudioStreamManagerDelegate.swift +0 -16
  130. package/ios/DataPoint.swift +0 -54
  131. package/ios/DecodingConfig.swift +0 -47
  132. package/ios/ExpoAudioStream.podspec +0 -27
  133. package/ios/ExpoAudioStreamModule.swift +0 -698
  134. package/ios/FFT.swift +0 -62
  135. package/ios/Features.swift +0 -95
  136. package/ios/Logger.swift +0 -7
  137. package/ios/NotificationExtension.swift +0 -15
  138. package/ios/RecordingResult.swift +0 -22
  139. package/ios/RecordingSettings.swift +0 -265
  140. package/ios/WaveformExtractor.swift +0 -105
  141. package/plugin/build/index.d.ts +0 -21
  142. package/plugin/build/index.js +0 -191
  143. package/plugin/src/index.ts +0 -278
  144. package/plugin/tsconfig.json +0 -10
  145. package/plugin/tsconfig.tsbuildinfo +0 -1
  146. package/src/AudioAnalysis/AudioAnalysis.types.ts +0 -165
  147. package/src/AudioAnalysis/extractAudioAnalysis.ts +0 -370
  148. package/src/AudioAnalysis/extractWaveform.ts +0 -22
  149. package/src/AudioRecorder.provider.tsx +0 -54
  150. package/src/ExpoAudioStream.native.ts +0 -6
  151. package/src/ExpoAudioStream.types.ts +0 -329
  152. package/src/ExpoAudioStream.web.ts +0 -359
  153. package/src/ExpoAudioStreamModule.ts +0 -286
  154. package/src/WebRecorder.web.ts +0 -580
  155. package/src/constants.ts +0 -18
  156. package/src/events.ts +0 -60
  157. package/src/useAudioRecorder.tsx +0 -620
  158. package/src/utils/BlobFix.ts +0 -559
  159. package/src/utils/audioProcessing.ts +0 -205
  160. package/src/utils/concatenateBuffers.ts +0 -24
  161. package/src/utils/convertPCMToFloat32.ts +0 -170
  162. package/src/utils/encodingToBitDepth.ts +0 -18
  163. package/src/utils/getWavFileInfo.ts +0 -132
  164. package/src/utils/writeWavHeader.ts +0 -114
  165. package/src/workers/InlineFeaturesExtractor.web.tsx +0 -827
  166. package/src/workers/inlineAudioWebWorker.web.tsx +0 -156
@@ -1,286 +0,0 @@
1
- import crc32 from 'crc-32'
2
- import { requireNativeModule } from 'expo-modules-core'
3
- import { Platform } from 'react-native'
4
-
5
- import {
6
- ExtractAudioDataOptions,
7
- ExtractedAudioData,
8
- BitDepth,
9
- } from './ExpoAudioStream.types'
10
- import {
11
- ExpoAudioStreamWeb,
12
- ExpoAudioStreamWebProps,
13
- } from './ExpoAudioStream.web'
14
- import { processAudioBuffer } from './utils/audioProcessing'
15
- import { writeWavHeader } from './utils/writeWavHeader'
16
-
17
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
- let ExpoAudioStreamModule: any
19
-
20
- if (Platform.OS === 'web') {
21
- let instance: ExpoAudioStreamWeb | null = null
22
-
23
- ExpoAudioStreamModule = (webProps: ExpoAudioStreamWebProps) => {
24
- if (!instance) {
25
- instance = new ExpoAudioStreamWeb(webProps)
26
- }
27
- return instance
28
- }
29
- ExpoAudioStreamModule.requestPermissionsAsync = async () => {
30
- try {
31
- const stream = await navigator.mediaDevices.getUserMedia({
32
- audio: true,
33
- })
34
- stream.getTracks().forEach((track) => track.stop())
35
- return {
36
- status: 'granted',
37
- expires: 'never',
38
- canAskAgain: true,
39
- granted: true,
40
- }
41
- } catch {
42
- return {
43
- status: 'denied',
44
- expires: 'never',
45
- canAskAgain: true,
46
- granted: false,
47
- }
48
- }
49
- }
50
- ExpoAudioStreamModule.getPermissionsAsync = async () => {
51
- let maybeStatus: string | null = null
52
-
53
- if (navigator?.permissions?.query) {
54
- try {
55
- const { state } = await navigator.permissions.query({
56
- name: 'microphone' as PermissionName,
57
- })
58
- maybeStatus = state
59
- } catch {
60
- maybeStatus = null
61
- }
62
- }
63
-
64
- switch (maybeStatus) {
65
- case 'granted':
66
- return {
67
- status: 'granted',
68
- expires: 'never',
69
- canAskAgain: true,
70
- granted: true,
71
- }
72
- case 'denied':
73
- return {
74
- status: 'denied',
75
- expires: 'never',
76
- canAskAgain: true,
77
- granted: false,
78
- }
79
- default:
80
- return await ExpoAudioStreamModule.requestPermissionsAsync()
81
- }
82
- }
83
- ExpoAudioStreamModule.extractAudioData = async (
84
- options: ExtractAudioDataOptions
85
- ): Promise<ExtractedAudioData> => {
86
- try {
87
- const {
88
- fileUri,
89
- position,
90
- length,
91
- startTimeMs,
92
- endTimeMs,
93
- decodingOptions,
94
- includeNormalizedData,
95
- includeBase64Data,
96
- includeWavHeader = false,
97
- logger,
98
- } = options
99
-
100
- logger?.debug('EXTRACT AUDIO - Step 1: Initial request', {
101
- fileUri,
102
- extractionParams: {
103
- position,
104
- length,
105
- startTimeMs,
106
- endTimeMs,
107
- },
108
- decodingOptions: {
109
- targetSampleRate:
110
- decodingOptions?.targetSampleRate ?? 16000,
111
- targetChannels: decodingOptions?.targetChannels ?? 1,
112
- targetBitDepth: decodingOptions?.targetBitDepth ?? 16,
113
- normalizeAudio: decodingOptions?.normalizeAudio ?? false,
114
- },
115
- outputOptions: {
116
- includeNormalizedData,
117
- includeBase64Data,
118
- includeWavHeader,
119
- },
120
- })
121
-
122
- // Process the audio using shared helper function
123
- const processedBuffer = await processAudioBuffer({
124
- fileUri,
125
- targetSampleRate: decodingOptions?.targetSampleRate ?? 16000,
126
- targetChannels: decodingOptions?.targetChannels ?? 1,
127
- normalizeAudio: decodingOptions?.normalizeAudio ?? false,
128
- position,
129
- length,
130
- startTimeMs,
131
- endTimeMs,
132
- logger,
133
- })
134
-
135
- logger?.debug('EXTRACT AUDIO - Step 2: Audio processing complete', {
136
- processedData: {
137
- samples: processedBuffer.samples,
138
- sampleRate: processedBuffer.sampleRate,
139
- channels: processedBuffer.channels,
140
- durationMs: processedBuffer.durationMs,
141
- },
142
- })
143
-
144
- const channelData = processedBuffer.channelData
145
- const bitDepth = (decodingOptions?.targetBitDepth ?? 16) as BitDepth
146
- const bytesPerSample = bitDepth / 8
147
- const numSamples = processedBuffer.samples
148
-
149
- logger?.debug('EXTRACT AUDIO - Step 3: PCM conversion setup', {
150
- channelData: {
151
- length: channelData.length,
152
- first: channelData[0],
153
- last: channelData[channelData.length - 1],
154
- },
155
- calculation: {
156
- bitDepth,
157
- bytesPerSample,
158
- numSamples,
159
- expectedBytes: numSamples * bytesPerSample,
160
- },
161
- })
162
-
163
- // Create PCM data with correct length based on original byte length
164
- const pcmData = new Uint8Array(numSamples * bytesPerSample)
165
- let offset = 0
166
-
167
- // Convert Float32 samples to PCM format
168
- for (let i = 0; i < numSamples; i++) {
169
- const sample = channelData[i]
170
- const value = Math.max(-1, Math.min(1, sample))
171
- // Convert to 16-bit signed integer
172
- let intValue = Math.round(value * 32767)
173
-
174
- // Handle negative values correctly
175
- if (intValue < 0) {
176
- intValue = 65536 + intValue
177
- }
178
-
179
- // Write as little-endian
180
- pcmData[offset++] = intValue & 255 // Low byte
181
- pcmData[offset++] = (intValue >> 8) & 255 // High byte
182
- }
183
-
184
- const durationMs = Math.round(
185
- (numSamples / processedBuffer.sampleRate) * 1000
186
- )
187
-
188
- logger?.debug('EXTRACT AUDIO - Step 4: Final output', {
189
- pcmData: {
190
- length: pcmData.length,
191
- first: pcmData[0],
192
- last: pcmData[pcmData.length - 1],
193
- },
194
- timing: {
195
- numSamples,
196
- sampleRate: processedBuffer.sampleRate,
197
- durationMs,
198
- shouldBe3000ms: endTimeMs
199
- ? endTimeMs - (startTimeMs ?? 0) === 3000
200
- : undefined,
201
- },
202
- })
203
-
204
- const result: ExtractedAudioData = {
205
- pcmData: new Uint8Array(pcmData.buffer),
206
- sampleRate: processedBuffer.sampleRate,
207
- channels: processedBuffer.channels,
208
- bitDepth,
209
- durationMs,
210
- format: `pcm_${bitDepth}bit` as const,
211
- samples: numSamples,
212
- }
213
-
214
- // Add WAV header if requested
215
- if (includeWavHeader) {
216
- logger?.debug('EXTRACT AUDIO - Step 4: Adding WAV header', {
217
- originalLength: pcmData.length,
218
- newLength: result.pcmData.length,
219
- firstBytes: Array.from(result.pcmData.slice(0, 44)), // WAV header is 44 bytes
220
- })
221
- const wavBuffer = writeWavHeader({
222
- buffer: pcmData.buffer.slice(0, pcmData.length),
223
- sampleRate: processedBuffer.sampleRate,
224
- numChannels: processedBuffer.channels,
225
- bitDepth,
226
- })
227
- result.pcmData = new Uint8Array(wavBuffer)
228
- result.hasWavHeader = true
229
- }
230
-
231
- if (includeNormalizedData) {
232
- // // Simple approach: Create normalized data directly from the PCM data
233
- // // Just convert to -1 to 1 range without any amplification
234
- // const normalizedData = new Float32Array(numSamples)
235
-
236
- // // Convert the PCM data to float values
237
- // for (let i = 0; i < numSamples; i++) {
238
- // // Get the 16-bit PCM value (little endian)
239
- // const lowByte = pcmData[i * 2]
240
- // const highByte = pcmData[i * 2 + 1]
241
- // const pcmValue = (highByte << 8) | lowByte
242
-
243
- // // Convert to signed 16-bit value
244
- // const signedValue =
245
- // pcmValue > 32767 ? pcmValue - 65536 : pcmValue
246
-
247
- // // Normalize to float between -1 and 1
248
- // normalizedData[i] = signedValue / 32768.0
249
- // }
250
- // Store the normalized data in the result
251
- result.normalizedData = channelData
252
- }
253
-
254
- if (includeBase64Data) {
255
- // Convert the PCM data to a base64 string
256
- const binary = Array.from(new Uint8Array(pcmData.buffer))
257
- .map((b) => String.fromCharCode(b))
258
- .join('')
259
- result.base64Data = btoa(binary)
260
- }
261
-
262
- if (options.computeChecksum) {
263
- result.checksum = crc32.buf(pcmData)
264
- }
265
-
266
- logger?.debug('EXTRACT AUDIO - Step 3: PCM conversion complete', {
267
- pcmStats: {
268
- length: pcmData.length,
269
- bytesPerSample,
270
- totalSamples: numSamples,
271
- firstBytes: Array.from(pcmData.slice(0, 16)),
272
- lastBytes: Array.from(pcmData.slice(-16)),
273
- },
274
- })
275
-
276
- return result
277
- } catch (error) {
278
- options.logger?.error('EXTRACT AUDIO - Error:', error)
279
- throw error
280
- }
281
- }
282
- } else {
283
- ExpoAudioStreamModule = requireNativeModule('ExpoAudioStream')
284
- }
285
-
286
- export default ExpoAudioStreamModule