@siteed/expo-audio-stream 2.0.0 → 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 +17 -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/plugin/build/index.js +6 -1
- package/plugin/src/index.ts +9 -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
|
@@ -7,32 +7,52 @@ import {
|
|
|
7
7
|
import { AudioAnalysisEvent } from './events'
|
|
8
8
|
|
|
9
9
|
export interface CompressionInfo {
|
|
10
|
+
/** Size of the compressed audio data in bytes */
|
|
10
11
|
size: number
|
|
12
|
+
/** MIME type of the compressed audio (e.g., 'audio/aac', 'audio/opus') */
|
|
11
13
|
mimeType: string
|
|
14
|
+
/** Bitrate of the compressed audio in bits per second */
|
|
12
15
|
bitrate: number
|
|
16
|
+
/** Format of the compression (e.g., 'aac', 'opus') */
|
|
13
17
|
format: string
|
|
18
|
+
/** URI to the compressed audio file if available */
|
|
14
19
|
compressedFileUri?: string
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export interface AudioStreamStatus {
|
|
23
|
+
/** Indicates whether audio recording is currently active */
|
|
18
24
|
isRecording: boolean
|
|
25
|
+
/** Indicates whether recording is in a paused state */
|
|
19
26
|
isPaused: boolean
|
|
27
|
+
/** Duration of the current recording in milliseconds */
|
|
20
28
|
durationMs: number
|
|
29
|
+
/** Size of the recorded audio data in bytes */
|
|
21
30
|
size: number
|
|
31
|
+
/** Interval in milliseconds at which recording data is emitted */
|
|
22
32
|
interval: number
|
|
33
|
+
/** Interval in milliseconds at which analysis data is emitted */
|
|
23
34
|
intervalAnalysis: number
|
|
35
|
+
/** MIME type of the recorded audio (e.g., 'audio/wav') */
|
|
24
36
|
mimeType: string
|
|
37
|
+
/** Information about audio compression if enabled */
|
|
25
38
|
compression?: CompressionInfo
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
export interface AudioDataEvent {
|
|
42
|
+
/** Audio data as base64 string (native) or Float32Array (web) */
|
|
29
43
|
data: string | Float32Array
|
|
44
|
+
/** Current position in the audio stream in bytes */
|
|
30
45
|
position: number
|
|
46
|
+
/** URI to the file being recorded */
|
|
31
47
|
fileUri: string
|
|
48
|
+
/** Size of the current data chunk in bytes */
|
|
32
49
|
eventDataSize: number
|
|
50
|
+
/** Total size of the recording so far in bytes */
|
|
33
51
|
totalSize: number
|
|
52
|
+
/** Information about compression if enabled, including the compressed data chunk */
|
|
34
53
|
compression?: CompressionInfo & {
|
|
35
|
-
|
|
54
|
+
/** Base64 (native) or Blob (web) encoded compressed data chunk */
|
|
55
|
+
data?: string | Blob
|
|
36
56
|
}
|
|
37
57
|
}
|
|
38
58
|
|
|
@@ -42,56 +62,98 @@ export type BitDepth = 8 | 16 | 32
|
|
|
42
62
|
export type PCMFormat = `pcm_${BitDepth}bit`
|
|
43
63
|
|
|
44
64
|
export type ConsoleLike = {
|
|
65
|
+
/** Logs a message with optional arguments */
|
|
45
66
|
log: (message: string, ...args: unknown[]) => void
|
|
67
|
+
/** Logs a debug message with optional arguments */
|
|
46
68
|
debug: (message: string, ...args: unknown[]) => void
|
|
69
|
+
/** Logs an info message with optional arguments */
|
|
47
70
|
info: (message: string, ...args: unknown[]) => void
|
|
71
|
+
/** Logs a warning message with optional arguments */
|
|
48
72
|
warn: (message: string, ...args: unknown[]) => void
|
|
73
|
+
/** Logs an error message with optional arguments */
|
|
49
74
|
error: (message: string, ...args: unknown[]) => void
|
|
50
75
|
}
|
|
51
76
|
|
|
52
77
|
export interface Chunk {
|
|
78
|
+
/** Transcribed text content */
|
|
53
79
|
text: string
|
|
80
|
+
/** Start and end timestamp in seconds [start, end] where end can be null if ongoing */
|
|
54
81
|
timestamp: [number, number | null]
|
|
55
82
|
}
|
|
56
83
|
|
|
57
84
|
export interface TranscriberData {
|
|
85
|
+
/** Unique identifier for the transcription */
|
|
58
86
|
id: string
|
|
87
|
+
/** Indicates if the transcriber is currently processing */
|
|
59
88
|
isBusy: boolean
|
|
89
|
+
/** Complete transcribed text */
|
|
60
90
|
text: string
|
|
91
|
+
/** Start time of the transcription in milliseconds */
|
|
61
92
|
startTime: number
|
|
93
|
+
/** End time of the transcription in milliseconds */
|
|
62
94
|
endTime: number
|
|
95
|
+
/** Array of transcribed text chunks with timestamps */
|
|
63
96
|
chunks: Chunk[]
|
|
64
97
|
}
|
|
65
98
|
|
|
66
99
|
export interface AudioRecording {
|
|
100
|
+
/** URI to the recorded audio file */
|
|
67
101
|
fileUri: string
|
|
102
|
+
/** Filename of the recorded audio */
|
|
68
103
|
filename: string
|
|
104
|
+
/** Duration of the recording in milliseconds */
|
|
69
105
|
durationMs: number
|
|
106
|
+
/** Size of the recording in bytes */
|
|
70
107
|
size: number
|
|
108
|
+
/** MIME type of the recorded audio */
|
|
71
109
|
mimeType: string
|
|
110
|
+
/** Number of audio channels (1 for mono, 2 for stereo) */
|
|
72
111
|
channels: number
|
|
112
|
+
/** Bit depth of the audio (8, 16, or 32 bits) */
|
|
73
113
|
bitDepth: BitDepth
|
|
114
|
+
/** Sample rate of the audio in Hz */
|
|
74
115
|
sampleRate: SampleRate
|
|
116
|
+
/** Timestamp when the recording was created */
|
|
75
117
|
createdAt?: number
|
|
118
|
+
/** Array of transcription data if available */
|
|
76
119
|
transcripts?: TranscriberData[]
|
|
77
|
-
|
|
120
|
+
/** Analysis data for the recording if processing was enabled */
|
|
121
|
+
analysisData?: AudioAnalysis
|
|
122
|
+
/** Information about compression if enabled, including the URI to the compressed file */
|
|
78
123
|
compression?: CompressionInfo & {
|
|
124
|
+
/** URI to the compressed audio file */
|
|
79
125
|
compressedFileUri: string
|
|
80
126
|
}
|
|
81
127
|
}
|
|
82
128
|
|
|
83
129
|
export interface StartRecordingResult {
|
|
130
|
+
/** URI to the file being recorded */
|
|
84
131
|
fileUri: string
|
|
132
|
+
/** MIME type of the recording */
|
|
85
133
|
mimeType: string
|
|
134
|
+
/** Number of audio channels (1 for mono, 2 for stereo) */
|
|
86
135
|
channels?: number
|
|
136
|
+
/** Bit depth of the audio (8, 16, or 32 bits) */
|
|
87
137
|
bitDepth?: BitDepth
|
|
138
|
+
/** Sample rate of the audio in Hz */
|
|
88
139
|
sampleRate?: SampleRate
|
|
140
|
+
/** Information about compression if enabled, including the URI to the compressed file */
|
|
89
141
|
compression?: CompressionInfo & {
|
|
142
|
+
/** URI to the compressed audio file */
|
|
90
143
|
compressedFileUri: string
|
|
91
144
|
}
|
|
92
145
|
}
|
|
93
146
|
|
|
94
147
|
export interface AudioSessionConfig {
|
|
148
|
+
/**
|
|
149
|
+
* Audio session category that defines the audio behavior
|
|
150
|
+
* - 'Ambient': Audio continues with silent switch, mixes with other audio
|
|
151
|
+
* - 'SoloAmbient': Audio continues with silent switch, interrupts other audio
|
|
152
|
+
* - 'Playback': Audio continues in background, interrupts other audio
|
|
153
|
+
* - 'Record': Optimized for recording, interrupts other audio
|
|
154
|
+
* - 'PlayAndRecord': Allows simultaneous playback and recording
|
|
155
|
+
* - 'MultiRoute': Routes audio to multiple outputs simultaneously
|
|
156
|
+
*/
|
|
95
157
|
category?:
|
|
96
158
|
| 'Ambient'
|
|
97
159
|
| 'SoloAmbient'
|
|
@@ -99,6 +161,17 @@ export interface AudioSessionConfig {
|
|
|
99
161
|
| 'Record'
|
|
100
162
|
| 'PlayAndRecord'
|
|
101
163
|
| 'MultiRoute'
|
|
164
|
+
/**
|
|
165
|
+
* Audio session mode that defines the behavior for specific use cases
|
|
166
|
+
* - 'Default': Standard audio behavior
|
|
167
|
+
* - 'VoiceChat': Optimized for voice chat applications
|
|
168
|
+
* - 'VideoChat': Optimized for video chat applications
|
|
169
|
+
* - 'GameChat': Optimized for in-game chat
|
|
170
|
+
* - 'VideoRecording': Optimized for video recording
|
|
171
|
+
* - 'Measurement': Optimized for audio measurement
|
|
172
|
+
* - 'MoviePlayback': Optimized for movie playback
|
|
173
|
+
* - 'SpokenAudio': Optimized for spoken audio content
|
|
174
|
+
*/
|
|
102
175
|
mode?:
|
|
103
176
|
| 'Default'
|
|
104
177
|
| 'VoiceChat'
|
|
@@ -108,6 +181,16 @@ export interface AudioSessionConfig {
|
|
|
108
181
|
| 'Measurement'
|
|
109
182
|
| 'MoviePlayback'
|
|
110
183
|
| 'SpokenAudio'
|
|
184
|
+
/**
|
|
185
|
+
* Options that modify the behavior of the audio session category
|
|
186
|
+
* - 'MixWithOthers': Allows mixing with other active audio sessions
|
|
187
|
+
* - 'DuckOthers': Reduces the volume of other audio sessions
|
|
188
|
+
* - 'InterruptSpokenAudioAndMixWithOthers': Interrupts spoken audio and mixes with others
|
|
189
|
+
* - 'AllowBluetooth': Allows audio routing to Bluetooth devices
|
|
190
|
+
* - 'AllowBluetoothA2DP': Allows audio routing to Bluetooth A2DP devices
|
|
191
|
+
* - 'AllowAirPlay': Allows audio routing to AirPlay devices
|
|
192
|
+
* - 'DefaultToSpeaker': Routes audio to the speaker by default
|
|
193
|
+
*/
|
|
111
194
|
categoryOptions?: (
|
|
112
195
|
| 'MixWithOthers'
|
|
113
196
|
| 'DuckOthers'
|
|
@@ -120,160 +203,182 @@ export interface AudioSessionConfig {
|
|
|
120
203
|
}
|
|
121
204
|
|
|
122
205
|
export interface IOSConfig {
|
|
206
|
+
/** Configuration for the iOS audio session */
|
|
123
207
|
audioSession?: AudioSessionConfig
|
|
124
208
|
}
|
|
125
209
|
|
|
126
210
|
// Add new type for interruption reasons
|
|
127
211
|
export type RecordingInterruptionReason =
|
|
212
|
+
/** Audio focus was lost to another app */
|
|
128
213
|
| 'audioFocusLoss'
|
|
214
|
+
/** Audio focus was regained */
|
|
129
215
|
| 'audioFocusGain'
|
|
216
|
+
/** Recording was interrupted by a phone call */
|
|
130
217
|
| 'phoneCall'
|
|
218
|
+
/** Phone call that interrupted recording has ended */
|
|
131
219
|
| 'phoneCallEnded'
|
|
220
|
+
/** Recording was stopped by the system or another app */
|
|
132
221
|
| 'recordingStopped'
|
|
133
222
|
|
|
134
223
|
// Add new interface for interruption events
|
|
135
224
|
export interface RecordingInterruptionEvent {
|
|
225
|
+
/** The reason for the recording interruption */
|
|
136
226
|
reason: RecordingInterruptionReason
|
|
227
|
+
/** Indicates whether the recording is paused due to the interruption */
|
|
137
228
|
isPaused: boolean
|
|
138
229
|
}
|
|
139
230
|
|
|
140
231
|
export interface RecordingConfig {
|
|
141
|
-
|
|
232
|
+
/** Sample rate for recording in Hz (16000, 44100, or 48000) */
|
|
142
233
|
sampleRate?: SampleRate
|
|
143
234
|
|
|
144
|
-
|
|
235
|
+
/** Number of audio channels (1 for mono, 2 for stereo) */
|
|
145
236
|
channels?: 1 | 2
|
|
146
237
|
|
|
147
|
-
|
|
238
|
+
/** Encoding type for the recording (pcm_32bit, pcm_16bit, pcm_8bit) */
|
|
148
239
|
encoding?: EncodingType
|
|
149
240
|
|
|
150
|
-
|
|
241
|
+
/** Interval in milliseconds at which to emit recording data */
|
|
151
242
|
interval?: number
|
|
152
243
|
|
|
153
|
-
|
|
244
|
+
/** Interval in milliseconds at which to emit analysis data */
|
|
154
245
|
intervalAnalysis?: number
|
|
155
246
|
|
|
156
|
-
|
|
247
|
+
/** Keep the device awake while recording (default is false) */
|
|
157
248
|
keepAwake?: boolean
|
|
158
249
|
|
|
159
|
-
|
|
250
|
+
/** Show a notification during recording (default is false) */
|
|
160
251
|
showNotification?: boolean
|
|
161
252
|
|
|
162
|
-
|
|
253
|
+
/** Show waveform in the notification (Android only, when showNotification is true) */
|
|
163
254
|
showWaveformInNotification?: boolean
|
|
164
255
|
|
|
165
|
-
|
|
256
|
+
/** Configuration for the notification */
|
|
166
257
|
notification?: NotificationConfig
|
|
167
258
|
|
|
168
|
-
|
|
259
|
+
/** Enable audio processing (default is false) */
|
|
169
260
|
enableProcessing?: boolean
|
|
170
261
|
|
|
171
|
-
|
|
262
|
+
/** iOS-specific configuration */
|
|
172
263
|
ios?: IOSConfig
|
|
173
264
|
|
|
174
|
-
|
|
265
|
+
/** Duration of each segment in milliseconds for analysis (default: 100) */
|
|
175
266
|
segmentDurationMs?: number
|
|
176
267
|
|
|
177
|
-
|
|
268
|
+
/** Feature options to extract during audio processing */
|
|
178
269
|
features?: AudioFeaturesOptions
|
|
179
270
|
|
|
180
|
-
|
|
271
|
+
/** Callback function to handle audio stream data */
|
|
181
272
|
onAudioStream?: (_: AudioDataEvent) => Promise<void>
|
|
182
273
|
|
|
183
|
-
|
|
274
|
+
/** Callback function to handle audio features extraction results */
|
|
184
275
|
onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>
|
|
185
276
|
|
|
277
|
+
/** Configuration for audio compression */
|
|
186
278
|
compression?: {
|
|
279
|
+
/** Enable audio compression */
|
|
187
280
|
enabled: boolean
|
|
281
|
+
/** Format for compression (aac or opus) */
|
|
188
282
|
format: 'aac' | 'opus'
|
|
283
|
+
/** Bitrate for compression in bits per second */
|
|
189
284
|
bitrate?: number
|
|
190
285
|
}
|
|
191
286
|
|
|
192
|
-
|
|
287
|
+
/** Whether to automatically resume recording after an interruption (default is false) */
|
|
193
288
|
autoResumeAfterInterruption?: boolean
|
|
194
289
|
|
|
195
|
-
|
|
290
|
+
/** Optional callback to handle recording interruptions */
|
|
196
291
|
onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void
|
|
197
292
|
|
|
198
|
-
|
|
293
|
+
/** Optional directory path where output files will be saved */
|
|
199
294
|
outputDirectory?: string // If not provided, uses default app directory
|
|
295
|
+
/** Optional filename for the recording (uses UUID if not provided) */
|
|
200
296
|
filename?: string // If not provided, uses UUID
|
|
201
297
|
}
|
|
202
298
|
|
|
203
299
|
export interface NotificationConfig {
|
|
204
|
-
|
|
300
|
+
/** Title of the notification */
|
|
205
301
|
title?: string
|
|
206
302
|
|
|
207
|
-
|
|
303
|
+
/** Main text content of the notification */
|
|
208
304
|
text?: string
|
|
209
305
|
|
|
210
|
-
|
|
306
|
+
/** Icon to be displayed in the notification (resource name or URI) */
|
|
211
307
|
icon?: string
|
|
212
308
|
|
|
213
|
-
|
|
309
|
+
/** Android-specific notification configuration */
|
|
214
310
|
android?: {
|
|
215
|
-
|
|
311
|
+
/** Unique identifier for the notification channel */
|
|
216
312
|
channelId?: string
|
|
217
313
|
|
|
218
|
-
|
|
314
|
+
/** User-visible name of the notification channel */
|
|
219
315
|
channelName?: string
|
|
220
316
|
|
|
221
|
-
|
|
317
|
+
/** User-visible description of the notification channel */
|
|
222
318
|
channelDescription?: string
|
|
223
319
|
|
|
224
|
-
|
|
320
|
+
/** Unique identifier for this notification */
|
|
225
321
|
notificationId?: number
|
|
226
322
|
|
|
227
|
-
|
|
323
|
+
/** List of actions that can be performed from the notification */
|
|
228
324
|
actions?: NotificationAction[]
|
|
229
325
|
|
|
230
|
-
|
|
326
|
+
/** Configuration for the waveform visualization in the notification */
|
|
231
327
|
waveform?: WaveformConfig
|
|
232
328
|
|
|
233
|
-
|
|
329
|
+
/** Color of the notification LED (if device supports it) */
|
|
234
330
|
lightColor?: string
|
|
235
331
|
|
|
236
|
-
|
|
332
|
+
/** Priority of the notification (affects how it's displayed) */
|
|
237
333
|
priority?: 'min' | 'low' | 'default' | 'high' | 'max'
|
|
238
334
|
|
|
239
|
-
|
|
335
|
+
/** Accent color for the notification (used for the app icon and buttons) */
|
|
240
336
|
accentColor?: string
|
|
241
337
|
}
|
|
242
338
|
|
|
243
|
-
|
|
339
|
+
/** iOS-specific notification configuration */
|
|
244
340
|
ios?: {
|
|
245
|
-
|
|
341
|
+
/** Identifier for the notification category (used for grouping similar notifications) */
|
|
246
342
|
categoryIdentifier?: string
|
|
247
343
|
}
|
|
248
344
|
}
|
|
249
345
|
|
|
250
346
|
export interface NotificationAction {
|
|
251
|
-
|
|
347
|
+
/** Display title for the action */
|
|
252
348
|
title: string
|
|
253
349
|
|
|
254
|
-
|
|
350
|
+
/** Unique identifier for the action */
|
|
255
351
|
identifier: string
|
|
256
352
|
|
|
257
|
-
|
|
353
|
+
/** Icon to be displayed for the action (Android only) */
|
|
258
354
|
icon?: string
|
|
259
355
|
}
|
|
260
356
|
|
|
261
357
|
export interface WaveformConfig {
|
|
358
|
+
/** The color of the waveform (e.g., "#FFFFFF" for white) */
|
|
262
359
|
color?: string // The color of the waveform (e.g., "#FFFFFF" for white)
|
|
360
|
+
/** Opacity of the waveform (0.0 - 1.0) */
|
|
263
361
|
opacity?: number // Opacity of the waveform (0.0 - 1.0)
|
|
362
|
+
/** Width of the waveform line (default: 1.5) */
|
|
264
363
|
strokeWidth?: number // Width of the waveform line (default: 1.5)
|
|
364
|
+
/** Drawing style: "stroke" for outline, "fill" for solid */
|
|
265
365
|
style?: 'stroke' | 'fill' // Drawing style: "stroke" for outline, "fill" for solid
|
|
366
|
+
/** Whether to mirror the waveform (symmetrical display) */
|
|
266
367
|
mirror?: boolean // Whether to mirror the waveform (symmetrical display)
|
|
368
|
+
/** Height of the waveform view in dp (default: 64) */
|
|
267
369
|
height?: number // Height of the waveform view in dp (default: 64)
|
|
268
370
|
}
|
|
269
371
|
|
|
270
372
|
export interface ExtractAudioDataOptions {
|
|
373
|
+
/** URI of the audio file to extract data from */
|
|
271
374
|
fileUri: string
|
|
272
|
-
|
|
375
|
+
/** Start time in milliseconds (for time-based range) */
|
|
273
376
|
startTimeMs?: number
|
|
377
|
+
/** End time in milliseconds (for time-based range) */
|
|
274
378
|
endTimeMs?: number
|
|
275
|
-
|
|
379
|
+
/** Start position in bytes (for byte-based range) */
|
|
276
380
|
position?: number
|
|
381
|
+
/** Length in bytes to extract (for byte-based range) */
|
|
277
382
|
length?: number
|
|
278
383
|
/** Include normalized audio data in [-1, 1] range */
|
|
279
384
|
includeNormalizedData?: boolean
|
|
@@ -283,7 +388,7 @@ export interface ExtractAudioDataOptions {
|
|
|
283
388
|
includeWavHeader?: boolean
|
|
284
389
|
/** Logger for debugging - can pass console directly. */
|
|
285
390
|
logger?: ConsoleLike
|
|
286
|
-
/** Compute the checksum of the
|
|
391
|
+
/** Compute the checksum of the PCM data */
|
|
287
392
|
computeChecksum?: boolean
|
|
288
393
|
/** Target config for the normalized audio (Android and Web) */
|
|
289
394
|
decodingOptions?: DecodingConfig
|
|
@@ -310,20 +415,227 @@ export interface ExtractedAudioData {
|
|
|
310
415
|
samples: number
|
|
311
416
|
/** Whether the pcmData includes a WAV header */
|
|
312
417
|
hasWavHeader?: boolean
|
|
313
|
-
/** CRC32 Checksum of
|
|
418
|
+
/** CRC32 Checksum of PCM data */
|
|
314
419
|
checksum?: number
|
|
315
420
|
}
|
|
316
421
|
|
|
317
422
|
export interface UseAudioRecorderState {
|
|
423
|
+
/** Starts recording with the specified configuration */
|
|
318
424
|
startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>
|
|
425
|
+
/** Stops the current recording and returns the recording data */
|
|
319
426
|
stopRecording: () => Promise<AudioRecording | null>
|
|
427
|
+
/** Pauses the current recording */
|
|
320
428
|
pauseRecording: () => Promise<void>
|
|
429
|
+
/** Resumes a paused recording */
|
|
321
430
|
resumeRecording: () => Promise<void>
|
|
431
|
+
/** Indicates whether recording is currently active */
|
|
322
432
|
isRecording: boolean
|
|
433
|
+
/** Indicates whether recording is in a paused state */
|
|
323
434
|
isPaused: boolean
|
|
435
|
+
/** Duration of the current recording in milliseconds */
|
|
324
436
|
durationMs: number // Duration of the recording
|
|
437
|
+
/** Size of the recorded audio in bytes */
|
|
325
438
|
size: number // Size in bytes of the recorded audio
|
|
439
|
+
/** Information about compression if enabled */
|
|
326
440
|
compression?: CompressionInfo
|
|
441
|
+
/** Analysis data for the recording if processing was enabled */
|
|
327
442
|
analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag
|
|
443
|
+
/** Optional callback to handle recording interruptions */
|
|
328
444
|
onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void
|
|
329
445
|
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Represents an event emitted during the trimming process to report progress.
|
|
449
|
+
*/
|
|
450
|
+
export interface TrimProgressEvent {
|
|
451
|
+
/**
|
|
452
|
+
* The percentage of the trimming process that has been completed, ranging from 0 to 100.
|
|
453
|
+
*/
|
|
454
|
+
progress: number
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* The number of bytes that have been processed so far. This is optional and may not be provided in all implementations.
|
|
458
|
+
*/
|
|
459
|
+
bytesProcessed?: number
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The total number of bytes to process. This is optional and may not be provided in all implementations.
|
|
463
|
+
*/
|
|
464
|
+
totalBytes?: number
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Defines a time range in milliseconds for trimming operations.
|
|
469
|
+
*/
|
|
470
|
+
export interface TimeRange {
|
|
471
|
+
/**
|
|
472
|
+
* The start time of the range in milliseconds.
|
|
473
|
+
*/
|
|
474
|
+
startTimeMs: number
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* The end time of the range in milliseconds.
|
|
478
|
+
*/
|
|
479
|
+
endTimeMs: number
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Options for configuring the audio trimming operation.
|
|
484
|
+
*/
|
|
485
|
+
export interface TrimAudioOptions {
|
|
486
|
+
/**
|
|
487
|
+
* The URI of the audio file to trim.
|
|
488
|
+
*/
|
|
489
|
+
fileUri: string
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* The mode of trimming to apply.
|
|
493
|
+
* - `'single'`: Trims the audio to a single range defined by `startTimeMs` and `endTimeMs`.
|
|
494
|
+
* - `'keep'`: Keeps the specified `ranges` and removes all other portions of the audio.
|
|
495
|
+
* - `'remove'`: Removes the specified `ranges` and keeps the remaining portions of the audio.
|
|
496
|
+
* @default 'single'
|
|
497
|
+
*/
|
|
498
|
+
mode?: 'single' | 'keep' | 'remove'
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* An array of time ranges to keep or remove, depending on the `mode`.
|
|
502
|
+
* - Required for `'keep'` and `'remove'` modes.
|
|
503
|
+
* - Ignored when `mode` is `'single'`.
|
|
504
|
+
*/
|
|
505
|
+
ranges?: TimeRange[]
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* The start time in milliseconds for the `'single'` mode.
|
|
509
|
+
* - If not provided, trimming starts from the beginning of the audio (0 ms).
|
|
510
|
+
*/
|
|
511
|
+
startTimeMs?: number
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* The end time in milliseconds for the `'single'` mode.
|
|
515
|
+
* - If not provided, trimming extends to the end of the audio.
|
|
516
|
+
*/
|
|
517
|
+
endTimeMs?: number
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* The name of the output file. If not provided, a default name will be generated.
|
|
521
|
+
*/
|
|
522
|
+
outputFileName?: string
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Configuration for the output audio format.
|
|
526
|
+
*/
|
|
527
|
+
outputFormat?: {
|
|
528
|
+
/**
|
|
529
|
+
* The format of the output audio file.
|
|
530
|
+
* - `'wav'`: Waveform Audio File Format (uncompressed).
|
|
531
|
+
* - `'aac'`: Advanced Audio Coding (compressed). Not supported on web platforms.
|
|
532
|
+
* - `'opus'`: Opus Interactive Audio Codec (compressed).
|
|
533
|
+
*/
|
|
534
|
+
format: 'wav' | 'aac' | 'opus'
|
|
535
|
+
|
|
536
|
+
/**
|
|
537
|
+
* The sample rate of the output audio in Hertz (Hz).
|
|
538
|
+
* - If not provided, the input audio's sample rate is used.
|
|
539
|
+
*/
|
|
540
|
+
sampleRate?: number
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* The number of channels in the output audio (e.g., 1 for mono, 2 for stereo).
|
|
544
|
+
* - If not provided, the input audio's channel count is used.
|
|
545
|
+
*/
|
|
546
|
+
channels?: number
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* The bit depth of the output audio, applicable to PCM formats like `'wav'`.
|
|
550
|
+
* - If not provided, the input audio's bit depth is used.
|
|
551
|
+
*/
|
|
552
|
+
bitDepth?: number
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* The bitrate of the output audio in bits per second, applicable to compressed formats like `'aac'`.
|
|
556
|
+
* - If not provided, a default bitrate is used based on the format.
|
|
557
|
+
*/
|
|
558
|
+
bitrate?: number
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Options for decoding the input audio file.
|
|
563
|
+
* - See `DecodingConfig` for details.
|
|
564
|
+
*/
|
|
565
|
+
decodingOptions?: DecodingConfig
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Result of the audio trimming operation.
|
|
570
|
+
*/
|
|
571
|
+
export interface TrimAudioResult {
|
|
572
|
+
/**
|
|
573
|
+
* The URI of the trimmed audio file.
|
|
574
|
+
*/
|
|
575
|
+
uri: string
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* The filename of the trimmed audio file.
|
|
579
|
+
*/
|
|
580
|
+
filename: string
|
|
581
|
+
|
|
582
|
+
/**
|
|
583
|
+
* The duration of the trimmed audio in milliseconds.
|
|
584
|
+
*/
|
|
585
|
+
durationMs: number
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* The size of the trimmed audio file in bytes.
|
|
589
|
+
*/
|
|
590
|
+
size: number
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* The sample rate of the trimmed audio in Hertz (Hz).
|
|
594
|
+
*/
|
|
595
|
+
sampleRate: number
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* The number of channels in the trimmed audio (e.g., 1 for mono, 2 for stereo).
|
|
599
|
+
*/
|
|
600
|
+
channels: number
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* The bit depth of the trimmed audio, applicable to PCM formats like `'wav'`.
|
|
604
|
+
*/
|
|
605
|
+
bitDepth: number
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* The MIME type of the trimmed audio file (e.g., `'audio/wav'`, `'audio/mpeg'`).
|
|
609
|
+
*/
|
|
610
|
+
mimeType: string
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Information about compression if the output format is compressed.
|
|
614
|
+
*/
|
|
615
|
+
compression?: {
|
|
616
|
+
/**
|
|
617
|
+
* The format of the compression (e.g., `'aac'`, `'mp3'`, `'opus'`).
|
|
618
|
+
*/
|
|
619
|
+
format: string
|
|
620
|
+
|
|
621
|
+
/**
|
|
622
|
+
* The bitrate of the compressed audio in bits per second.
|
|
623
|
+
*/
|
|
624
|
+
bitrate: number
|
|
625
|
+
|
|
626
|
+
/**
|
|
627
|
+
* The size of the compressed audio file in bytes.
|
|
628
|
+
*/
|
|
629
|
+
size: number
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/**
|
|
633
|
+
* Information about the processing time.
|
|
634
|
+
*/
|
|
635
|
+
processingInfo?: {
|
|
636
|
+
/**
|
|
637
|
+
* The time it took to process the audio in milliseconds.
|
|
638
|
+
*/
|
|
639
|
+
durationMs: number
|
|
640
|
+
}
|
|
641
|
+
}
|