react-native-audio-api 0.11.0-nightly-95f9c99-20251215 → 0.11.0-nightly-dd83923-20251216
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/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +382 -39
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +45 -18
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +33 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +170 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +46 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +0 -1
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.cpp +83 -0
- package/android/src/main/cpp/audioapi/android/core/utils/FileOptions.h +22 -0
- package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +8 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +493 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +70 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/ptrs.hpp +56 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.cpp +114 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/utils.h +34 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +296 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +40 -0
- package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +32 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +2 -0
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +7 -3
- package/android/src/main/java/com/swmansion/audioapi/system/CentralizedForegroundService.kt +1 -0
- package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +18 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/PlaybackNotification.kt +1 -0
- package/android/src/main/java/com/swmansion/audioapi/system/notification/RecordingNotificationReceiver.kt +2 -0
- package/android/src/oldarch/NativeAudioAPIModuleSpec.java +100 -80
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +3 -11
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +145 -16
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +21 -6
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +43 -60
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +53 -33
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.cpp +42 -14
- package/common/cpp/audioapi/core/sources/RecorderAdapterNode.h +12 -9
- package/common/cpp/audioapi/core/utils/AudioFileWriter.cpp +41 -0
- package/common/cpp/audioapi/core/utils/AudioFileWriter.h +44 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.cpp +101 -0
- package/common/cpp/audioapi/core/utils/AudioRecorderCallback.h +52 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.cpp +92 -0
- package/common/cpp/audioapi/utils/AudioFileProperties.h +76 -0
- package/common/cpp/audioapi/utils/Result.hpp +323 -0
- package/common/cpp/audioapi/utils/UnitConversion.h +9 -0
- package/ios/audioapi/ios/AudioAPIModule.mm +9 -14
- package/ios/audioapi/ios/core/IOSAudioPlayer.h +1 -1
- package/ios/audioapi/ios/core/IOSAudioPlayer.mm +7 -6
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +39 -13
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +302 -26
- package/ios/audioapi/ios/core/NativeAudioPlayer.m +7 -11
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +8 -9
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +70 -76
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +1 -0
- package/ios/audioapi/ios/core/utils/FileOptions.h +33 -0
- package/ios/audioapi/ios/core/utils/FileOptions.mm +195 -0
- package/ios/audioapi/ios/core/utils/IOSFileWriter.h +53 -0
- package/ios/audioapi/ios/core/utils/IOSFileWriter.mm +239 -0
- package/ios/audioapi/ios/core/utils/IOSRecorderCallback.h +47 -0
- package/ios/audioapi/ios/core/utils/IOSRecorderCallback.mm +185 -0
- package/ios/audioapi/ios/system/AudioEngine.h +21 -16
- package/ios/audioapi/ios/system/AudioEngine.mm +138 -130
- package/ios/audioapi/ios/system/AudioSessionManager.h +19 -9
- package/ios/audioapi/ios/system/AudioSessionManager.mm +250 -215
- package/ios/audioapi/ios/system/NotificationManager.mm +24 -42
- package/lib/commonjs/api.js +82 -109
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +159 -13
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js +17 -14
- package/lib/commonjs/system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/commonjs/system/notification/RecordingNotificationManager.js +22 -19
- package/lib/commonjs/system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/commonjs/system/notification/SimpleNotificationManager.js +16 -13
- package/lib/commonjs/system/notification/SimpleNotificationManager.js.map +1 -1
- package/lib/commonjs/types.js +39 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/filePresets.js +43 -0
- package/lib/commonjs/utils/filePresets.js.map +1 -0
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js +6 -3
- package/lib/commonjs/web-system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js +6 -3
- package/lib/commonjs/web-system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/module/api.js +5 -4
- package/lib/module/api.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +159 -13
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/specs/NativeAudioAPIModule.js.map +1 -1
- package/lib/module/system/notification/PlaybackNotificationManager.js +17 -14
- package/lib/module/system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/module/system/notification/RecordingNotificationManager.js +22 -19
- package/lib/module/system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/module/system/notification/SimpleNotificationManager.js +16 -13
- package/lib/module/system/notification/SimpleNotificationManager.js.map +1 -1
- package/lib/module/types.js +38 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/filePresets.js +39 -0
- package/lib/module/utils/filePresets.js.map +1 -0
- package/lib/module/web-system/notification/PlaybackNotificationManager.js +6 -3
- package/lib/module/web-system/notification/PlaybackNotificationManager.js.map +1 -1
- package/lib/module/web-system/notification/RecordingNotificationManager.js +6 -3
- package/lib/module/web-system/notification/RecordingNotificationManager.js.map +1 -1
- package/lib/typescript/api.d.ts +5 -4
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +69 -7
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +36 -2
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +24 -4
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts +1 -1
- package/lib/typescript/specs/NativeAudioAPIModule.d.ts.map +1 -1
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts +4 -3
- package/lib/typescript/system/notification/PlaybackNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts +4 -3
- package/lib/typescript/system/notification/RecordingNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts +3 -2
- package/lib/typescript/system/notification/SimpleNotificationManager.d.ts.map +1 -1
- package/lib/typescript/system/notification/types.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +79 -3
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/filePresets.d.ts +9 -0
- package/lib/typescript/utils/filePresets.d.ts.map +1 -0
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts +4 -3
- package/lib/typescript/web-system/notification/PlaybackNotificationManager.d.ts.map +1 -1
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts +4 -3
- package/lib/typescript/web-system/notification/RecordingNotificationManager.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/AudioAPIModule/globals.d.ts +1 -2
- package/src/api.ts +8 -29
- package/src/core/AudioRecorder.ts +195 -23
- package/src/events/types.ts +40 -2
- package/src/interfaces.ts +34 -5
- package/src/specs/NativeAudioAPIModule.ts +2 -2
- package/src/system/notification/PlaybackNotificationManager.ts +20 -16
- package/src/system/notification/RecordingNotificationManager.ts +26 -21
- package/src/system/notification/SimpleNotificationManager.ts +18 -13
- package/src/system/notification/types.ts +1 -0
- package/src/types.ts +89 -3
- package/src/utils/filePresets.ts +47 -0
- package/src/web-system/notification/PlaybackNotificationManager.ts +9 -5
- package/src/web-system/notification/RecordingNotificationManager.ts +9 -5
package/src/interfaces.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { AudioEventCallback, AudioEventName } from './events/types';
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
|
+
AudioRecorderCallbackOptions,
|
|
4
|
+
AudioRecorderFileOptions,
|
|
3
5
|
BiquadFilterType,
|
|
4
6
|
ChannelCountMode,
|
|
5
7
|
ChannelInterpretation,
|
|
6
8
|
ContextState,
|
|
9
|
+
FileInfo,
|
|
7
10
|
OscillatorType,
|
|
11
|
+
Result,
|
|
8
12
|
WindowType,
|
|
9
13
|
} from './types';
|
|
10
14
|
|
|
@@ -285,14 +289,39 @@ export interface IWorkletSourceNode extends IAudioScheduledSourceNode {}
|
|
|
285
289
|
|
|
286
290
|
export interface IWorkletProcessingNode extends IAudioNode {}
|
|
287
291
|
|
|
292
|
+
export interface IAudioRecorderCallbackOptions
|
|
293
|
+
extends AudioRecorderCallbackOptions {
|
|
294
|
+
callbackId: string;
|
|
295
|
+
}
|
|
296
|
+
|
|
288
297
|
export interface IAudioRecorder {
|
|
289
|
-
|
|
290
|
-
|
|
298
|
+
// default recorder methods
|
|
299
|
+
start: () => Result<{ path: string }>;
|
|
300
|
+
stop: () => Result<FileInfo>;
|
|
301
|
+
isRecording: () => boolean;
|
|
302
|
+
isPaused: () => boolean;
|
|
303
|
+
|
|
304
|
+
enableFileOutput: (
|
|
305
|
+
options: AudioRecorderFileOptions
|
|
306
|
+
) => Result<{ path: string }>;
|
|
307
|
+
disableFileOutput: () => void;
|
|
308
|
+
|
|
309
|
+
// pause and resume methods for file recording
|
|
310
|
+
pause: () => void;
|
|
311
|
+
resume: () => void;
|
|
312
|
+
|
|
313
|
+
// Graph integration methods
|
|
291
314
|
connect: (node: IRecorderAdapterNode) => void;
|
|
292
315
|
disconnect: () => void;
|
|
293
316
|
|
|
294
|
-
|
|
295
|
-
|
|
317
|
+
setOnAudioReady: (options: IAudioRecorderCallbackOptions) => Result<void>;
|
|
318
|
+
clearOnAudioReady: () => void;
|
|
319
|
+
|
|
320
|
+
setOnError: (options: { callbackId: string }) => void;
|
|
321
|
+
clearOnError: () => void;
|
|
322
|
+
|
|
323
|
+
getCurrentDuration: () => number;
|
|
324
|
+
getFilePath: () => string | null;
|
|
296
325
|
}
|
|
297
326
|
|
|
298
327
|
export interface IAudioDecoder {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
import { TurboModuleRegistry } from 'react-native';
|
|
3
2
|
import type { TurboModule } from 'react-native';
|
|
4
|
-
import {
|
|
3
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
+
import { AudioDevicesInfo, PermissionStatus } from '../system/types';
|
|
5
5
|
|
|
6
6
|
type OptionsMap = { [key: string]: string | boolean | number | undefined };
|
|
7
7
|
type NotificationOpResponse = { success: boolean; error?: string };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { NativeAudioAPIModule } from '../../specs';
|
|
2
1
|
import { AudioEventEmitter, AudioEventSubscription } from '../../events';
|
|
2
|
+
import { NativeAudioAPIModule } from '../../specs';
|
|
3
3
|
import type {
|
|
4
|
+
NotificationEvents,
|
|
4
5
|
NotificationManager,
|
|
5
|
-
PlaybackNotificationInfo,
|
|
6
6
|
PlaybackControlName,
|
|
7
7
|
PlaybackNotificationEventName,
|
|
8
|
-
|
|
8
|
+
PlaybackNotificationInfo,
|
|
9
9
|
} from './types';
|
|
10
10
|
|
|
11
11
|
/// Manager for media playback notifications with controls and MediaSession integration.
|
|
@@ -18,8 +18,8 @@ class PlaybackNotificationManager
|
|
|
18
18
|
>
|
|
19
19
|
{
|
|
20
20
|
private notificationKey = 'playback';
|
|
21
|
-
private
|
|
22
|
-
private
|
|
21
|
+
private isRegistered_ = false;
|
|
22
|
+
private isShown_ = false;
|
|
23
23
|
private audioEventEmitter: AudioEventEmitter;
|
|
24
24
|
|
|
25
25
|
constructor() {
|
|
@@ -28,7 +28,7 @@ class PlaybackNotificationManager
|
|
|
28
28
|
|
|
29
29
|
/// Register the playback notification (must be called before showing).
|
|
30
30
|
async register(): Promise<void> {
|
|
31
|
-
if (this.
|
|
31
|
+
if (this.isRegistered_) {
|
|
32
32
|
console.warn('PlaybackNotification is already registered');
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -46,12 +46,12 @@ class PlaybackNotificationManager
|
|
|
46
46
|
throw new Error(result.error);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
this.
|
|
49
|
+
this.isRegistered_ = true;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/// Show the notification with initial metadata.
|
|
53
53
|
async show(info: PlaybackNotificationInfo): Promise<void> {
|
|
54
|
-
if (!this.
|
|
54
|
+
if (!this.isRegistered_) {
|
|
55
55
|
throw new Error(
|
|
56
56
|
'PlaybackNotification must be registered before showing. Call register() first.'
|
|
57
57
|
);
|
|
@@ -70,12 +70,12 @@ class PlaybackNotificationManager
|
|
|
70
70
|
throw new Error(result.error);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
this.
|
|
73
|
+
this.isShown_ = true;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
/// Update the notification with new metadata or state.
|
|
77
77
|
async update(info: PlaybackNotificationInfo): Promise<void> {
|
|
78
|
-
if (!this.
|
|
78
|
+
if (!this.isShown_) {
|
|
79
79
|
console.warn('PlaybackNotification is not shown. Call show() first.');
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
@@ -96,7 +96,7 @@ class PlaybackNotificationManager
|
|
|
96
96
|
|
|
97
97
|
/// Hide the notification (can be shown again later).
|
|
98
98
|
async hide(): Promise<void> {
|
|
99
|
-
if (!this.
|
|
99
|
+
if (!this.isShown_) {
|
|
100
100
|
return;
|
|
101
101
|
}
|
|
102
102
|
|
|
@@ -112,16 +112,16 @@ class PlaybackNotificationManager
|
|
|
112
112
|
throw new Error(result.error);
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
this.
|
|
115
|
+
this.isShown_ = false;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
/// Unregister the notification (must register again to use).
|
|
119
119
|
async unregister(): Promise<void> {
|
|
120
|
-
if (!this.
|
|
120
|
+
if (!this.isRegistered_) {
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
if (this.
|
|
124
|
+
if (this.isShown_) {
|
|
125
125
|
await this.hide();
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -137,7 +137,7 @@ class PlaybackNotificationManager
|
|
|
137
137
|
throw new Error(result.error);
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
this.
|
|
140
|
+
this.isRegistered_ = false;
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
/// Enable or disable a specific playback control.
|
|
@@ -145,7 +145,7 @@ class PlaybackNotificationManager
|
|
|
145
145
|
control: PlaybackControlName,
|
|
146
146
|
enabled: boolean
|
|
147
147
|
): Promise<void> {
|
|
148
|
-
if (!this.
|
|
148
|
+
if (!this.isRegistered_) {
|
|
149
149
|
console.warn('PlaybackNotification is not registered');
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
@@ -176,6 +176,10 @@ class PlaybackNotificationManager
|
|
|
176
176
|
);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
isRegistered(): boolean {
|
|
180
|
+
return this.isRegistered_;
|
|
181
|
+
}
|
|
182
|
+
|
|
179
183
|
/// Add an event listener for notification actions.
|
|
180
184
|
addEventListener<T extends PlaybackNotificationEventName>(
|
|
181
185
|
eventName: T,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Platform } from 'react-native';
|
|
2
|
-
import { NativeAudioAPIModule } from '../../specs';
|
|
3
2
|
import { AudioEventEmitter, AudioEventSubscription } from '../../events';
|
|
3
|
+
import { NativeAudioAPIModule } from '../../specs';
|
|
4
4
|
import type {
|
|
5
|
+
NotificationEvents,
|
|
5
6
|
NotificationManager,
|
|
6
|
-
RecordingNotificationInfo,
|
|
7
7
|
RecordingControlName,
|
|
8
8
|
RecordingNotificationEventName,
|
|
9
|
-
|
|
9
|
+
RecordingNotificationInfo,
|
|
10
10
|
} from './types';
|
|
11
11
|
|
|
12
12
|
/// Manager for recording notifications with controls.
|
|
@@ -18,9 +18,10 @@ class RecordingNotificationManager
|
|
|
18
18
|
RecordingNotificationEventName
|
|
19
19
|
>
|
|
20
20
|
{
|
|
21
|
+
private isRegistered_ = false;
|
|
22
|
+
private isShown_ = false;
|
|
23
|
+
|
|
21
24
|
private notificationKey = 'recording';
|
|
22
|
-
private isRegistered = false;
|
|
23
|
-
private isShown = false;
|
|
24
25
|
private audioEventEmitter: AudioEventEmitter;
|
|
25
26
|
private isIOS = Platform.OS === 'ios';
|
|
26
27
|
|
|
@@ -30,14 +31,14 @@ class RecordingNotificationManager
|
|
|
30
31
|
|
|
31
32
|
/// Register the recording notification (must be called before showing).
|
|
32
33
|
async register(): Promise<void> {
|
|
33
|
-
if (this.
|
|
34
|
+
if (this.isRegistered_) {
|
|
34
35
|
console.warn('RecordingNotification is already registered');
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
39
|
// Recording notifications are only supported on Android
|
|
39
40
|
if (this.isIOS) {
|
|
40
|
-
this.
|
|
41
|
+
this.isRegistered_ = true;
|
|
41
42
|
return;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -54,12 +55,12 @@ class RecordingNotificationManager
|
|
|
54
55
|
throw new Error(result.error);
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
this.
|
|
58
|
+
this.isRegistered_ = true;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/// Show the notification with initial metadata.
|
|
61
62
|
async show(info: RecordingNotificationInfo): Promise<void> {
|
|
62
|
-
if (!this.
|
|
63
|
+
if (!this.isRegistered_) {
|
|
63
64
|
throw new Error(
|
|
64
65
|
'RecordingNotification must be registered before showing. Call register() first.'
|
|
65
66
|
);
|
|
@@ -67,7 +68,7 @@ class RecordingNotificationManager
|
|
|
67
68
|
|
|
68
69
|
// Recording notifications are only supported on Android
|
|
69
70
|
if (this.isIOS) {
|
|
70
|
-
this.
|
|
71
|
+
this.isShown_ = true;
|
|
71
72
|
return;
|
|
72
73
|
}
|
|
73
74
|
|
|
@@ -84,12 +85,12 @@ class RecordingNotificationManager
|
|
|
84
85
|
throw new Error(result.error);
|
|
85
86
|
}
|
|
86
87
|
|
|
87
|
-
this.
|
|
88
|
+
this.isShown_ = true;
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
/// Update the notification with new metadata or state.
|
|
91
92
|
async update(info: RecordingNotificationInfo): Promise<void> {
|
|
92
|
-
if (!this.
|
|
93
|
+
if (!this.isShown_) {
|
|
93
94
|
console.warn('RecordingNotification is not shown. Call show() first.');
|
|
94
95
|
return;
|
|
95
96
|
}
|
|
@@ -115,13 +116,13 @@ class RecordingNotificationManager
|
|
|
115
116
|
|
|
116
117
|
/// Hide the notification (can be shown again later).
|
|
117
118
|
async hide(): Promise<void> {
|
|
118
|
-
if (!this.
|
|
119
|
+
if (!this.isShown_) {
|
|
119
120
|
return;
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
// Recording notifications are only supported on Android
|
|
123
124
|
if (this.isIOS) {
|
|
124
|
-
this.
|
|
125
|
+
this.isShown_ = false;
|
|
125
126
|
return;
|
|
126
127
|
}
|
|
127
128
|
|
|
@@ -137,22 +138,22 @@ class RecordingNotificationManager
|
|
|
137
138
|
throw new Error(result.error);
|
|
138
139
|
}
|
|
139
140
|
|
|
140
|
-
this.
|
|
141
|
+
this.isShown_ = false;
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
/// Unregister the notification (must register again to use).
|
|
144
145
|
async unregister(): Promise<void> {
|
|
145
|
-
if (!this.
|
|
146
|
+
if (!this.isRegistered_) {
|
|
146
147
|
return;
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
if (this.
|
|
150
|
+
if (this.isShown_) {
|
|
150
151
|
await this.hide();
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
// Recording notifications are only supported on Android
|
|
154
155
|
if (this.isIOS) {
|
|
155
|
-
this.
|
|
156
|
+
this.isRegistered_ = false;
|
|
156
157
|
return;
|
|
157
158
|
}
|
|
158
159
|
|
|
@@ -168,7 +169,7 @@ class RecordingNotificationManager
|
|
|
168
169
|
throw new Error(result.error);
|
|
169
170
|
}
|
|
170
171
|
|
|
171
|
-
this.
|
|
172
|
+
this.isRegistered_ = false;
|
|
172
173
|
}
|
|
173
174
|
|
|
174
175
|
/// Enable or disable a specific recording control.
|
|
@@ -176,7 +177,7 @@ class RecordingNotificationManager
|
|
|
176
177
|
control: RecordingControlName,
|
|
177
178
|
enabled: boolean
|
|
178
179
|
): Promise<void> {
|
|
179
|
-
if (!this.
|
|
180
|
+
if (!this.isRegistered_) {
|
|
180
181
|
console.warn('RecordingNotification is not registered');
|
|
181
182
|
return;
|
|
182
183
|
}
|
|
@@ -205,7 +206,7 @@ class RecordingNotificationManager
|
|
|
205
206
|
async isActive(): Promise<boolean> {
|
|
206
207
|
// Recording notifications are only supported on Android
|
|
207
208
|
if (this.isIOS) {
|
|
208
|
-
return this.
|
|
209
|
+
return this.isShown_;
|
|
209
210
|
}
|
|
210
211
|
|
|
211
212
|
if (!NativeAudioAPIModule) {
|
|
@@ -217,6 +218,10 @@ class RecordingNotificationManager
|
|
|
217
218
|
);
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
isRegistered(): boolean {
|
|
222
|
+
return this.isRegistered_;
|
|
223
|
+
}
|
|
224
|
+
|
|
220
225
|
/// Add an event listener for notification actions.
|
|
221
226
|
addEventListener<T extends RecordingNotificationEventName>(
|
|
222
227
|
eventName: T,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NativeAudioAPIModule } from '../../specs';
|
|
2
1
|
import { AudioEventEmitter, AudioEventSubscription } from '../../events';
|
|
2
|
+
import { NativeAudioAPIModule } from '../../specs';
|
|
3
3
|
import type { NotificationManager, SimpleNotificationOptions } from './types';
|
|
4
4
|
|
|
5
5
|
/// Simple notification manager for basic notifications with title and text.
|
|
@@ -13,9 +13,10 @@ class SimpleNotificationManager
|
|
|
13
13
|
never
|
|
14
14
|
>
|
|
15
15
|
{
|
|
16
|
+
private isRegistered_ = false;
|
|
17
|
+
private isShown_ = false;
|
|
18
|
+
|
|
16
19
|
private notificationKey = 'simple';
|
|
17
|
-
private isRegistered = false;
|
|
18
|
-
private isShown = false;
|
|
19
20
|
private audioEventEmitter: AudioEventEmitter;
|
|
20
21
|
|
|
21
22
|
constructor() {
|
|
@@ -24,7 +25,7 @@ class SimpleNotificationManager
|
|
|
24
25
|
|
|
25
26
|
/// Register the simple notification (must be called before showing).
|
|
26
27
|
async register(): Promise<void> {
|
|
27
|
-
if (this.
|
|
28
|
+
if (this.isRegistered_) {
|
|
28
29
|
console.warn('SimpleNotification is already registered');
|
|
29
30
|
return;
|
|
30
31
|
}
|
|
@@ -42,12 +43,12 @@ class SimpleNotificationManager
|
|
|
42
43
|
throw new Error(result.error);
|
|
43
44
|
}
|
|
44
45
|
|
|
45
|
-
this.
|
|
46
|
+
this.isRegistered_ = true;
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
/// Show the notification with initial options.
|
|
49
50
|
async show(options: SimpleNotificationOptions): Promise<void> {
|
|
50
|
-
if (!this.
|
|
51
|
+
if (!this.isRegistered_) {
|
|
51
52
|
throw new Error(
|
|
52
53
|
'SimpleNotification must be registered before showing. Call register() first.'
|
|
53
54
|
);
|
|
@@ -66,12 +67,12 @@ class SimpleNotificationManager
|
|
|
66
67
|
throw new Error(result.error);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
this.
|
|
70
|
+
this.isShown_ = true;
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
/// Update the notification with new options.
|
|
73
74
|
async update(options: SimpleNotificationOptions): Promise<void> {
|
|
74
|
-
if (!this.
|
|
75
|
+
if (!this.isShown_) {
|
|
75
76
|
console.warn('SimpleNotification is not shown. Call show() first.');
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
@@ -92,7 +93,7 @@ class SimpleNotificationManager
|
|
|
92
93
|
|
|
93
94
|
/// Hide the notification (can be shown again later).
|
|
94
95
|
async hide(): Promise<void> {
|
|
95
|
-
if (!this.
|
|
96
|
+
if (!this.isShown_) {
|
|
96
97
|
return;
|
|
97
98
|
}
|
|
98
99
|
|
|
@@ -108,16 +109,16 @@ class SimpleNotificationManager
|
|
|
108
109
|
throw new Error(result.error);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
this.
|
|
112
|
+
this.isShown_ = false;
|
|
112
113
|
}
|
|
113
114
|
|
|
114
115
|
/// Unregister the notification (must register again to use).
|
|
115
116
|
async unregister(): Promise<void> {
|
|
116
|
-
if (!this.
|
|
117
|
+
if (!this.isRegistered_) {
|
|
117
118
|
return;
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
if (this.
|
|
121
|
+
if (this.isShown_) {
|
|
121
122
|
await this.hide();
|
|
122
123
|
}
|
|
123
124
|
|
|
@@ -133,7 +134,7 @@ class SimpleNotificationManager
|
|
|
133
134
|
throw new Error(result.error);
|
|
134
135
|
}
|
|
135
136
|
|
|
136
|
-
this.
|
|
137
|
+
this.isRegistered_ = false;
|
|
137
138
|
}
|
|
138
139
|
|
|
139
140
|
/// Check if the notification is currently active.
|
|
@@ -147,6 +148,10 @@ class SimpleNotificationManager
|
|
|
147
148
|
);
|
|
148
149
|
}
|
|
149
150
|
|
|
151
|
+
isRegistered(): boolean {
|
|
152
|
+
return this.isRegistered_;
|
|
153
|
+
}
|
|
154
|
+
|
|
150
155
|
/// Add an event listener (SimpleNotification doesn't emit events).
|
|
151
156
|
addEventListener<T extends never>(
|
|
152
157
|
_eventName: T,
|
|
@@ -97,6 +97,7 @@ export type RecordingNotificationEventName = keyof RecordingNotificationEvent;
|
|
|
97
97
|
|
|
98
98
|
export type NotificationEvents = PlaybackNotificationEvent &
|
|
99
99
|
RecordingNotificationEvent;
|
|
100
|
+
|
|
100
101
|
export type NotificationEventName = keyof NotificationEvents;
|
|
101
102
|
|
|
102
103
|
export type NotificationCallback<Name extends NotificationEventName> = (
|
package/src/types.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import AudioBuffer from './core/AudioBuffer';
|
|
2
2
|
|
|
3
|
+
export type Result<T> =
|
|
4
|
+
| ({ status: 'success' } & T)
|
|
5
|
+
| { status: 'error'; message: string };
|
|
6
|
+
|
|
3
7
|
export type ChannelCountMode = 'max' | 'clamped-max' | 'explicit';
|
|
4
8
|
|
|
5
9
|
export type ChannelInterpretation = 'speakers' | 'discrete';
|
|
@@ -14,7 +18,7 @@ export type BiquadFilterType =
|
|
|
14
18
|
| 'notch'
|
|
15
19
|
| 'allpass';
|
|
16
20
|
|
|
17
|
-
export type ContextState = 'running' | 'closed' |
|
|
21
|
+
export type ContextState = 'running' | 'closed' | 'suspended';
|
|
18
22
|
|
|
19
23
|
export type AudioWorkletRuntime = 'AudioRuntime' | 'UIRuntime';
|
|
20
24
|
|
|
@@ -39,9 +43,69 @@ export interface OfflineAudioContextOptions {
|
|
|
39
43
|
sampleRate: number;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
export
|
|
46
|
+
export enum FileDirectory {
|
|
47
|
+
Document = 0,
|
|
48
|
+
Cache = 1,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export enum FileFormat {
|
|
52
|
+
Wav = 0,
|
|
53
|
+
Caf = 1,
|
|
54
|
+
M4A = 2,
|
|
55
|
+
Flac = 3,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export enum IOSAudioQuality {
|
|
59
|
+
Min = 0,
|
|
60
|
+
Low = 1,
|
|
61
|
+
Medium = 2,
|
|
62
|
+
High = 3,
|
|
63
|
+
Max = 4,
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export enum BitDepth {
|
|
67
|
+
Bit16 = 0,
|
|
68
|
+
Bit24 = 1,
|
|
69
|
+
Bit32 = 2,
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export enum FlacCompressionLevel {
|
|
73
|
+
L0 = 0,
|
|
74
|
+
L1 = 1,
|
|
75
|
+
L2 = 2,
|
|
76
|
+
L3 = 3,
|
|
77
|
+
L4 = 4,
|
|
78
|
+
L5 = 5,
|
|
79
|
+
L6 = 6,
|
|
80
|
+
L7 = 7,
|
|
81
|
+
L8 = 8,
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface FilePresetType {
|
|
85
|
+
bitRate: number;
|
|
43
86
|
sampleRate: number;
|
|
44
|
-
|
|
87
|
+
bitDepth: BitDepth;
|
|
88
|
+
iosQuality: IOSAudioQuality;
|
|
89
|
+
flacCompressionLevel: FlacCompressionLevel;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export interface AudioRecorderFileOptions {
|
|
93
|
+
channelCount?: number;
|
|
94
|
+
batchDurationSeconds?: number;
|
|
95
|
+
|
|
96
|
+
format?: FileFormat;
|
|
97
|
+
preset?: FilePresetType;
|
|
98
|
+
|
|
99
|
+
directory?: FileDirectory;
|
|
100
|
+
subDirectory?: string;
|
|
101
|
+
fileNamePrefix?: string;
|
|
102
|
+
androidFlushIntervalMs?: number;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface FileInfo {
|
|
106
|
+
path: string;
|
|
107
|
+
size: number;
|
|
108
|
+
duration: number;
|
|
45
109
|
}
|
|
46
110
|
|
|
47
111
|
export type WindowType = 'blackman' | 'hann';
|
|
@@ -57,6 +121,28 @@ export interface ConvolverNodeOptions {
|
|
|
57
121
|
disableNormalization?: boolean;
|
|
58
122
|
}
|
|
59
123
|
|
|
124
|
+
export interface AudioRecorderCallbackOptions {
|
|
125
|
+
/**
|
|
126
|
+
* The desired sample rate (in Hz) for audio buffers delivered to the
|
|
127
|
+
* recording callback. Common values include 44100 or 48000 Hz. The actual
|
|
128
|
+
* sample rate may differ depending on hardware and system capabilities.
|
|
129
|
+
*/
|
|
130
|
+
sampleRate: number;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The preferred size of each audio buffer, expressed as the number of samples
|
|
134
|
+
* per channel. Smaller buffers reduce latency but increase CPU load, while
|
|
135
|
+
* larger buffers improve efficiency at the cost of higher latency.
|
|
136
|
+
*/
|
|
137
|
+
bufferLength: number;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* The desired number of audio channels per buffer. Typically 1 for mono or 2
|
|
141
|
+
* for stereo recordings.
|
|
142
|
+
*/
|
|
143
|
+
channelCount: number;
|
|
144
|
+
}
|
|
145
|
+
|
|
60
146
|
export interface IIRFilterNodeOptions {
|
|
61
147
|
feedforward: number[];
|
|
62
148
|
feedback: number[];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BitDepth,
|
|
3
|
+
FilePresetType,
|
|
4
|
+
FlacCompressionLevel,
|
|
5
|
+
IOSAudioQuality,
|
|
6
|
+
} from '../types';
|
|
7
|
+
|
|
8
|
+
const LowQuality: FilePresetType = {
|
|
9
|
+
sampleRate: 22050,
|
|
10
|
+
bitRate: 48000,
|
|
11
|
+
bitDepth: BitDepth.Bit16,
|
|
12
|
+
flacCompressionLevel: FlacCompressionLevel.L0,
|
|
13
|
+
iosQuality: IOSAudioQuality.Low,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const MediumQuality: FilePresetType = {
|
|
17
|
+
sampleRate: 44100,
|
|
18
|
+
bitRate: 128000,
|
|
19
|
+
bitDepth: BitDepth.Bit16,
|
|
20
|
+
flacCompressionLevel: FlacCompressionLevel.L3,
|
|
21
|
+
iosQuality: IOSAudioQuality.Medium,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const HighQuality: FilePresetType = {
|
|
25
|
+
sampleRate: 48000,
|
|
26
|
+
bitRate: 192000,
|
|
27
|
+
bitDepth: BitDepth.Bit24,
|
|
28
|
+
flacCompressionLevel: FlacCompressionLevel.L5,
|
|
29
|
+
iosQuality: IOSAudioQuality.High,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const LosslessQuality: FilePresetType = {
|
|
33
|
+
sampleRate: 48000,
|
|
34
|
+
bitRate: 320000,
|
|
35
|
+
bitDepth: BitDepth.Bit24,
|
|
36
|
+
flacCompressionLevel: FlacCompressionLevel.L8,
|
|
37
|
+
iosQuality: IOSAudioQuality.High,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const FilePreset = {
|
|
41
|
+
Low: LowQuality,
|
|
42
|
+
Medium: MediumQuality,
|
|
43
|
+
High: HighQuality,
|
|
44
|
+
Lossless: LosslessQuality,
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
export default FilePreset;
|
|
@@ -4,11 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
import type { AudioEventSubscription } from '../../events';
|
|
6
6
|
import type {
|
|
7
|
+
NotificationEvents,
|
|
7
8
|
NotificationManager,
|
|
8
|
-
PlaybackNotificationInfo,
|
|
9
9
|
PlaybackControlName,
|
|
10
10
|
PlaybackNotificationEventName,
|
|
11
|
-
|
|
11
|
+
PlaybackNotificationInfo,
|
|
12
12
|
} from '../../system';
|
|
13
13
|
|
|
14
14
|
/// Mock Manager for playback notifications. Does nothing.
|
|
@@ -20,8 +20,8 @@ class PlaybackNotificationManager
|
|
|
20
20
|
PlaybackNotificationEventName
|
|
21
21
|
>
|
|
22
22
|
{
|
|
23
|
-
private
|
|
24
|
-
private
|
|
23
|
+
private isRegistered_ = false;
|
|
24
|
+
private isShown_ = false;
|
|
25
25
|
|
|
26
26
|
constructor() {}
|
|
27
27
|
|
|
@@ -41,7 +41,11 @@ class PlaybackNotificationManager
|
|
|
41
41
|
): Promise<void> {}
|
|
42
42
|
|
|
43
43
|
async isActive(): Promise<boolean> {
|
|
44
|
-
return this.
|
|
44
|
+
return this.isShown_;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
isRegistered(): boolean {
|
|
48
|
+
return this.isRegistered_;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
51
|
addEventListener<T extends PlaybackNotificationEventName>(
|