sezo-audio-engine 0.0.3 → 0.0.4

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/README.md CHANGED
@@ -22,6 +22,28 @@ Android recording:
22
22
  <uses-permission android:name="android.permission.RECORD_AUDIO" />
23
23
  ```
24
24
 
25
+ ## Android Engine Dependency
26
+
27
+ The Expo module links to the Android engine from JitPack by default. Add the JitPack repository to your app:
28
+
29
+ ```gradle
30
+ // android/build.gradle
31
+ allprojects {
32
+ repositories {
33
+ maven { url "https://www.jitpack.io" }
34
+ }
35
+ }
36
+ ```
37
+
38
+ Optionally pin the engine version in `android/gradle.properties`:
39
+
40
+ ```properties
41
+ sezoAudioEngineVersion=android-engine-v0.1.3
42
+ ```
43
+
44
+ If you want to build from source instead, include the local engine module in
45
+ `android/settings.gradle` and it will be picked up automatically.
46
+
25
47
  iOS recording or background playback:
26
48
 
27
49
  ```json
@@ -44,7 +44,7 @@ dependencies {
44
44
  if (androidEngineProject != null) {
45
45
  implementation androidEngineProject
46
46
  } else {
47
- def sezoAudioEngineVersion = project.findProperty("sezoAudioEngineVersion") ?: "v0.1.3"
47
+ def sezoAudioEngineVersion = project.findProperty("sezoAudioEngineVersion") ?: "android-engine-v0.1.3"
48
48
  implementation "com.github.Sepzie:SezoAudioEngine:${sezoAudioEngineVersion}"
49
49
  }
50
50
  }
@@ -290,16 +290,27 @@ final class NativeAudioEngine {
290
290
  }
291
291
 
292
292
  /// Starts recording from the input node into AAC or WAV.
293
- func startRecording(config: [String: Any]?) {
294
- queue.sync {
295
- guard !isRecordingFlag else { return }
293
+ @discardableResult
294
+ func startRecording(config: [String: Any]?) -> Bool {
295
+ return queue.sync {
296
+ guard !isRecordingFlag else { return true }
296
297
  ensureInitializedIfNeeded()
297
298
 
298
299
  let inputNode = engine.inputNode
299
- let inputFormat = inputNode.outputFormat(forBus: 0)
300
+ var inputFormat = inputNode.outputFormat(forBus: 0)
301
+ var attempts = 0
302
+ while (inputFormat.sampleRate == 0 || inputFormat.channelCount == 0) && attempts < 3 {
303
+ sessionManager.configure(with: lastConfig)
304
+ Thread.sleep(forTimeInterval: 0.05)
305
+ inputFormat = inputNode.outputFormat(forBus: 0)
306
+ attempts += 1
307
+ }
308
+ guard inputFormat.sampleRate > 0, inputFormat.channelCount > 0 else {
309
+ return false
310
+ }
300
311
  let requestedFormat = config?["format"] as? String ?? "aac"
301
- let channels = config?["channels"] as? Int ?? Int(inputFormat.channelCount)
302
- let sampleRate = config?["sampleRate"] as? Double ?? inputFormat.sampleRate
312
+ let channels = Int(inputFormat.channelCount)
313
+ let sampleRate = inputFormat.sampleRate
303
314
  let bitrate = resolveBitrate(config: config)
304
315
  let formatInfo = resolveRecordingFormat(requestedFormat: requestedFormat)
305
316
  let outputURL = resolveOutputURL(
@@ -341,7 +352,7 @@ final class NativeAudioEngine {
341
352
 
342
353
  guard startEngineIfNeeded() else {
343
354
  recordingState = nil
344
- return
355
+ return false
345
356
  }
346
357
 
347
358
  inputNode.removeTap(onBus: 0)
@@ -360,8 +371,10 @@ final class NativeAudioEngine {
360
371
  }
361
372
 
362
373
  isRecordingFlag = true
374
+ return true
363
375
  } catch {
364
376
  recordingState = nil
377
+ return false
365
378
  }
366
379
  }
367
380
  }
@@ -95,8 +95,17 @@ public class ExpoAudioEngineModule: Module {
95
95
  engine.setTempoAndPitch(tempo: tempo, pitch: pitch)
96
96
  }
97
97
 
98
- AsyncFunction("startRecording") { (config: [String: Any]?) in
99
- engine.startRecording(config: config)
98
+ AsyncFunction("startRecording") { (config: [String: Any]?) throws in
99
+ let didStart = engine.startRecording(config: config)
100
+ if !didStart {
101
+ throw NSError(
102
+ domain: "ExpoAudioEngine",
103
+ code: 1,
104
+ userInfo: [
105
+ NSLocalizedDescriptionKey: "Failed to start recording. Audio input format is invalid or the audio session is not ready."
106
+ ]
107
+ )
108
+ }
100
109
  }
101
110
  AsyncFunction("stopRecording") {
102
111
  return engine.stopRecording()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sezo-audio-engine",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Cross-platform Expo module for the Sezo Audio Engine with iOS implementation and background playback.",
5
5
  "license": "MIT",
6
6
  "author": "Sezo",