nosnia-audio-recorder 0.6.3 → 0.7.2

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.
@@ -161,9 +161,9 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
161
161
  if (!sampleRate || ![sampleRate isKindOfClass:[NSNumber class]] || [sampleRate integerValue] <= 0) {
162
162
  sampleRate = @(44100);
163
163
  } else {
164
- // AAC requires specific sample rates: 8000, 16000, 22050, 24000, 32000, 44100, 48000
164
+ // AAC/MP3 compatible sample rates: 8000, 16000, 22050, 32000, 44100, 48000
165
165
  NSInteger rate = [sampleRate integerValue];
166
- NSArray *validRates = @[@8000, @16000, @22050, @24000, @32000, @44100, @48000];
166
+ NSArray *validRates = @[@8000, @16000, @22050, @32000, @44100, @48000];
167
167
  if (![validRates containsObject:sampleRate]) {
168
168
  sampleRate = @(44100); // Default to 44100 if invalid
169
169
  }
@@ -176,17 +176,30 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
176
176
  return;
177
177
  }
178
178
 
179
- // Set audio category - use Record category with DuckOthers option
179
+ // Set audio category - use Record category with multiple options for compatibility
180
180
  NSError *categoryError = nil;
181
+ AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionDuckOthers |
182
+ AVAudioSessionCategoryOptionDefaultToSpeaker;
181
183
  BOOL categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
182
- withOptions:AVAudioSessionCategoryOptionDuckOthers
184
+ withOptions:options
183
185
  error:&categoryError];
184
186
  if (!categorySuccess || categoryError) {
185
- NSString *msg = categoryError ? categoryError.description : @"Failed to set audio category";
186
- reject(@"AUDIO_SESSION_ERROR", msg, categoryError);
187
- return;
187
+ // Try without DefaultToSpeaker if it fails
188
+ categoryError = nil;
189
+ categorySuccess = [audioSession setCategory:AVAudioSessionCategoryRecord
190
+ withOptions:AVAudioSessionCategoryOptionDuckOthers
191
+ error:&categoryError];
192
+ if (!categorySuccess || categoryError) {
193
+ NSString *msg = categoryError ? categoryError.description : @"Failed to set audio category";
194
+ reject(@"AUDIO_SESSION_ERROR", msg, categoryError);
195
+ return;
196
+ }
188
197
  }
189
198
 
199
+ // Set audio mode to measurement for recording
200
+ NSError *modeError = nil;
201
+ [audioSession setMode:AVAudioSessionModeMeasurement error:&modeError];
202
+
190
203
  // Activate audio session
191
204
  NSError *activateError = nil;
192
205
  BOOL activateSuccess = [audioSession setActive:YES error:&activateError];
@@ -204,13 +217,14 @@ RCT_EXPORT_METHOD(startRecording:(NSDictionary *)options
204
217
 
205
218
  // Create recording settings dictionary with safety checks
206
219
  @try {
207
- // Use IMA4 codec - most compatible across all iOS versions
220
+ // Use AAC format with validated parameters
221
+ // AVAudioRecorder will encode to M4A/AAC automatically
208
222
  NSDictionary *recordingSettings = @{
209
- AVFormatIDKey: @(kAudioFormatIMA4),
210
- AVSampleRateKey: @(16000),
211
- AVNumberOfChannelsKey: @(1),
212
- AVEncoderBitRateKey: @(32000),
213
- AVEncoderAudioQualityKey: @(AVAudioQualityLow)
223
+ AVFormatIDKey: @(kAudioFormatMPEG4AAC),
224
+ AVSampleRateKey: sampleRate,
225
+ AVNumberOfChannelsKey: channels,
226
+ AVEncoderBitRateKey: bitrate,
227
+ AVEncoderAudioQualityKey: @(AVAudioQualityHigh)
214
228
  };
215
229
 
216
230
  // Validate settings dictionary created successfully
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nosnia-audio-recorder",
3
- "version": "0.6.3",
3
+ "version": "0.7.2",
4
4
  "description": "This is a modern audio recorder which actually works cross platform",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",