@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,370 +0,0 @@
1
- // packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts
2
- /**
3
- * This module provides functions for extracting and analyzing audio data.
4
- * - `extractAudioAnalysis`: For detailed analysis with customizable ranges and decoding options.
5
- * - `extractWavAudioAnalysis`: For analyzing WAV files without decoding, preserving original PCM values.
6
- * - `extractPreview`: For generating quick previews of audio waveforms, optimized for UI rendering.
7
- */
8
- import crc32 from 'crc-32'
9
-
10
- import { ConsoleLike, ExtractAudioDataOptions } from '../ExpoAudioStream.types'
11
- import ExpoAudioStreamModule from '../ExpoAudioStreamModule'
12
- import { isWeb } from '../constants'
13
- import {
14
- AudioAnalysis,
15
- AudioFeaturesOptions,
16
- DataPoint,
17
- DecodingConfig,
18
- PreviewOptions,
19
- } from './AudioAnalysis.types'
20
- import { processAudioBuffer } from '../utils/audioProcessing'
21
- import { convertPCMToFloat32 } from '../utils/convertPCMToFloat32'
22
- import { getWavFileInfo, WavFileInfo } from '../utils/getWavFileInfo'
23
- import { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web'
24
-
25
- function calculateCRC32ForDataPoint(data: Float32Array): number {
26
- // Convert float array to byte array for CRC32
27
- const byteArray = new Uint8Array(data.length * 4)
28
- const dataView = new DataView(byteArray.buffer)
29
-
30
- for (let i = 0; i < data.length; i++) {
31
- dataView.setFloat32(i * 4, data[i], true)
32
- }
33
-
34
- return crc32.buf(byteArray)
35
- }
36
-
37
- export interface ExtractWavAudioAnalysisProps {
38
- fileUri?: string // should provide either fileUri or arrayBuffer
39
- wavMetadata?: WavFileInfo
40
- arrayBuffer?: ArrayBuffer
41
- bitDepth?: number
42
- durationMs?: number
43
- sampleRate?: number
44
- numberOfChannels?: number
45
- position?: number // Optional number of bytes to skip. Default is 0
46
- length?: number // Optional number of bytes to read.
47
- segmentDurationMs?: number // Optional number of points per second. Use to reduce the number of points and compute the number of datapoints to return.
48
- features?: AudioFeaturesOptions
49
- featuresExtratorUrl?: string
50
- logger?: ConsoleLike
51
- decodingOptions?: DecodingConfig
52
- }
53
-
54
- // Define base options interface with common properties
55
- interface BaseExtractOptions {
56
- fileUri?: string
57
- arrayBuffer?: ArrayBuffer
58
- /**
59
- * Duration of each analysis segment in milliseconds. Defaults to 100ms if not specified.
60
- */
61
- segmentDurationMs?: number
62
- features?: AudioFeaturesOptions
63
- decodingOptions?: DecodingConfig
64
- logger?: ConsoleLike
65
- }
66
-
67
- // Time-based range options
68
- interface TimeRangeOptions extends BaseExtractOptions {
69
- startTimeMs?: number
70
- endTimeMs?: number
71
- position?: never
72
- length?: never
73
- }
74
-
75
- // Byte-based range options
76
- interface ByteRangeOptions extends BaseExtractOptions {
77
- position?: number
78
- length?: number
79
- startTimeMs?: never
80
- endTimeMs?: never
81
- }
82
-
83
- /**
84
- * Options for extracting audio analysis.
85
- * - For time-based analysis, provide `startTimeMs` and `endTimeMs`.
86
- * - For byte-based analysis, provide `position` and `length`.
87
- * - Do not mix time and byte ranges.
88
- */
89
- export type ExtractAudioAnalysisProps = TimeRangeOptions | ByteRangeOptions
90
-
91
- /**
92
- * Extracts detailed audio analysis from the specified audio file or buffer.
93
- * Supports either time-based or byte-based ranges for flexibility in analysis.
94
- *
95
- * @param props - The options for extraction, including file URI, ranges, and decoding settings.
96
- * @returns A promise that resolves to the audio analysis data.
97
- * @throws {Error} If both time and byte ranges are provided or if required parameters are missing.
98
- */
99
- export async function extractAudioAnalysis(
100
- props: ExtractAudioAnalysisProps
101
- ): Promise<AudioAnalysis> {
102
- const {
103
- fileUri,
104
- arrayBuffer,
105
- decodingOptions,
106
- logger,
107
- segmentDurationMs = 100,
108
- features,
109
- } = props
110
-
111
- if (isWeb) {
112
- try {
113
- // Create AudioContext here
114
- const audioContext = new (window.AudioContext ||
115
- (window as any).webkitAudioContext)({
116
- sampleRate: decodingOptions?.targetSampleRate ?? 16000,
117
- })
118
-
119
- try {
120
- const processedBuffer = await processAudioBuffer({
121
- arrayBuffer,
122
- fileUri,
123
- targetSampleRate:
124
- decodingOptions?.targetSampleRate ?? 16000,
125
- targetChannels: decodingOptions?.targetChannels ?? 1,
126
- normalizeAudio: decodingOptions?.normalizeAudio ?? false,
127
- startTimeMs:
128
- 'startTimeMs' in props ? props.startTimeMs : undefined,
129
- endTimeMs:
130
- 'endTimeMs' in props ? props.endTimeMs : undefined,
131
- position: 'position' in props ? props.position : undefined,
132
- length: 'length' in props ? props.length : undefined,
133
- audioContext, // Pass the context we created
134
- logger,
135
- })
136
-
137
- const channelData = processedBuffer.buffer.getChannelData(0)
138
-
139
- // Create and initialize the worker
140
- const blob = new Blob([InlineFeaturesExtractor], {
141
- type: 'application/javascript',
142
- })
143
- const workerUrl = URL.createObjectURL(blob)
144
- const worker = new Worker(workerUrl)
145
-
146
- return new Promise((resolve, reject) => {
147
- worker.onmessage = (event) => {
148
- if (event.data.error) {
149
- reject(new Error(event.data.error))
150
- return
151
- }
152
-
153
- const result: AudioAnalysis = event.data.result
154
- // Calculate CRC32 after worker completes if requested
155
- if (features?.crc32) {
156
- const samplesPerSegment = Math.floor(
157
- (processedBuffer.sampleRate *
158
- segmentDurationMs) /
159
- 1000
160
- )
161
-
162
- result.dataPoints = result.dataPoints.map(
163
- (point: DataPoint, index: number) => {
164
- const startSample =
165
- index * samplesPerSegment
166
- const segmentData = channelData.slice(
167
- startSample,
168
- startSample + samplesPerSegment
169
- )
170
-
171
- return {
172
- ...point,
173
- features: {
174
- ...point.features,
175
- crc32: calculateCRC32ForDataPoint(
176
- segmentData
177
- ),
178
- },
179
- }
180
- }
181
- )
182
- }
183
-
184
- URL.revokeObjectURL(workerUrl)
185
- worker.terminate()
186
- resolve(result)
187
- }
188
-
189
- worker.onerror = (error) => {
190
- URL.revokeObjectURL(workerUrl)
191
- worker.terminate()
192
- reject(error)
193
- }
194
-
195
- worker.postMessage({
196
- channelData,
197
- sampleRate: processedBuffer.sampleRate,
198
- segmentDurationMs,
199
- bitDepth: decodingOptions?.targetBitDepth ?? 32,
200
- numberOfChannels: processedBuffer.channels,
201
- // enableLogging: !!logger,
202
- features,
203
- })
204
- })
205
- } finally {
206
- await audioContext.close()
207
- }
208
- } catch (error) {
209
- logger?.error('Failed to process audio:', error)
210
- throw error
211
- }
212
- } else {
213
- return await ExpoAudioStreamModule.extractAudioAnalysis(props)
214
- }
215
- }
216
-
217
- /**
218
- * Analyzes WAV files without decoding, preserving original PCM values.
219
- * Use this function when you need to ensure the analysis matches other software by avoiding any transformations.
220
- *
221
- * @param props - The options for WAV analysis, including file URI and range.
222
- * @returns A promise that resolves to the audio analysis data.
223
- */
224
- export const extractRawWavAnalysis = async ({
225
- fileUri,
226
- segmentDurationMs = 100, // Default to 100ms
227
- arrayBuffer,
228
- bitDepth,
229
- durationMs,
230
- sampleRate,
231
- numberOfChannels,
232
- features,
233
- logger,
234
- position = 0,
235
- length,
236
- }: ExtractWavAudioAnalysisProps): Promise<AudioAnalysis> => {
237
- if (isWeb) {
238
- if (!arrayBuffer && !fileUri) {
239
- throw new Error('Either arrayBuffer or fileUri must be provided')
240
- }
241
-
242
- if (!arrayBuffer) {
243
- logger?.log(`fetching fileUri`, fileUri)
244
- const response = await fetch(fileUri!)
245
-
246
- if (!response.ok) {
247
- throw new Error(
248
- `Failed to fetch fileUri: ${response.statusText}`
249
- )
250
- }
251
-
252
- arrayBuffer = await response.arrayBuffer()
253
- logger?.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)
254
- }
255
-
256
- // Create a new copy of the ArrayBuffer to avoid detachment issues
257
- const bufferCopy = arrayBuffer.slice(0)
258
- logger?.log(
259
- `extractAudioAnalysis bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,
260
- bufferCopy.slice(0, 100)
261
- )
262
-
263
- let actualBitDepth = bitDepth
264
- if (!actualBitDepth) {
265
- logger?.log(
266
- `extractAudioAnalysis bitDepth not provided -- getting wav file info`
267
- )
268
- const fileInfo = await getWavFileInfo(bufferCopy)
269
- actualBitDepth = fileInfo.bitDepth
270
- }
271
- logger?.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`)
272
-
273
- const {
274
- pcmValues: channelData,
275
- min,
276
- max,
277
- } = await convertPCMToFloat32({
278
- buffer: arrayBuffer,
279
- bitDepth: actualBitDepth,
280
- })
281
- logger?.log(
282
- `extractAudioAnalysis convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`
283
- )
284
-
285
- // Apply position and length constraints to channelData if specified
286
- const startIndex = position
287
- const endIndex = length ? startIndex + length : channelData.length
288
- const constrainedChannelData = channelData.slice(startIndex, endIndex)
289
-
290
- return new Promise((resolve, reject) => {
291
- const blob = new Blob([InlineFeaturesExtractor], {
292
- type: 'application/javascript',
293
- })
294
- const url = URL.createObjectURL(blob)
295
- const worker = new Worker(url)
296
-
297
- worker.onmessage = (event) => {
298
- resolve(event.data.result)
299
- }
300
-
301
- worker.onerror = (error) => {
302
- reject(error)
303
- }
304
-
305
- worker.postMessage({
306
- command: 'process',
307
- channelData: constrainedChannelData,
308
- sampleRate,
309
- segmentDurationMs,
310
- logger,
311
- bitDepth,
312
- fullAudioDurationMs: durationMs,
313
- numberOfChannels,
314
- })
315
- })
316
- } else {
317
- if (!fileUri) {
318
- throw new Error('fileUri is required')
319
- }
320
- logger?.log(`extractAudioAnalysis`, {
321
- fileUri,
322
- segmentDurationMs,
323
- })
324
- const res = await ExpoAudioStreamModule.extractAudioAnalysis({
325
- fileUri,
326
- segmentDurationMs,
327
- features,
328
- position,
329
- length,
330
- })
331
- logger?.log(`extractAudioAnalysis`, res)
332
- return res
333
- }
334
- }
335
-
336
- /**
337
- * Generates a simplified preview of the audio waveform for quick visualization.
338
- * Ideal for UI rendering with a specified number of points.
339
- *
340
- * @param options - The options for the preview, including file URI and time range.
341
- * @returns A promise that resolves to the audio preview data.
342
- */
343
- export async function extractPreview({
344
- fileUri,
345
- numberOfPoints = 100,
346
- startTimeMs = 0,
347
- endTimeMs = 30000, // First 30 seconds
348
- decodingOptions,
349
- logger,
350
- }: PreviewOptions): Promise<AudioAnalysis> {
351
- const durationMs = endTimeMs - startTimeMs
352
- const segmentDurationMs = Math.floor(durationMs / numberOfPoints)
353
-
354
- // Call extractAudioAnalysis with calculated parameters
355
- const analysis = await extractAudioAnalysis({
356
- fileUri,
357
- startTimeMs,
358
- endTimeMs,
359
- logger,
360
- segmentDurationMs,
361
- decodingOptions,
362
- })
363
-
364
- // Transform the result into AudioPreview format
365
- return analysis
366
- }
367
-
368
- export const extractAudioData = async (props: ExtractAudioDataOptions) => {
369
- return await ExpoAudioStreamModule.extractAudioData(props)
370
- }
@@ -1,22 +0,0 @@
1
- import ExpoAudioStreamModule from '../ExpoAudioStreamModule'
2
-
3
- export interface ExtractWaveformProps {
4
- fileUri: string
5
- numberOfSamples: number
6
- offset?: number
7
- length?: number
8
- }
9
- export const extractWaveform = async ({
10
- fileUri,
11
- numberOfSamples,
12
- offset = 0,
13
- length,
14
- }: ExtractWaveformProps): Promise<unknown> => {
15
- const res = await ExpoAudioStreamModule.extractAudioAnalysis({
16
- fileUri,
17
- numberOfSamples,
18
- offset,
19
- length,
20
- })
21
- return res
22
- }
@@ -1,54 +0,0 @@
1
- // packages/expo-audio-stream/src/AudioRecorder.provider.tsx
2
- import React, { createContext, useContext } from 'react'
3
-
4
- import { UseAudioRecorderState } from './ExpoAudioStream.types'
5
- import { UseAudioRecorderProps, useAudioRecorder } from './useAudioRecorder'
6
-
7
- const initContext: UseAudioRecorderState = {
8
- isRecording: false,
9
- isPaused: false,
10
- durationMs: 0,
11
- size: 0,
12
- compression: undefined,
13
- startRecording: async () => {
14
- throw new Error('AudioRecorderProvider not found')
15
- },
16
- stopRecording: async () => {
17
- throw new Error('AudioRecorderProvider not found')
18
- },
19
- pauseRecording: async () => {
20
- throw new Error('AudioRecorderProvider not found')
21
- },
22
- resumeRecording: async () => {
23
- throw new Error('AudioRecorderProvider not found')
24
- },
25
- }
26
-
27
- const AudioRecorderContext = createContext<UseAudioRecorderState>(initContext)
28
-
29
- interface AudioRecorderProviderProps {
30
- children: React.ReactNode
31
- config?: UseAudioRecorderProps
32
- }
33
-
34
- export const AudioRecorderProvider: React.FC<AudioRecorderProviderProps> = ({
35
- children,
36
- config = {},
37
- }) => {
38
- const audioRecorder = useAudioRecorder(config)
39
- return (
40
- <AudioRecorderContext.Provider value={audioRecorder}>
41
- {children}
42
- </AudioRecorderContext.Provider>
43
- )
44
- }
45
-
46
- export const useSharedAudioRecorder = () => {
47
- const context = useContext(AudioRecorderContext)
48
- if (!context) {
49
- throw new Error(
50
- 'useSharedAudioRecorder must be used within an AudioRecorderProvider'
51
- )
52
- }
53
- return context
54
- }
@@ -1,6 +0,0 @@
1
- // src/ExpoAudioStreamModule.ts
2
- import { requireNativeModule } from 'expo-modules-core'
3
-
4
- // It loads the native module object from the JSI or falls back to
5
- // the bridge module (from NativeModulesProxy) if the remote debugger is on.
6
- export default requireNativeModule('ExpoAudioStream')