@siteed/expo-audio-stream 2.0.1 → 2.1.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.
- package/CHANGELOG.md +12 -1
- package/README.md +202 -1
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +300 -1
- package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +16 -2
- package/android/src/main/java/net/siteed/audiostream/AudioTrimmer.kt +1099 -0
- package/android/src/main/java/net/siteed/audiostream/Constants.kt +1 -0
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +274 -44
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +35 -0
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -1
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -1
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +2 -12
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -1
- package/build/AudioAnalysis/extractAudioAnalysis.js +0 -26
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -1
- 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/ExpoAudioStream.types.d.ts +329 -3
- package/build/ExpoAudioStream.types.d.ts.map +1 -1
- package/build/ExpoAudioStream.types.js.map +1 -1
- package/build/ExpoAudioStreamModule.d.ts.map +1 -1
- package/build/ExpoAudioStreamModule.js +455 -1
- package/build/ExpoAudioStreamModule.js.map +1 -1
- package/build/WebRecorder.web.js +2 -2
- package/build/WebRecorder.web.js.map +1 -1
- package/build/index.d.ts +6 -3
- package/build/index.d.ts.map +1 -1
- package/build/index.js +6 -2
- package/build/index.js.map +1 -1
- 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/ios/AudioProcessor.swift +536 -81
- package/ios/ExpoAudioStreamModule.swift +125 -18
- package/package.json +1 -1
- package/src/AudioAnalysis/AudioAnalysis.types.ts +38 -1
- package/src/AudioAnalysis/extractAudioAnalysis.ts +1 -38
- package/src/AudioAnalysis/extractAudioData.ts +6 -0
- package/src/AudioAnalysis/extractMelSpectrogram.ts +144 -0
- package/src/AudioAnalysis/extractPreview.ts +34 -0
- package/src/ExpoAudioStream.types.ts +354 -42
- package/src/ExpoAudioStreamModule.ts +682 -1
- package/src/WebRecorder.web.ts +2 -2
- package/src/index.ts +7 -8
- package/src/trimAudio.ts +90 -0
package/src/WebRecorder.web.ts
CHANGED
|
@@ -302,7 +302,7 @@ export class WebRecorder {
|
|
|
302
302
|
}
|
|
303
303
|
}
|
|
304
304
|
|
|
305
|
-
|
|
305
|
+
this.logger?.debug('[WebRecorder] Raw segment result:', {
|
|
306
306
|
dataPointsLength: segmentResult.dataPoints.length,
|
|
307
307
|
durationMs: segmentResult.durationMs,
|
|
308
308
|
sampleRate: segmentResult.sampleRate,
|
|
@@ -367,7 +367,7 @@ export class WebRecorder {
|
|
|
367
367
|
)
|
|
368
368
|
this.emitAudioAnalysisCallback(segmentResult)
|
|
369
369
|
|
|
370
|
-
|
|
370
|
+
this.logger?.debug('[WebRecorder] Updated audioAnalysisData:', {
|
|
371
371
|
dataPointsLength: this.audioAnalysisData.dataPoints.length,
|
|
372
372
|
durationMs: this.audioAnalysisData.durationMs,
|
|
373
373
|
sampleRate: this.audioAnalysisData.sampleRate,
|
package/src/index.ts
CHANGED
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
import {
|
|
4
4
|
extractRawWavAnalysis,
|
|
5
5
|
extractAudioAnalysis,
|
|
6
|
-
extractPreview,
|
|
7
|
-
extractAudioData,
|
|
8
6
|
} from './AudioAnalysis/extractAudioAnalysis'
|
|
7
|
+
import { extractAudioData } from './AudioAnalysis/extractAudioData'
|
|
8
|
+
import { extractMelSpectrogram } from './AudioAnalysis/extractMelSpectrogram'
|
|
9
|
+
import { extractPreview } from './AudioAnalysis/extractPreview'
|
|
9
10
|
import {
|
|
10
11
|
AudioRecorderProvider,
|
|
11
12
|
useSharedAudioRecorder,
|
|
12
13
|
} from './AudioRecorder.provider'
|
|
13
14
|
import ExpoAudioStreamModule from './ExpoAudioStreamModule'
|
|
15
|
+
import { trimAudio } from './trimAudio'
|
|
14
16
|
import { useAudioRecorder } from './useAudioRecorder'
|
|
15
17
|
|
|
16
18
|
export * from './utils/convertPCMToFloat32'
|
|
@@ -20,18 +22,15 @@ export * from './utils/writeWavHeader'
|
|
|
20
22
|
export {
|
|
21
23
|
AudioRecorderProvider,
|
|
22
24
|
ExpoAudioStreamModule,
|
|
23
|
-
extractRawWavAnalysis
|
|
25
|
+
extractRawWavAnalysis,
|
|
24
26
|
extractAudioAnalysis,
|
|
25
27
|
extractPreview,
|
|
28
|
+
trimAudio,
|
|
26
29
|
extractAudioData,
|
|
30
|
+
extractMelSpectrogram,
|
|
27
31
|
useAudioRecorder,
|
|
28
32
|
useSharedAudioRecorder,
|
|
29
33
|
}
|
|
30
34
|
|
|
31
35
|
export type * from './AudioAnalysis/AudioAnalysis.types'
|
|
32
|
-
|
|
33
36
|
export type * from './ExpoAudioStream.types'
|
|
34
|
-
export type {
|
|
35
|
-
ExtractWavAudioAnalysisProps,
|
|
36
|
-
ExtractAudioAnalysisProps,
|
|
37
|
-
} from './AudioAnalysis/extractAudioAnalysis'
|
package/src/trimAudio.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TrimAudioOptions,
|
|
5
|
+
TrimAudioResult,
|
|
6
|
+
TrimProgressEvent,
|
|
7
|
+
} from './ExpoAudioStream.types'
|
|
8
|
+
import ExpoAudioStreamModule from './ExpoAudioStreamModule'
|
|
9
|
+
|
|
10
|
+
// Create a single emitter instance
|
|
11
|
+
const emitter = new LegacyEventEmitter(ExpoAudioStreamModule)
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Trims an audio file based on the provided options.
|
|
15
|
+
*
|
|
16
|
+
* @experimental This API is experimental and not fully optimized for production use.
|
|
17
|
+
* Performance may vary based on file size and device capabilities.
|
|
18
|
+
* Future versions may include breaking changes.
|
|
19
|
+
*
|
|
20
|
+
* @param options Configuration options for the trimming operation
|
|
21
|
+
* @param progressCallback Optional callback to receive progress updates
|
|
22
|
+
* @returns Promise resolving to the trimmed audio file information, including processing time
|
|
23
|
+
*/
|
|
24
|
+
export async function trimAudio(
|
|
25
|
+
options: TrimAudioOptions,
|
|
26
|
+
progressCallback?: (event: TrimProgressEvent) => void
|
|
27
|
+
): Promise<TrimAudioResult> {
|
|
28
|
+
// Validation
|
|
29
|
+
if (!options.fileUri) {
|
|
30
|
+
throw new Error('fileUri is required')
|
|
31
|
+
}
|
|
32
|
+
const mode = options.mode ?? 'single'
|
|
33
|
+
if (mode === 'single') {
|
|
34
|
+
if (
|
|
35
|
+
options.startTimeMs === undefined &&
|
|
36
|
+
options.endTimeMs === undefined
|
|
37
|
+
) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
'At least one of startTimeMs or endTimeMs must be provided in single mode'
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
} else if (mode === 'keep' || mode === 'remove') {
|
|
43
|
+
if (!options.ranges || options.ranges.length === 0) {
|
|
44
|
+
throw new Error(
|
|
45
|
+
'ranges must be provided and non-empty for keep or remove modes'
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Set up progress event listener if callback is provided
|
|
55
|
+
let subscription: EventSubscription | undefined
|
|
56
|
+
if (progressCallback) {
|
|
57
|
+
subscription = emitter.addListener(
|
|
58
|
+
'TrimProgress',
|
|
59
|
+
(event: TrimProgressEvent) => {
|
|
60
|
+
progressCallback(event)
|
|
61
|
+
}
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
try {
|
|
66
|
+
const result = await ExpoAudioStreamModule.trimAudio(options)
|
|
67
|
+
return result
|
|
68
|
+
} finally {
|
|
69
|
+
if (subscription) {
|
|
70
|
+
subscription.remove()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Simplified version of trimAudio that returns only the URI of the trimmed file.
|
|
77
|
+
*
|
|
78
|
+
* @experimental This API is experimental and not fully optimized for production use.
|
|
79
|
+
* Performance may vary based on file size and device capabilities.
|
|
80
|
+
* Future versions may include breaking changes.
|
|
81
|
+
*
|
|
82
|
+
* @param options Configuration options for the trimming operation
|
|
83
|
+
* @returns Promise resolving to the URI of the trimmed audio file
|
|
84
|
+
*/
|
|
85
|
+
export async function trimAudioSimple(
|
|
86
|
+
options: TrimAudioOptions
|
|
87
|
+
): Promise<string> {
|
|
88
|
+
const result = await trimAudio(options)
|
|
89
|
+
return result.uri
|
|
90
|
+
}
|