nosnia-audio-recorder 0.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/LICENSE +20 -0
- package/NosniaAudioRecorder.podspec +20 -0
- package/README.md +175 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/nosniaaudiorecorder/NosniaAudioRecorderModule.kt +232 -0
- package/android/src/main/java/com/nosniaaudiorecorder/NosniaAudioRecorderPackage.kt +33 -0
- package/ios/NosniaAudioRecorder.h +6 -0
- package/ios/NosniaAudioRecorder.mm +243 -0
- package/lib/module/NativeNosniaAudioRecorder.js +5 -0
- package/lib/module/NativeNosniaAudioRecorder.js.map +1 -0
- package/lib/module/index.js +133 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeNosniaAudioRecorder.d.ts +25 -0
- package/lib/typescript/src/NativeNosniaAudioRecorder.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +50 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +170 -0
- package/src/NativeNosniaAudioRecorder.ts +27 -0
- package/src/index.tsx +140 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#import "NosniaAudioRecorder.h"
|
|
2
|
+
#import <AVFoundation/AVFoundation.h>
|
|
3
|
+
#import <React/RCTBridgeModule.h>
|
|
4
|
+
|
|
5
|
+
@interface NosniaAudioRecorder () <AVAudioRecorderDelegate>
|
|
6
|
+
@property (nonatomic, strong) AVAudioRecorder *audioRecorder;
|
|
7
|
+
@property (nonatomic, strong) NSURL *recordingURL;
|
|
8
|
+
@property (nonatomic, assign) BOOL isRecording;
|
|
9
|
+
@end
|
|
10
|
+
|
|
11
|
+
@implementation NosniaAudioRecorder {
|
|
12
|
+
AVAudioRecorder *_audioRecorder;
|
|
13
|
+
NSURL *_recordingURL;
|
|
14
|
+
BOOL _isRecording;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
- (instancetype)init {
|
|
18
|
+
self = [super init];
|
|
19
|
+
if (self) {
|
|
20
|
+
_isRecording = NO;
|
|
21
|
+
}
|
|
22
|
+
return self;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
- (NSString *)getRecordingDirectory {
|
|
26
|
+
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
|
27
|
+
NSDocumentDirectory,
|
|
28
|
+
NSUserDomainMask,
|
|
29
|
+
YES
|
|
30
|
+
);
|
|
31
|
+
NSString *documentDir = [paths objectAtIndex:0];
|
|
32
|
+
NSString *recordingDir = [documentDir stringByAppendingPathComponent:@"NosniaAudioRecorder"];
|
|
33
|
+
|
|
34
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
35
|
+
if (![fileManager fileExistsAtPath:recordingDir]) {
|
|
36
|
+
[fileManager createDirectoryAtPath:recordingDir
|
|
37
|
+
withIntermediateDirectories:YES
|
|
38
|
+
attributes:nil
|
|
39
|
+
error:nil];
|
|
40
|
+
}
|
|
41
|
+
return recordingDir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (NSString *)generateFilename {
|
|
45
|
+
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
46
|
+
[formatter setDateFormat:@"yyyyMMdd_HHmmss"];
|
|
47
|
+
NSString *timestamp = [formatter stringFromDate:[NSDate date]];
|
|
48
|
+
return [NSString stringWithFormat:@"recording_%@.m4a", timestamp];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
- (void)startRecording:(NSDictionary *)options
|
|
52
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
53
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
54
|
+
@try {
|
|
55
|
+
if (_isRecording) {
|
|
56
|
+
reject(@"ALREADY_RECORDING", @"Recording is already in progress", nil);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
NSString *filename = options[@"filename"];
|
|
61
|
+
if (!filename) {
|
|
62
|
+
filename = [self generateFilename];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
NSString *recordingDir = [self getRecordingDirectory];
|
|
66
|
+
NSString *filePath = [recordingDir stringByAppendingPathComponent:filename];
|
|
67
|
+
_recordingURL = [NSURL fileURLWithPath:filePath];
|
|
68
|
+
|
|
69
|
+
NSNumber *bitrate = options[@"bitrate"] ?: @(128000);
|
|
70
|
+
NSNumber *channels = options[@"channels"] ?: @(1);
|
|
71
|
+
NSNumber *sampleRate = options[@"sampleRate"] ?: @(44100);
|
|
72
|
+
|
|
73
|
+
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
|
|
74
|
+
NSError *categoryError = nil;
|
|
75
|
+
[audioSession setCategory:AVAudioSessionCategoryRecord
|
|
76
|
+
error:&categoryError];
|
|
77
|
+
if (categoryError) {
|
|
78
|
+
reject(@"AUDIO_SESSION_ERROR", categoryError.description, categoryError);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
NSDictionary *recordingSettings = @{
|
|
83
|
+
AVFormatIDKey: @(kAudioFormatMPEG4AAC),
|
|
84
|
+
AVSampleRateKey: sampleRate,
|
|
85
|
+
AVNumberOfChannelsKey: channels,
|
|
86
|
+
AVEncoderBitRateKey: bitrate,
|
|
87
|
+
AVEncoderAudioQualityKey: @(AVAudioQualityMedium)
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
NSError *recorderError = nil;
|
|
91
|
+
_audioRecorder = [[AVAudioRecorder alloc] initWithURL:_recordingURL
|
|
92
|
+
settings:recordingSettings
|
|
93
|
+
error:&recorderError];
|
|
94
|
+
|
|
95
|
+
if (recorderError) {
|
|
96
|
+
reject(@"INIT_RECORDER_ERROR", recorderError.description, recorderError);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_audioRecorder.delegate = self;
|
|
101
|
+
if (![_audioRecorder record]) {
|
|
102
|
+
reject(@"START_RECORDING_ERROR", @"Failed to start recording", nil);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_isRecording = YES;
|
|
107
|
+
resolve(nil);
|
|
108
|
+
} @catch (NSException *exception) {
|
|
109
|
+
reject(@"START_RECORDING_ERROR", exception.reason, nil);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
- (void)stopRecording:(RCTPromiseResolveBlock)resolve
|
|
114
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
115
|
+
@try {
|
|
116
|
+
if (!_isRecording || !_audioRecorder) {
|
|
117
|
+
reject(@"NOT_RECORDING", @"No recording in progress", nil);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
[_audioRecorder stop];
|
|
122
|
+
NSString *filePath = [_recordingURL path];
|
|
123
|
+
_audioRecorder = nil;
|
|
124
|
+
_isRecording = NO;
|
|
125
|
+
|
|
126
|
+
resolve(filePath);
|
|
127
|
+
} @catch (NSException *exception) {
|
|
128
|
+
reject(@"STOP_RECORDING_ERROR", exception.reason, nil);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
- (void)pauseRecording:(RCTPromiseResolveBlock)resolve
|
|
133
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
134
|
+
@try {
|
|
135
|
+
if (!_isRecording || !_audioRecorder) {
|
|
136
|
+
reject(@"NOT_RECORDING", @"No recording in progress", nil);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
[_audioRecorder pause];
|
|
141
|
+
resolve(nil);
|
|
142
|
+
} @catch (NSException *exception) {
|
|
143
|
+
reject(@"PAUSE_ERROR", exception.reason, nil);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
- (void)resumeRecording:(RCTPromiseResolveBlock)resolve
|
|
148
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
149
|
+
@try {
|
|
150
|
+
if (!_isRecording || !_audioRecorder || [_audioRecorder isRecording]) {
|
|
151
|
+
reject(@"NOT_PAUSED", @"Recording is not paused", nil);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
[_audioRecorder record];
|
|
156
|
+
resolve(nil);
|
|
157
|
+
} @catch (NSException *exception) {
|
|
158
|
+
reject(@"RESUME_ERROR", exception.reason, nil);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
- (void)cancelRecording:(RCTPromiseResolveBlock)resolve
|
|
163
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
164
|
+
@try {
|
|
165
|
+
if (_audioRecorder) {
|
|
166
|
+
[_audioRecorder stop];
|
|
167
|
+
_audioRecorder = nil;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (_recordingURL) {
|
|
171
|
+
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
172
|
+
[fileManager removeItemAtURL:_recordingURL error:nil];
|
|
173
|
+
_recordingURL = nil;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_isRecording = NO;
|
|
177
|
+
resolve(nil);
|
|
178
|
+
} @catch (NSException *exception) {
|
|
179
|
+
reject(@"CANCEL_ERROR", exception.reason, nil);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
- (void)getRecorderStatus:(RCTPromiseResolveBlock)resolve
|
|
184
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
185
|
+
@try {
|
|
186
|
+
NSMutableDictionary *status = [NSMutableDictionary dictionary];
|
|
187
|
+
status[@"isRecording"] = @(_isRecording);
|
|
188
|
+
status[@"duration"] = @(_audioRecorder.currentTime * 1000);
|
|
189
|
+
if (_recordingURL) {
|
|
190
|
+
status[@"currentFilePath"] = [_recordingURL path];
|
|
191
|
+
}
|
|
192
|
+
resolve(status);
|
|
193
|
+
} @catch (NSException *exception) {
|
|
194
|
+
reject(@"STATUS_ERROR", exception.reason, nil);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
- (void)requestAudioPermission:(RCTPromiseResolveBlock)resolve
|
|
199
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
200
|
+
@try {
|
|
201
|
+
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
|
|
202
|
+
[audioSession requestRecordPermission:^(BOOL granted) {
|
|
203
|
+
resolve(@(granted));
|
|
204
|
+
}];
|
|
205
|
+
} @catch (NSException *exception) {
|
|
206
|
+
reject(@"PERMISSION_ERROR", exception.reason, nil);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
- (void)checkAudioPermission:(RCTPromiseResolveBlock)resolve
|
|
211
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
212
|
+
@try {
|
|
213
|
+
AVAudioSessionRecordPermission permissionStatus =
|
|
214
|
+
[[AVAudioSession sharedInstance] recordPermission];
|
|
215
|
+
BOOL hasPermission = permissionStatus == AVAudioSessionRecordPermissionGranted;
|
|
216
|
+
resolve(@(hasPermission));
|
|
217
|
+
} @catch (NSException *exception) {
|
|
218
|
+
reject(@"PERMISSION_ERROR", exception.reason, nil);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
#pragma mark - AVAudioRecorderDelegate
|
|
223
|
+
|
|
224
|
+
- (void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder
|
|
225
|
+
successfully:(BOOL)flag {
|
|
226
|
+
_isRecording = NO;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
- (void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder
|
|
230
|
+
error:(NSError *)error {
|
|
231
|
+
_isRecording = NO;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
235
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params {
|
|
236
|
+
return std::make_shared<facebook::react::NativeNosniaAudioRecorderSpecJSI>(params);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
+ (NSString *)moduleName {
|
|
240
|
+
return @"NosniaAudioRecorder";
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"..\\..\\src","sources":["NativeNosniaAudioRecorder.ts"],"mappings":";;AAAA,SAASA,mBAAmB,QAA0B,cAAc;AA0BpE,eAAeA,mBAAmB,CAACC,YAAY,CAAO,qBAAqB,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import NativeModule from "./NativeNosniaAudioRecorder.js";
|
|
4
|
+
class AudioRecorder {
|
|
5
|
+
static instance = null;
|
|
6
|
+
constructor() {}
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!AudioRecorder.instance) {
|
|
9
|
+
AudioRecorder.instance = new AudioRecorder();
|
|
10
|
+
}
|
|
11
|
+
return AudioRecorder.instance;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Request audio recording permission from the user
|
|
16
|
+
* @returns Promise that resolves to true if permission is granted
|
|
17
|
+
*/
|
|
18
|
+
async requestPermission() {
|
|
19
|
+
try {
|
|
20
|
+
return await NativeModule.requestAudioPermission();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error('Error requesting audio permission:', error);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Check if audio recording permission is already granted
|
|
29
|
+
* @returns Promise that resolves to true if permission is granted
|
|
30
|
+
*/
|
|
31
|
+
async checkPermission() {
|
|
32
|
+
try {
|
|
33
|
+
return await NativeModule.checkAudioPermission();
|
|
34
|
+
} catch (error) {
|
|
35
|
+
console.error('Error checking audio permission:', error);
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Start recording audio with optional configuration
|
|
42
|
+
* @param options Configuration options for the recording (bitrate, channels, sample rate, filename)
|
|
43
|
+
* @returns Promise that resolves when recording starts
|
|
44
|
+
*/
|
|
45
|
+
async startRecording(options) {
|
|
46
|
+
try {
|
|
47
|
+
const hasPermission = await this.checkPermission();
|
|
48
|
+
if (!hasPermission) {
|
|
49
|
+
throw new Error('Audio recording permission not granted. Request permission first.');
|
|
50
|
+
}
|
|
51
|
+
const config = {
|
|
52
|
+
bitrate: 128000,
|
|
53
|
+
// 128 kbps
|
|
54
|
+
channels: 1,
|
|
55
|
+
// Mono
|
|
56
|
+
sampleRate: 44100,
|
|
57
|
+
// 44.1 kHz
|
|
58
|
+
...options
|
|
59
|
+
};
|
|
60
|
+
return await NativeModule.startRecording(config);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
console.error('Error starting recording:', error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Stop recording and save the file
|
|
69
|
+
* @returns Promise that resolves to the file path of the recorded audio
|
|
70
|
+
*/
|
|
71
|
+
async stopRecording() {
|
|
72
|
+
try {
|
|
73
|
+
return await NativeModule.stopRecording();
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error stopping recording:', error);
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Pause the current recording
|
|
82
|
+
* @returns Promise that resolves when recording is paused
|
|
83
|
+
*/
|
|
84
|
+
async pauseRecording() {
|
|
85
|
+
try {
|
|
86
|
+
return await NativeModule.pauseRecording();
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Error pausing recording:', error);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Resume a paused recording
|
|
95
|
+
* @returns Promise that resolves when recording resumes
|
|
96
|
+
*/
|
|
97
|
+
async resumeRecording() {
|
|
98
|
+
try {
|
|
99
|
+
return await NativeModule.resumeRecording();
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.error('Error resuming recording:', error);
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Cancel the current recording and discard the file
|
|
108
|
+
* @returns Promise that resolves when recording is cancelled
|
|
109
|
+
*/
|
|
110
|
+
async cancelRecording() {
|
|
111
|
+
try {
|
|
112
|
+
return await NativeModule.cancelRecording();
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error('Error cancelling recording:', error);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the current status of the recorder
|
|
121
|
+
* @returns Promise that resolves to the current recorder status
|
|
122
|
+
*/
|
|
123
|
+
async getStatus() {
|
|
124
|
+
try {
|
|
125
|
+
return await NativeModule.getRecorderStatus();
|
|
126
|
+
} catch (error) {
|
|
127
|
+
console.error('Error getting recorder status:', error);
|
|
128
|
+
throw error;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export const NosniaAudioRecorder = AudioRecorder.getInstance();
|
|
133
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NativeModule","AudioRecorder","instance","constructor","getInstance","requestPermission","requestAudioPermission","error","console","checkPermission","checkAudioPermission","startRecording","options","hasPermission","Error","config","bitrate","channels","sampleRate","stopRecording","pauseRecording","resumeRecording","cancelRecording","getStatus","getRecorderStatus","NosniaAudioRecorder"],"sourceRoot":"..\\..\\src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,YAAY,MAGZ,gCAA6B;AAIpC,MAAMC,aAAa,CAAC;EAClB,OAAeC,QAAQ,GAA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;AACF;AAEA,OAAO,MAAMkB,mBAAmB,GAAGxB,aAAa,CAACG,WAAW,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type TurboModule } from 'react-native';
|
|
2
|
+
export interface RecorderOptions {
|
|
3
|
+
filename?: string;
|
|
4
|
+
bitrate?: number;
|
|
5
|
+
channels?: number;
|
|
6
|
+
sampleRate?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface RecorderStatus {
|
|
9
|
+
isRecording: boolean;
|
|
10
|
+
duration: number;
|
|
11
|
+
currentFilePath?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface Spec extends TurboModule {
|
|
14
|
+
startRecording(options: RecorderOptions): Promise<void>;
|
|
15
|
+
stopRecording(): Promise<string>;
|
|
16
|
+
pauseRecording(): Promise<void>;
|
|
17
|
+
resumeRecording(): Promise<void>;
|
|
18
|
+
cancelRecording(): Promise<void>;
|
|
19
|
+
getRecorderStatus(): Promise<RecorderStatus>;
|
|
20
|
+
requestAudioPermission(): Promise<boolean>;
|
|
21
|
+
checkAudioPermission(): Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
declare const _default: Spec;
|
|
24
|
+
export default _default;
|
|
25
|
+
//# sourceMappingURL=NativeNosniaAudioRecorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeNosniaAudioRecorder.d.ts","sourceRoot":"","sources":["../../../src/NativeNosniaAudioRecorder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,cAAc,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACjC,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAChC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;IAC7C,sBAAsB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAC3C,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1C;;AAED,wBAA6E"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type RecorderOptions, type RecorderStatus } from './NativeNosniaAudioRecorder';
|
|
2
|
+
export type { RecorderOptions, RecorderStatus };
|
|
3
|
+
declare class AudioRecorder {
|
|
4
|
+
private static instance;
|
|
5
|
+
private constructor();
|
|
6
|
+
static getInstance(): AudioRecorder;
|
|
7
|
+
/**
|
|
8
|
+
* Request audio recording permission from the user
|
|
9
|
+
* @returns Promise that resolves to true if permission is granted
|
|
10
|
+
*/
|
|
11
|
+
requestPermission(): Promise<boolean>;
|
|
12
|
+
/**
|
|
13
|
+
* Check if audio recording permission is already granted
|
|
14
|
+
* @returns Promise that resolves to true if permission is granted
|
|
15
|
+
*/
|
|
16
|
+
checkPermission(): Promise<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Start recording audio with optional configuration
|
|
19
|
+
* @param options Configuration options for the recording (bitrate, channels, sample rate, filename)
|
|
20
|
+
* @returns Promise that resolves when recording starts
|
|
21
|
+
*/
|
|
22
|
+
startRecording(options?: RecorderOptions): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Stop recording and save the file
|
|
25
|
+
* @returns Promise that resolves to the file path of the recorded audio
|
|
26
|
+
*/
|
|
27
|
+
stopRecording(): Promise<string>;
|
|
28
|
+
/**
|
|
29
|
+
* Pause the current recording
|
|
30
|
+
* @returns Promise that resolves when recording is paused
|
|
31
|
+
*/
|
|
32
|
+
pauseRecording(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Resume a paused recording
|
|
35
|
+
* @returns Promise that resolves when recording resumes
|
|
36
|
+
*/
|
|
37
|
+
resumeRecording(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Cancel the current recording and discard the file
|
|
40
|
+
* @returns Promise that resolves when recording is cancelled
|
|
41
|
+
*/
|
|
42
|
+
cancelRecording(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Get the current status of the recorder
|
|
45
|
+
* @returns Promise that resolves to the current recorder status
|
|
46
|
+
*/
|
|
47
|
+
getStatus(): Promise<RecorderStatus>;
|
|
48
|
+
}
|
|
49
|
+
export declare const NosniaAudioRecorder: AudioRecorder;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAqB,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,6BAA6B,CAAC;AAErC,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,CAAC;AAEhD,cAAM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA8B;IAErD,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,aAAa;IAOnC;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;IAS3C;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,OAAO,CAAC;IASzC;;;;OAIG;IACG,cAAc,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB9D;;;OAGG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IAStC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IASrC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC;;;OAGG;IACG,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC;IAStC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,cAAc,CAAC;CAQ3C;AAED,eAAO,MAAM,mBAAmB,eAA8B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nosnia-audio-recorder",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "This is a modern audio recorder which actually works cross platform",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace nosnia-audio-recorder-example",
|
|
36
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
40
|
+
"release": "release-it --only-version",
|
|
41
|
+
"test": "jest"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://nosnia.ai.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "Parth Thakkar <parth@nosnia.ai> (https://nosnia.ai)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://nosnia.ai/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://nosnia.ai#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@react-native-community/cli": "20.0.1",
|
|
67
|
+
"@react-native/babel-preset": "0.81.1",
|
|
68
|
+
"@react-native/eslint-config": "^0.81.1",
|
|
69
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
70
|
+
"@types/jest": "^29.5.14",
|
|
71
|
+
"@types/react": "^19.1.0",
|
|
72
|
+
"commitlint": "^19.8.1",
|
|
73
|
+
"del-cli": "^6.0.0",
|
|
74
|
+
"eslint": "^9.35.0",
|
|
75
|
+
"eslint-config-prettier": "^10.1.8",
|
|
76
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
77
|
+
"jest": "^29.7.0",
|
|
78
|
+
"lefthook": "^2.0.3",
|
|
79
|
+
"prettier": "^2.8.8",
|
|
80
|
+
"react": "19.1.0",
|
|
81
|
+
"react-native": "0.81.1",
|
|
82
|
+
"react-native-builder-bob": "^0.40.13",
|
|
83
|
+
"release-it": "^19.0.4",
|
|
84
|
+
"turbo": "^2.5.6",
|
|
85
|
+
"typescript": "^5.9.2"
|
|
86
|
+
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"react": "*",
|
|
89
|
+
"react-native": "*"
|
|
90
|
+
},
|
|
91
|
+
"workspaces": [
|
|
92
|
+
"example"
|
|
93
|
+
],
|
|
94
|
+
"packageManager": "yarn@4.11.0",
|
|
95
|
+
"react-native-builder-bob": {
|
|
96
|
+
"source": "src",
|
|
97
|
+
"output": "lib",
|
|
98
|
+
"targets": [
|
|
99
|
+
[
|
|
100
|
+
"module",
|
|
101
|
+
{
|
|
102
|
+
"esm": true
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
[
|
|
106
|
+
"typescript",
|
|
107
|
+
{
|
|
108
|
+
"project": "tsconfig.build.json"
|
|
109
|
+
}
|
|
110
|
+
]
|
|
111
|
+
]
|
|
112
|
+
},
|
|
113
|
+
"codegenConfig": {
|
|
114
|
+
"name": "NosniaAudioRecorderSpec",
|
|
115
|
+
"type": "modules",
|
|
116
|
+
"jsSrcsDir": "src",
|
|
117
|
+
"android": {
|
|
118
|
+
"javaPackageName": "com.nosniaaudiorecorder"
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
"prettier": {
|
|
122
|
+
"quoteProps": "consistent",
|
|
123
|
+
"singleQuote": true,
|
|
124
|
+
"tabWidth": 2,
|
|
125
|
+
"trailingComma": "es5",
|
|
126
|
+
"useTabs": false
|
|
127
|
+
},
|
|
128
|
+
"commitlint": {
|
|
129
|
+
"extends": [
|
|
130
|
+
"@commitlint/config-conventional"
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
"release-it": {
|
|
134
|
+
"git": {
|
|
135
|
+
"commitMessage": "chore: release ${version}",
|
|
136
|
+
"tagName": "v${version}"
|
|
137
|
+
},
|
|
138
|
+
"npm": {
|
|
139
|
+
"publish": true
|
|
140
|
+
},
|
|
141
|
+
"github": {
|
|
142
|
+
"release": true
|
|
143
|
+
},
|
|
144
|
+
"plugins": {
|
|
145
|
+
"@release-it/conventional-changelog": {
|
|
146
|
+
"preset": {
|
|
147
|
+
"name": "angular"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"jest": {
|
|
153
|
+
"preset": "react-native",
|
|
154
|
+
"modulePathIgnorePatterns": [
|
|
155
|
+
"<rootDir>/example/node_modules",
|
|
156
|
+
"<rootDir>/lib/"
|
|
157
|
+
]
|
|
158
|
+
},
|
|
159
|
+
"create-react-native-library": {
|
|
160
|
+
"languages": "kotlin-objc",
|
|
161
|
+
"type": "turbo-module",
|
|
162
|
+
"tools": [
|
|
163
|
+
"eslint",
|
|
164
|
+
"lefthook",
|
|
165
|
+
"release-it",
|
|
166
|
+
"jest"
|
|
167
|
+
],
|
|
168
|
+
"version": "0.55.0"
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TurboModuleRegistry, type TurboModule } from 'react-native';
|
|
2
|
+
|
|
3
|
+
export interface RecorderOptions {
|
|
4
|
+
filename?: string;
|
|
5
|
+
bitrate?: number;
|
|
6
|
+
channels?: number;
|
|
7
|
+
sampleRate?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface RecorderStatus {
|
|
11
|
+
isRecording: boolean;
|
|
12
|
+
duration: number;
|
|
13
|
+
currentFilePath?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Spec extends TurboModule {
|
|
17
|
+
startRecording(options: RecorderOptions): Promise<void>;
|
|
18
|
+
stopRecording(): Promise<string>;
|
|
19
|
+
pauseRecording(): Promise<void>;
|
|
20
|
+
resumeRecording(): Promise<void>;
|
|
21
|
+
cancelRecording(): Promise<void>;
|
|
22
|
+
getRecorderStatus(): Promise<RecorderStatus>;
|
|
23
|
+
requestAudioPermission(): Promise<boolean>;
|
|
24
|
+
checkAudioPermission(): Promise<boolean>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('NosniaAudioRecorder');
|