@siteed/expo-audio-stream 1.14.2 → 1.15.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 CHANGED
@@ -8,8 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [Unreleased]
9
9
 
10
10
 
11
+ ## [1.15.0] - 2025-02-15
12
+ ### Changed
13
+ - fix(ios): improve audio recording interruption handling and auto-resume functionality (#119) ([7767dff](https://github.com/deeeed/expo-audio-stream/commit/7767dff09c7c8d2f2dc8558d24fd2419cb981f4d))
14
+ - fix(android): improve background recording and call interruption handling (#118) ([bf19fe9](https://github.com/deeeed/expo-audio-stream/commit/bf19fe92cadbcc080c27a8aa06ba9a2f6ca841b0))
11
15
  ## [1.14.2] - 2025-02-13
12
-
16
+ - fix: update STOP action to clear recording metadata ([3484f76](https://github.com/deeeed/expo-audio-stream/commit/3484f76331c0cc83e2384dd18a7f4555f5c5ce8d))
13
17
  ## [1.14.1] - 2025-02-12
14
18
  - fix: enable background recording by default and improve audio playground (#114) ([2f60d5e](https://github.com/deeeed/expo-audio-stream/commit/2f60d5edd96ea6d0db7cf35614bc12dcd8d9c6ed))
15
19
  ## [1.14.0] - 2025-02-12
@@ -115,7 +119,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
115
119
  - Feature: Audio features extraction during recording.
116
120
  - Feature: Consistent WAV PCM recording format across all platforms.
117
121
 
118
- [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.14.2...HEAD
122
+ [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.15.0...HEAD
123
+ [1.15.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.14.2...@siteed/expo-audio-stream@1.15.0
119
124
  [1.14.2]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.14.1...@siteed/expo-audio-stream@1.14.2
120
125
  [1.14.1]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.14.0...@siteed/expo-audio-stream@1.14.1
121
126
  [1.14.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.13.2...@siteed/expo-audio-stream@1.14.0
@@ -1,5 +1,6 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
2
  <!-- Permissions will be merged into the app's manifest -->
3
+ <uses-permission android:name="android.permission.READ_PHONE_STATE" />
3
4
  <uses-permission android:name="android.permission.RECORD_AUDIO"/>
4
5
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
5
6
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>
@@ -30,6 +30,7 @@ import android.telephony.PhoneStateListener
30
30
  import android.telephony.TelephonyManager
31
31
  import android.app.ActivityManager
32
32
  import java.util.UUID
33
+ import android.media.AudioDeviceInfo
33
34
 
34
35
  class AudioRecorderManager(
35
36
  private val context: Context,
@@ -75,6 +76,100 @@ class AudioRecorderManager(
75
76
  private var audioFocusRequest: Any? = null // Type Any to handle both old and new APIs
76
77
  private var phoneStateListener: PhoneStateListener? = null
77
78
  private var telephonyManager: TelephonyManager? = null
79
+ get() {
80
+ if (field == null) {
81
+ field = context.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
82
+ Log.d(Constants.TAG, "TelephonyManager initialization: ${if (field != null) "successful" else "failed"}")
83
+ }
84
+ return field
85
+ }
86
+
87
+ private fun initializePhoneStateListener() {
88
+ try {
89
+ Log.d(Constants.TAG, "Initializing phone state listener...")
90
+
91
+ if (permissionUtils.checkPhoneStatePermission()) {
92
+ Log.d(Constants.TAG, "Phone state permission granted")
93
+
94
+ phoneStateListener = object : PhoneStateListener() {
95
+ override fun onCallStateChanged(state: Int, phoneNumber: String?) {
96
+ val stateStr = when (state) {
97
+ TelephonyManager.CALL_STATE_RINGING -> "RINGING"
98
+ TelephonyManager.CALL_STATE_OFFHOOK -> "OFFHOOK"
99
+ TelephonyManager.CALL_STATE_IDLE -> "IDLE"
100
+ else -> "UNKNOWN"
101
+ }
102
+ Log.d(Constants.TAG, "Phone state changed to: $stateStr")
103
+
104
+ when (state) {
105
+ TelephonyManager.CALL_STATE_RINGING,
106
+ TelephonyManager.CALL_STATE_OFFHOOK -> {
107
+ if (isRecording.get() && !isPaused.get()) {
108
+ Log.d(Constants.TAG, "Pausing recording due to incoming/ongoing call")
109
+ mainHandler.post {
110
+ pauseRecording(object : Promise {
111
+ override fun resolve(value: Any?) {
112
+ Log.d(Constants.TAG, "Successfully paused recording due to call")
113
+ eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
114
+ "reason" to "phoneCall",
115
+ "isPaused" to true
116
+ ))
117
+ }
118
+ override fun reject(code: String, message: String?, cause: Throwable?) {
119
+ Log.e(Constants.TAG, "Failed to pause recording on phone call", cause)
120
+ }
121
+ })
122
+ }
123
+ }
124
+ }
125
+ TelephonyManager.CALL_STATE_IDLE -> {
126
+ if (isRecording.get() && isPaused.get()) {
127
+ Log.d(Constants.TAG, "Call ended, handling auto-resume (enabled: ${recordingConfig.autoResumeAfterInterruption})")
128
+ if (recordingConfig.autoResumeAfterInterruption) {
129
+ mainHandler.post {
130
+ resumeRecording(object : Promise {
131
+ override fun resolve(value: Any?) {
132
+ Log.d(Constants.TAG, "Successfully resumed recording after call")
133
+ eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
134
+ "reason" to "phoneCallEnded",
135
+ "isPaused" to false
136
+ ))
137
+ }
138
+ override fun reject(code: String, message: String?, cause: Throwable?) {
139
+ Log.e(Constants.TAG, "Failed to resume recording after phone call", cause)
140
+ }
141
+ })
142
+ }
143
+ } else {
144
+ Log.d(Constants.TAG, "Auto-resume disabled, staying paused")
145
+ eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
146
+ "reason" to "phoneCallEnded",
147
+ "isPaused" to true
148
+ ))
149
+ }
150
+ }
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ if (telephonyManager != null) {
157
+ try {
158
+ telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
159
+ Log.d(Constants.TAG, "Successfully registered phone state listener")
160
+ } catch (e: Exception) {
161
+ Log.e(Constants.TAG, "Failed to register phone state listener", e)
162
+ }
163
+ } else {
164
+ Log.e(Constants.TAG, "TelephonyManager is null, cannot register phone state listener")
165
+ }
166
+ } else {
167
+ Log.w(Constants.TAG, "READ_PHONE_STATE permission not granted, phone call interruption handling disabled")
168
+ }
169
+ } catch (e: Exception) {
170
+ Log.e(Constants.TAG, "Failed to initialize phone state listener", e)
171
+ }
172
+ }
78
173
 
79
174
  @RequiresApi(Build.VERSION_CODES.O)
80
175
  private val audioFocusCallback = object : AudioManager.OnAudioFocusChangeListener {
@@ -146,6 +241,106 @@ class AudioRecorderManager(
146
241
  }
147
242
  }
148
243
 
244
+ private fun isOngoingCall(): Boolean {
245
+ try {
246
+ if (!permissionUtils.checkPhoneStatePermission()) {
247
+ Log.w(Constants.TAG, "READ_PHONE_STATE permission not granted, cannot check call state")
248
+ return false
249
+ }
250
+
251
+ val tm = telephonyManager
252
+ if (tm == null) {
253
+ Log.e(Constants.TAG, "TelephonyManager is null")
254
+ return false
255
+ }
256
+
257
+ // Get audio manager state
258
+ val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
259
+ val audioMode = audioManager.mode
260
+ val isMusicActive = audioManager.isMusicActive
261
+
262
+ // Get current audio device info
263
+ val currentRoute =
264
+ audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS).firstOrNull()?.type?.let { type ->
265
+ when (type) {
266
+ AudioDeviceInfo.TYPE_BUILTIN_SPEAKER -> "SPEAKER"
267
+ AudioDeviceInfo.TYPE_BUILTIN_EARPIECE -> "EARPIECE"
268
+ AudioDeviceInfo.TYPE_BLUETOOTH_SCO -> "BLUETOOTH_SCO"
269
+ AudioDeviceInfo.TYPE_BLUETOOTH_A2DP -> "BLUETOOTH_A2DP"
270
+ AudioDeviceInfo.TYPE_WIRED_HEADSET -> "WIRED_HEADSET"
271
+ AudioDeviceInfo.TYPE_WIRED_HEADPHONES -> "WIRED_HEADPHONES"
272
+ else -> "OTHER($type)"
273
+ }
274
+ } ?: "UNKNOWN"
275
+
276
+ // Get communication device info
277
+ val communicationDevice = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
278
+ audioManager.communicationDevice?.type?.let { type ->
279
+ when (type) {
280
+ AudioDeviceInfo.TYPE_BLUETOOTH_SCO -> "BLUETOOTH_SCO"
281
+ AudioDeviceInfo.TYPE_BUILTIN_SPEAKER -> "SPEAKER"
282
+ AudioDeviceInfo.TYPE_BUILTIN_EARPIECE -> "EARPIECE"
283
+ else -> "OTHER($type)"
284
+ }
285
+ } ?: "NONE"
286
+ } else {
287
+ @Suppress("DEPRECATION")
288
+ if (audioManager.isBluetoothScoOn) "BLUETOOTH_SCO" else "NONE"
289
+ }
290
+
291
+ Log.d(Constants.TAG, """
292
+ Audio State Check:
293
+ - Audio Mode: ${getAudioModeString(audioMode)}
294
+ - Music Active: $isMusicActive
295
+ - Current Audio Route: $currentRoute
296
+ - Communication Device: $communicationDevice
297
+ """.trimIndent())
298
+
299
+ // Check telephony state
300
+ val callState = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
301
+ tm.callStateForSubscription
302
+ } else {
303
+ @Suppress("DEPRECATION")
304
+ tm.callState
305
+ }
306
+
307
+ val isVoipCall = audioMode == AudioManager.MODE_IN_COMMUNICATION
308
+ val isRegularCall = callState == TelephonyManager.CALL_STATE_OFFHOOK ||
309
+ callState == TelephonyManager.CALL_STATE_RINGING
310
+
311
+ Log.d(Constants.TAG, """
312
+ Call State Check:
313
+ - Telephony Call State: ${getCallStateString(callState)}
314
+ - VoIP Call Detected: $isVoipCall
315
+ - Regular Call Detected: $isRegularCall
316
+ """.trimIndent())
317
+
318
+ return isVoipCall || isRegularCall
319
+
320
+ } catch (e: SecurityException) {
321
+ Log.e(Constants.TAG, "SecurityException when checking call state", e)
322
+ return false
323
+ } catch (e: Exception) {
324
+ Log.e(Constants.TAG, "Error checking call state", e)
325
+ return false
326
+ }
327
+ }
328
+
329
+ private fun getAudioModeString(mode: Int): String = when (mode) {
330
+ AudioManager.MODE_NORMAL -> "MODE_NORMAL"
331
+ AudioManager.MODE_RINGTONE -> "MODE_RINGTONE"
332
+ AudioManager.MODE_IN_CALL -> "MODE_IN_CALL"
333
+ AudioManager.MODE_IN_COMMUNICATION -> "MODE_IN_COMMUNICATION"
334
+ else -> "MODE_UNKNOWN($mode)"
335
+ }
336
+
337
+ private fun getCallStateString(state: Int): String = when (state) {
338
+ TelephonyManager.CALL_STATE_IDLE -> "CALL_STATE_IDLE"
339
+ TelephonyManager.CALL_STATE_RINGING -> "CALL_STATE_RINGING"
340
+ TelephonyManager.CALL_STATE_OFFHOOK -> "CALL_STATE_OFFHOOK"
341
+ else -> "CALL_STATE_UNKNOWN($state)"
342
+ }
343
+
149
344
  @RequiresApi(Build.VERSION_CODES.R)
150
345
  fun startRecording(options: Map<String, Any?>, promise: Promise) {
151
346
  try {
@@ -280,6 +475,11 @@ class AudioRecorderManager(
280
475
  return false
281
476
  }
282
477
 
478
+ if (!permissionUtils.checkPhoneStatePermission()) {
479
+ Log.w(Constants.TAG, "READ_PHONE_STATE permission not granted, phone call interruption handling will be disabled")
480
+ // Don't reject here, just log warning as this is optional
481
+ }
482
+
283
483
  if (options["showNotification"] as? Boolean == true && !permissionUtils.checkNotificationPermission()) {
284
484
  promise.reject(
285
485
  "NOTIFICATION_PERMISSION_DENIED",
@@ -482,6 +682,12 @@ class AudioRecorderManager(
482
682
  }
483
683
 
484
684
  recordingThread = Thread { recordingProcess() }.apply { start() }
685
+
686
+ // Start service if keepAwake is true, regardless of notification settings
687
+ if (recordingConfig.keepAwake) {
688
+ AudioRecordingService.startService(context)
689
+ }
690
+
485
691
  return true
486
692
 
487
693
  } catch (e: Exception) {
@@ -607,6 +813,11 @@ class AudioRecorderManager(
607
813
  return
608
814
  }
609
815
 
816
+ if (isOngoingCall()) {
817
+ promise.reject("ONGOING_CALL", "Cannot resume recording during an ongoing call", null)
818
+ return
819
+ }
820
+
610
821
  try {
611
822
  if (recordingConfig.showNotification) {
612
823
  notificationManager.resumeUpdates()
@@ -708,18 +919,16 @@ class AudioRecorderManager(
708
919
  }
709
920
  }
710
921
 
711
- private val wakeLockTimeout = 60 * 60 * 1000L // 1 hour timeout
712
-
713
922
  private fun acquireWakeLock() {
714
923
  if (recordingConfig.keepAwake && wakeLock == null) {
715
924
  try {
716
925
  val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager
717
926
  wakeLock = powerManager.newWakeLock(
718
- PowerManager.PARTIAL_WAKE_LOCK, // Use PARTIAL_WAKE_LOCK instead of deprecated SCREEN_DIM_WAKE_LOCK
927
+ PowerManager.PARTIAL_WAKE_LOCK,
719
928
  "AudioRecorderManager::RecordingWakeLock"
720
929
  ).apply {
721
930
  setReferenceCounted(false)
722
- acquire(wakeLockTimeout) // Add timeout
931
+ acquire()
723
932
  }
724
933
  wasWakeLockEnabled = true
725
934
  Log.d(Constants.TAG, "Wake lock acquired")
@@ -968,7 +1177,7 @@ class AudioRecorderManager(
968
1177
 
969
1178
  // Send event to notify that recording was stopped
970
1179
  eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
971
- "reason" to "appKilled",
1180
+ "reason" to "recordingStopped",
972
1181
  "isPaused" to false
973
1182
  ))
974
1183
  } catch (e: Exception) {
@@ -1012,74 +1221,6 @@ class AudioRecorderManager(
1012
1221
  }
1013
1222
  }
1014
1223
 
1015
- private fun initializePhoneStateListener() {
1016
- try {
1017
- // Check for READ_PHONE_STATE permission before initializing phone state listener
1018
- if (permissionUtils.checkPhoneStatePermission()) {
1019
- phoneStateListener = object : PhoneStateListener() {
1020
- override fun onCallStateChanged(state: Int, phoneNumber: String?) {
1021
- when (state) {
1022
- TelephonyManager.CALL_STATE_RINGING,
1023
- TelephonyManager.CALL_STATE_OFFHOOK -> {
1024
- if (isRecording.get() && !isPaused.get()) {
1025
- mainHandler.post {
1026
- pauseRecording(object : Promise {
1027
- override fun resolve(value: Any?) {
1028
- eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
1029
- "reason" to "phoneCall",
1030
- "isPaused" to true
1031
- ))
1032
- }
1033
- override fun reject(code: String, message: String?, cause: Throwable?) {
1034
- Log.e(Constants.TAG, "Failed to pause recording on phone call")
1035
- }
1036
- })
1037
- }
1038
- }
1039
- }
1040
- TelephonyManager.CALL_STATE_IDLE -> {
1041
- if (isRecording.get() && isPaused.get() && recordingConfig.autoResumeAfterInterruption) {
1042
- mainHandler.post {
1043
- resumeRecording(object : Promise {
1044
- override fun resolve(value: Any?) {
1045
- eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
1046
- "reason" to "phoneCallEnded",
1047
- "isPaused" to false
1048
- ))
1049
- }
1050
- override fun reject(code: String, message: String?, cause: Throwable?) {
1051
- Log.e(Constants.TAG, "Failed to resume recording after phone call")
1052
- }
1053
- })
1054
- }
1055
- } else if (isRecording.get() && isPaused.get()) {
1056
- // If autoResume is false, just notify that call ended but stay paused
1057
- eventSender.sendExpoEvent(Constants.RECORDING_INTERRUPTED_EVENT_NAME, bundleOf(
1058
- "reason" to "phoneCallEnded",
1059
- "isPaused" to true
1060
- ))
1061
- }
1062
- }
1063
- }
1064
- }
1065
- }
1066
-
1067
- telephonyManager = context.getSystemService(Context.TELEPHONY_SERVICE) as? TelephonyManager
1068
- if (telephonyManager != null) {
1069
- try {
1070
- telephonyManager?.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE)
1071
- } catch (e: Exception) {
1072
- Log.e(Constants.TAG, "Failed to register phone state listener", e)
1073
- }
1074
- }
1075
- } else {
1076
- Log.w(Constants.TAG, "READ_PHONE_STATE permission not granted, phone call interruption handling disabled")
1077
- }
1078
- } catch (e: Exception) {
1079
- Log.e(Constants.TAG, "Failed to initialize phone state listener", e)
1080
- }
1081
- }
1082
-
1083
1224
  @SuppressLint("NewApi")
1084
1225
  private fun requestAudioFocus(): Boolean {
1085
1226
  audioFocusChangeListener = AudioManager.OnAudioFocusChangeListener { focusChange ->
@@ -113,7 +113,10 @@ class ExpoAudioStreamModule : Module(), EventSender {
113
113
 
114
114
  AsyncFunction("requestPermissionsAsync") { promise: Promise ->
115
115
  try {
116
- val permissions = mutableListOf(Manifest.permission.RECORD_AUDIO)
116
+ val permissions = mutableListOf(
117
+ Manifest.permission.RECORD_AUDIO,
118
+ Manifest.permission.READ_PHONE_STATE
119
+ )
117
120
 
118
121
  // Add foreground service permission for Android 14+
119
122
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
@@ -134,7 +137,10 @@ class ExpoAudioStreamModule : Module(), EventSender {
134
137
  }
135
138
 
136
139
  AsyncFunction("getPermissionsAsync") { promise: Promise ->
137
- val permissions = mutableListOf(Manifest.permission.RECORD_AUDIO)
140
+ val permissions = mutableListOf(
141
+ Manifest.permission.RECORD_AUDIO,
142
+ Manifest.permission.READ_PHONE_STATE
143
+ )
138
144
 
139
145
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
140
146
  permissions.add(Manifest.permission.FOREGROUND_SERVICE_MICROPHONE)
@@ -81,7 +81,7 @@ export interface AudioSessionConfig {
81
81
  export interface IOSConfig {
82
82
  audioSession?: AudioSessionConfig;
83
83
  }
84
- export type RecordingInterruptionReason = 'audioFocusLoss' | 'audioFocusGain' | 'phoneCall' | 'phoneCallEnded';
84
+ export type RecordingInterruptionReason = 'audioFocusLoss' | 'audioFocusGain' | 'phoneCall' | 'phoneCallEnded' | 'recordingStopped';
85
85
  export interface RecordingInterruptionEvent {
86
86
  reason: RecordingInterrupt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MAAM,CAAA;IAGlB,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,cAAc;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAA;IACzB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrE,aAAa,EAAE,MAAM,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnD,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,sBAAsB,CAAC,EAAE,CAAC,CAAC,EAAE,0BAA0B,KAAK,IAAI,CAAA;CACnE"}
@@ -1 +1 @@
1
- {"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AmplitudeAlgorithm,\n AudioAnalysis,\n AudioFeaturesOptions,\n} from './AudioAnalysis/AudioAnalysis.types'\nimport { AudioAnalysisEvent } from './events'\n\nexport interface CompressionInfo {\n size: number\n mimeType: string\n bitrate: number\n format: string\n compressedFileUri?: string\n}\n\nexport interface AudioStreamStatus {\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n interval: number\n mimeType: string\n compression?: CompressionInfo\n}\n\nexport interface AudioDataEvent {\n data: string | Float32Array\n position: number\n fileUri: string\n eventDataSize: number\n totalSize: number\n compression?: CompressionInfo & {\n data?: string | Blob // Base64 (native) or Float32Array (web) encoded compressed data chunk\n }\n}\n\nexport type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit'\nexport type SampleRate = 16000 | 44100 | 48000\nexport type BitDepth = 8 | 16 | 32\n\nexport type ConsoleLike = {\n log: (message: string, ...args: unknown[]) => void\n debug: (message: string, ...args: unknown[]) => void\n warn: (message: string, ...args: unknown[]) => void\n error: (message: string, ...args: unknown[]) => void\n}\n\nexport interface Chunk {\n text: string\n timestamp: [number, number | null]\n}\n\nexport interface TranscriberData {\n id: string\n isBusy: boolean\n text: string\n startTime: number\n endTime: number\n chunks: Chunk[]\n}\n\nexport interface AudioRecording {\n fileUri: string\n filename: string\n durationMs: number\n size: number\n mimeType: string\n channels: number\n bitDepth: BitDepth\n sampleRate: SampleRate\n createdAt?: number\n transcripts?: TranscriberData[]\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n compression?: CompressionInfo & {\n compressedFileUri: string\n }\n}\n\nexport interface StartRecordingResult {\n fileUri: string\n mimeType: string\n channels?: number\n bitDepth?: BitDepth\n sampleRate?: SampleRate\n compression?: CompressionInfo & {\n compressedFileUri: string\n }\n}\n\nexport interface AudioSessionConfig {\n category?:\n | 'Ambient'\n | 'SoloAmbient'\n | 'Playback'\n | 'Record'\n | 'PlayAndRecord'\n | 'MultiRoute'\n mode?:\n | 'Default'\n | 'VoiceChat'\n | 'VideoChat'\n | 'GameChat'\n | 'VideoRecording'\n | 'Measurement'\n | 'MoviePlayback'\n | 'SpokenAudio'\n categoryOptions?: (\n | 'MixWithOthers'\n | 'DuckOthers'\n | 'InterruptSpokenAudioAndMixWithOthers'\n | 'AllowBluetooth'\n | 'AllowBluetoothA2DP'\n | 'AllowAirPlay'\n | 'DefaultToSpeaker'\n )[]\n}\n\nexport interface IOSConfig {\n audioSession?: AudioSessionConfig\n}\n\n// Add new type for interruption reasons\nexport type RecordingInterruptionReason =\n | 'audioFocusLoss'\n | 'audioFocusGain'\n | 'phoneCall'\n | 'phoneCallEnded'\n\n// Add new interface for interruption events\nexport interface RecordingInterruptionEvent {\n reason: RecordingInterruptionReason\n isPaused: boolean\n}\n\nexport interface RecordingConfig {\n // Sample rate for recording (16000, 44100, or 48000 Hz)\n sampleRate?: SampleRate\n\n // Number of audio channels (1 for mono, 2 for stereo)\n channels?: 1 | 2\n\n // Encoding type for the recording (pcm_32bit, pcm_16bit, pcm_8bit)\n encoding?: EncodingType\n\n // Interval in milliseconds at which to emit recording data\n interval?: number\n\n // Continue recording when app is in background (default is true)\n keepAwake?: boolean\n\n // Show a notification during recording (default is false)\n showNotification?: boolean\n\n // Show waveform in the notification (Android only, when showNotification is true)\n showWaveformInNotification?: boolean\n\n // Configuration for the notification\n notification?: NotificationConfig\n\n // Enable audio processing (default is false)\n enableProcessing?: boolean\n\n // iOS-specific configuration\n ios?: IOSConfig\n\n // Number of data points to extract per second of audio (default is 1000)\n pointsPerSecond?: number\n\n // Algorithm to use for amplitude computation (default is \"rms\")\n algorithm?: AmplitudeAlgorithm\n\n // Feature options to extract (default is empty)\n features?: AudioFeaturesOptions\n\n // Callback function to handle audio stream\n onAudioStream?: (_: AudioDataEvent) => Promise<void>\n\n // Callback function to handle audio features extraction results\n onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>\n\n compression?: {\n enabled: boolean\n format: 'aac' | 'opus' | 'mp3'\n bitrate?: number\n }\n\n // Whether to automatically resume recording after an interruption (default is false)\n autoResumeAfterInterruption?: boolean\n\n // Optional callback to handle recording interruptions\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n\n // Optional output configuration\n outputDirectory?: string // If not provided, uses default app directory\n filename?: string // If not provided, uses UUID\n}\n\nexport interface NotificationConfig {\n // Title of the notification\n title?: string\n\n // Main text content of the notification\n text?: string\n\n // Icon to be displayed in the notification (resource name or URI)\n icon?: string\n\n // Android-specific notification configuration\n android?: {\n // Unique identifier for the notification channel\n channelId?: string\n\n // User-visible name of the notification channel\n channelName?: string\n\n // User-visible description of the notification channel\n channelDescription?: string\n\n // Unique identifier for this notification\n notificationId?: number\n\n // List of actions that can be performed from the notification\n actions?: NotificationAction[]\n\n // Configuration for the waveform visualization in the notification\n waveform?: WaveformConfig\n\n // Color of the notification LED (if device supports it)\n lightColor?: string\n\n // Priority of the notification (affects how it's displayed)\n priority?: 'min' | 'low' | 'default' | 'high' | 'max'\n\n // Accent color for the notification (used for the app icon and buttons)\n accentColor?: string\n }\n\n // iOS-specific notification configuration\n ios?: {\n // Identifier for the notification category (used for grouping similar notifications)\n categoryIdentifier?: string\n }\n}\n\nexport interface NotificationAction {\n // Display title for the action\n title: string\n\n // Unique identifier for the action\n identifier: string\n\n // Icon to be displayed for the action (Android only)\n icon?: string\n}\n\nexport interface WaveformConfig {\n color?: string // The color of the waveform (e.g., \"#FFFFFF\" for white)\n opacity?: number // Opacity of the waveform (0.0 - 1.0)\n strokeWidth?: number // Width of the waveform line (default: 1.5)\n style?: 'stroke' | 'fill' // Drawing style: \"stroke\" for outline, \"fill\" for solid\n mirror?: boolean // Whether to mirror the waveform (symmetrical display)\n height?: number // Height of the waveform view in dp (default: 64)\n}\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n stopRecording: () => Promise<AudioRecording | null>\n pauseRecording: () => Promise<void>\n resumeRecording: () => Promise<void>\n isRecording: boolean\n isPaused: boolean\n durationMs: number // Duration of the recording\n size: number // Size in bytes of the recorded audio\n compression?: CompressionInfo\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n}\n"]}
1
+ {"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AmplitudeAlgorithm,\n AudioAnalysis,\n AudioFeaturesOptions,\n} from './AudioAnalysis/AudioAnalysis.types'\nimport { AudioAnalysisEvent } from './events'\n\nexport interface CompressionInfo {\n size: number\n mimeType: string\n bitrate: number\n format: string\n compressedFileUri?: string\n}\n\nexport interface AudioStreamStatus {\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n interval: number\n mimeType: string\n compression?: CompressionInfo\n}\n\nexport interface AudioDataEvent {\n data: string | Float32Array\n position: number\n fileUri: string\n eventDataSize: number\n totalSize: number\n compression?: CompressionInfo & {\n data?: string | Blob // Base64 (native) or Float32Array (web) encoded compressed data chunk\n }\n}\n\nexport type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit'\nexport type SampleRate = 16000 | 44100 | 48000\nexport type BitDepth = 8 | 16 | 32\n\nexport type ConsoleLike = {\n log: (message: string, ...args: unknown[]) => void\n debug: (message: string, ...args: unknown[]) => void\n warn: (message: string, ...args: unknown[]) => void\n error: (message: string, ...args: unknown[]) => void\n}\n\nexport interface Chunk {\n text: string\n timestamp: [number, number | null]\n}\n\nexport interface TranscriberData {\n id: string\n isBusy: boolean\n text: string\n startTime: number\n endTime: number\n chunks: Chunk[]\n}\n\nexport interface AudioRecording {\n fileUri: string\n filename: string\n durationMs: number\n size: number\n mimeType: string\n channels: number\n bitDepth: BitDepth\n sampleRate: SampleRate\n createdAt?: number\n transcripts?: TranscriberData[]\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n compression?: CompressionInfo & {\n compressedFileUri: string\n }\n}\n\nexport interface StartRecordingResult {\n fileUri: string\n mimeType: string\n channels?: number\n bitDepth?: BitDepth\n sampleRate?: SampleRate\n compression?: CompressionInfo & {\n compressedFileUri: string\n }\n}\n\nexport interface AudioSessionConfig {\n category?:\n | 'Ambient'\n | 'SoloAmbient'\n | 'Playback'\n | 'Record'\n | 'PlayAndRecord'\n | 'MultiRoute'\n mode?:\n | 'Default'\n | 'VoiceChat'\n | 'VideoChat'\n | 'GameChat'\n | 'VideoRecording'\n | 'Measurement'\n | 'MoviePlayback'\n | 'SpokenAudio'\n categoryOptions?: (\n | 'MixWithOthers'\n | 'DuckOthers'\n | 'InterruptSpokenAudioAndMixWithOthers'\n | 'AllowBluetooth'\n | 'AllowBluetoothA2DP'\n | 'AllowAirPlay'\n | 'DefaultToSpeaker'\n )[]\n}\n\nexport interface IOSConfig {\n audioSession?: AudioSessionConfig\n}\n\n// Add new type for interruption reasons\nexport type RecordingInterruptionReason =\n | 'audioFocusLoss'\n | 'audioFocusGain'\n | 'phoneCall'\n | 'phoneCallEnded'\n | 'recordingStopped'\n\n// Add new interface for interruption events\nexport interface RecordingInterruptionEvent {\n reason: RecordingInterruptionReason\n isPaused: boolean\n}\n\nexport interface RecordingConfig {\n // Sample rate for recording (16000, 44100, or 48000 Hz)\n sampleRate?: SampleRate\n\n // Number of audio channels (1 for mono, 2 for stereo)\n channels?: 1 | 2\n\n // Encoding type for the recording (pcm_32bit, pcm_16bit, pcm_8bit)\n encoding?: EncodingType\n\n // Interval in milliseconds at which to emit recording data\n interval?: number\n\n // Continue recording when app is in background (default is true)\n keepAwake?: boolean\n\n // Show a notification during recording (default is false)\n showNotification?: boolean\n\n // Show waveform in the notification (Android only, when showNotification is true)\n showWaveformInNotification?: boolean\n\n // Configuration for the notification\n notification?: NotificationConfig\n\n // Enable audio processing (default is false)\n enableProcessing?: boolean\n\n // iOS-specific configuration\n ios?: IOSConfig\n\n // Number of data points to extract per second of audio (default is 1000)\n pointsPerSecond?: number\n\n // Algorithm to use for amplitude computation (default is \"rms\")\n algorithm?: AmplitudeAlgorithm\n\n // Feature options to extract (default is empty)\n features?: AudioFeaturesOptions\n\n // Callback function to handle audio stream\n onAudioStream?: (_: AudioDataEvent) => Promise<void>\n\n // Callback function to handle audio features extraction results\n onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>\n\n compression?: {\n enabled: boolean\n format: 'aac' | 'opus' | 'mp3'\n bitrate?: number\n }\n\n // Whether to automatically resume recording after an interruption (default is false)\n autoResumeAfterInterruption?: boolean\n\n // Optional callback to handle recording interruptions\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n\n // Optional output configuration\n outputDirectory?: string // If not provided, uses default app directory\n filename?: string // If not provided, uses UUID\n}\n\nexport interface NotificationConfig {\n // Title of the notification\n title?: string\n\n // Main text content of the notification\n text?: string\n\n // Icon to be displayed in the notification (resource name or URI)\n icon?: string\n\n // Android-specific notification configuration\n android?: {\n // Unique identifier for the notification channel\n channelId?: string\n\n // User-visible name of the notification channel\n channelName?: string\n\n // User-visible description of the notification channel\n channelDescription?: string\n\n // Unique identifier for this notification\n notificationId?: number\n\n // List of actions that can be performed from the notification\n actions?: NotificationAction[]\n\n // Configuration for the waveform visualization in the notification\n waveform?: WaveformConfig\n\n // Color of the notification LED (if device supports it)\n lightColor?: string\n\n // Priority of the notification (affects how it's displayed)\n priority?: 'min' | 'low' | 'default' | 'high' | 'max'\n\n // Accent color for the notification (used for the app icon and buttons)\n accentColor?: string\n }\n\n // iOS-specific notification configuration\n ios?: {\n // Identifier for the notification category (used for grouping similar notifications)\n categoryIdentifier?: string\n }\n}\n\nexport interface NotificationAction {\n // Display title for the action\n title: string\n\n // Unique identifier for the action\n identifier: string\n\n // Icon to be displayed for the action (Android only)\n icon?: string\n}\n\nexport interface WaveformConfig {\n color?: string // The color of the waveform (e.g., \"#FFFFFF\" for white)\n opacity?: number // Opacity of the waveform (0.0 - 1.0)\n strokeWidth?: number // Width of the waveform line (default: 1.5)\n style?: 'stroke' | 'fill' // Drawing style: \"stroke\" for outline, \"fill\" for solid\n mirror?: boolean // Whether to mirror the waveform (symmetrical display)\n height?: number // Height of the waveform view in dp (default: 64)\n}\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n stopRecording: () => Promise<AudioRecording | null>\n pauseRecording: () => Promise<void>\n resumeRecording: () => Promise<void>\n isRecording: boolean\n isPaused: boolean\n durationMs: number // Duration of the recording\n size: number // Size in bytes of the recorded audio\n compression?: CompressionInfo\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n}\n"]}
package/build/events.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { type EventSubscription } from 'expo-modules-core';
2
2
  import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
3
+ import { RecordingInterruptionEvent } from './ExpoAudioStream.types';
3
4
  export interface AudioEventPayload {
4
5
  encoded?: string;
5
6
  buffer?: Float32Array;
@@ -21,4 +22,5 @@ export declare function addAudioEventListener(listener: (event: AudioEventPayloa
21
22
  export interface AudioAnalysisEvent extends AudioAnalysis {
22
23
  }
23
24
  export declare function addAudioAnalysisListener(listener: (event: AudioAnalysisEvent) => Promise<void>): EventSubscription;
25
+ export declare function addRecordingInterruptionListener(listener: (event: RecordingInterruptionEvent) => void): EventSubscription;
24
26
  //# sourceMappingURL=events.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAEA,OAAO,EAAsB,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAMnE,MAAM,WAAW,iBAAiB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,CAAC,EAAE;QACV,IAAI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OAAO,CAAC,IAAI,CAAC,GACtD,iBAAiB,CAEnB;AAGD,MAAM,WAAW,kBAAmB,SAAQ,aAAa;CAAG;AAE5D,wBAAgB,wBAAwB,CACpC,QAAQ,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,GACvD,iBAAiB,CAEnB;AAED,wBAAgB,gCAAgC,CAC5C,QAAQ,EAAE,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GACtD,iBAAiB,CAanB"}
package/build/events.js CHANGED
@@ -8,4 +8,14 @@ export function addAudioEventListener(listener) {
8
8
  export function addAudioAnalysisListener(listener) {
9
9
  return emitter.addListener('AudioAnalysis', listener);
10
10
  }
11
+ export function addRecordingInterruptionListener(listener) {
12
+ // Add debug logging
13
+ console.debug('Adding recording interruption listener');
14
+ const subscription = emitter.addListener('onRecordingInterrupted', // Make sure this matches the native event name
15
+ (event) => {
16
+ console.debug('Recording interruption event received:', event);
17
+ listener(event);
18
+ });
19
+ return subscription;
20
+ }
11
21
  //# sourceMappingURL=events.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,kBAAkB,EAA0B,MAAM,mBAAmB,CAAA;AAG9E,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;AAqB7D,MAAM,UAAU,qBAAqB,CACjC,QAAqD;IAErD,OAAO,OAAO,CAAC,WAAW,CAAoB,WAAW,EAAE,QAAQ,CAAC,CAAA;AACxE,CAAC;AAKD,MAAM,UAAU,wBAAwB,CACpC,QAAsD;IAEtD,OAAO,OAAO,CAAC,WAAW,CAAqB,eAAe,EAAE,QAAQ,CAAC,CAAA;AAC7E,CAAC","sourcesContent":["// packages/expo-audio-stream/src/events.ts\n\nimport { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\n\nconst emitter = new LegacyEventEmitter(ExpoAudioStreamModule)\n\n// Internal event payload from native module\nexport interface AudioEventPayload {\n encoded?: string\n buffer?: Float32Array\n fileUri: string\n lastEmittedSize: number\n position: number\n deltaSize: number\n totalSize: number\n mimeType: string\n streamUuid: string\n compression?: {\n data?: string | Blob // Base64 (native) or Float32Array (web) encoded compressed data chunk\n position: number\n eventDataSize: number\n totalSize: number\n }\n}\n\nexport function addAudioEventListener(\n listener: (event: AudioEventPayload) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioEventPayload>('AudioData', listener)\n}\n\n// Only aliasing the AudioAnalysis type for the event payload\nexport interface AudioAnalysisEvent extends AudioAnalysis {}\n\nexport function addAudioAnalysisListener(\n listener: (event: AudioAnalysisEvent) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioAnalysisEvent>('AudioAnalysis', listener)\n}\n"]}
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,kBAAkB,EAA0B,MAAM,mBAAmB,CAAA;AAI9E,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;AAqB7D,MAAM,UAAU,qBAAqB,CACjC,QAAqD;IAErD,OAAO,OAAO,CAAC,WAAW,CAAoB,WAAW,EAAE,QAAQ,CAAC,CAAA;AACxE,CAAC;AAKD,MAAM,UAAU,wBAAwB,CACpC,QAAsD;IAEtD,OAAO,OAAO,CAAC,WAAW,CAAqB,eAAe,EAAE,QAAQ,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC5C,QAAqD;IAErD,oBAAoB;IACpB,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAEvD,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CACpC,wBAAwB,EAAE,+CAA+C;IACzE,CAAC,KAAK,EAAE,EAAE;QACN,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC9D,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC,CACJ,CAAA;IAED,OAAO,YAAY,CAAA;AACvB,CAAC","sourcesContent":["// packages/expo-audio-stream/src/events.ts\n\nimport { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport { RecordingInterruptionEvent } from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\n\nconst emitter = new LegacyEventEmitter(ExpoAudioStreamModule)\n\n// Internal event payload from native module\nexport interface AudioEventPayload {\n encoded?: string\n buffer?: Float32Array\n fileUri: string\n lastEmittedSize: number\n position: number\n deltaSize: number\n totalSize: number\n mimeType: string\n streamUuid: string\n compression?: {\n data?: string | Blob // Base64 (native) or Float32Array (web) encoded compressed data chunk\n position: number\n eventDataSize: number\n totalSize: number\n }\n}\n\nexport function addAudioEventListener(\n listener: (event: AudioEventPayload) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioEventPayload>('AudioData', listener)\n}\n\n// Only aliasing the AudioAnalysis type for the event payload\nexport interface AudioAnalysisEvent extends AudioAnalysis {}\n\nexport function addAudioAnalysisListener(\n listener: (event: AudioAnalysisEvent) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioAnalysisEvent>('AudioAnalysis', listener)\n}\n\nexport function addRecordingInterruptionListener(\n listener: (event: RecordingInterruptionEvent) => void\n): EventSubscription {\n // Add debug logging\n console.debug('Adding recording interruption listener')\n\n const subscription = emitter.addListener<RecordingInterruptionEvent>(\n 'onRecordingInterrupted', // Make sure this matches the native event name\n (event) => {\n console.debug('Recording interruption event received:', event)\n listener(event)\n }\n )\n\n return subscription\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useAudioRecorder.d.ts","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAEH,cAAc,EAEd,eAAe,EACf,WAAW,EACX,eAAe,EACf,oBAAoB,EACvB,MAAM,yBAAyB,CAAA;AAQhC,MAAM,WAAW,qBAAqB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrE,aAAa,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5C,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B;AAgHD,wBAAgB,gBAAgB,CAAC,EAC7B,MAAM,EACN,eAAe,EACf,mBAAmB,GACtB,GAAE,qBAA0B,GAAG,qBAAqB,CAqapD"}
1
+ {"version":3,"file":"useAudioRecorder.d.ts","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAEH,cAAc,EAEd,eAAe,EACf,WAAW,EACX,eAAe,EACf,oBAAoB,EACvB,MAAM,yBAAyB,CAAA;AAShC,MAAM,WAAW,qBAAqB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrE,aAAa,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5C,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B;AAgHD,wBAAgB,gBAAgB,CAAC,EAC7B,MAAM,EACN,eAAe,EACf,mBAAmB,GACtB,GAAE,qBAA0B,GAAG,qBAAqB,CA4cpD"}
@@ -2,7 +2,7 @@
2
2
  import { Platform } from 'expo-modules-core';
3
3
  import { useCallback, useEffect, useReducer, useRef } from 'react';
4
4
  import ExpoAudioStreamModule from './ExpoAudioStreamModule';
5
- import { addAudioAnalysisListener, addAudioEventListener, } from './events';
5
+ import { addAudioAnalysisListener, addAudioEventListener, addRecordingInterruptionListener, } from './events';
6
6
  const defaultAnalysis = {
7
7
  pointsPerSecond: 10,
8
8
  bitDepth: 32,
@@ -108,6 +108,7 @@ export function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl,
108
108
  size: 0,
109
109
  compression: undefined,
110
110
  });
111
+ const recordingConfigRef = useRef(null);
111
112
  const handleAudioAnalysis = useCallback(async ({ analysis, visualizationDuration, }) => {
112
113
  const savedAnalysisData = analysisRef.current || {
113
114
  ...defaultAnalysis,
@@ -155,10 +156,18 @@ export function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl,
155
156
  max: newMax,
156
157
  };
157
158
  logger?.debug(`[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`, savedAnalysisData);
159
+ // Call the onAudioAnalysis callback if it exists in the recording config
160
+ if (recordingConfigRef.current?.onAudioAnalysis) {
161
+ try {
162
+ await recordingConfigRef.current.onAudioAnalysis(analysis);
163
+ }
164
+ catch (error) {
165
+ logger?.error('Error in onAudioAnalysis callback:', error);
166
+ }
167
+ }
158
168
  // Update the ref
159
169
  analysisRef.current = savedAnalysisData;
160
170
  // Dispatch the updated analysis data to state to trigger re-render
161
- // need to use spread operator otherwise it doesnt trigger update.
162
171
  dispatch({
163
172
  type: 'UPDATE_ANALYSIS',
164
173
  payload: { ...savedAnalysisData },
@@ -291,6 +300,7 @@ export function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl,
291
300
  state.compression,
292
301
  ]);
293
302
  const startRecording = useCallback(async (recordingOptions) => {
303
+ recordingConfigRef.current = recordingOptions;
294
304
  logger?.debug(`start recoding`, recordingOptions);
295
305
  analysisRef.current = { ...defaultAnalysis }; // Reset analysis data
296
306
  fullAnalysisRef.current = { ...defaultAnalysis };
@@ -375,6 +385,29 @@ export function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl,
375
385
  subscribeAudio.remove();
376
386
  };
377
387
  }, [handleAudioEvent, handleAudioAnalysis]);
388
+ useEffect(() => {
389
+ // Add event subscription for recording interruptions
390
+ logger?.debug('Setting up recording interruption listener');
391
+ const subscription = addRecordingInterruptionListener((event) => {
392
+ logger?.debug('Received recording interruption event:', event);
393
+ // Check if we have a callback configured
394
+ if (recordingConfigRef.current?.onRecordingInterrupted) {
395
+ try {
396
+ recordingConfigRef.current.onRecordingInterrupted(event);
397
+ }
398
+ catch (error) {
399
+ logger?.error('Error in recording interruption callback:', error);
400
+ }
401
+ }
402
+ else {
403
+ logger?.warn('No recording interruption callback configured');
404
+ }
405
+ });
406
+ return () => {
407
+ logger?.debug('Removing recording interruption listener');
408
+ subscription.remove();
409
+ };
410
+ }, []); // Empty dependency array since we want this to run once
378
411
  return {
379
412
  startRecording,
380
413
  stopRecording,
@@ -1 +1 @@
1
- {"version":3,"file":"useAudioRecorder.js","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAqB,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAYlE,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EACH,wBAAwB,EACxB,qBAAqB,GAExB,MAAM,UAAU,CAAA;AAiDjB,MAAM,eAAe,GAAkB;IACnC,eAAe,EAAE,EAAE;IACnB,QAAQ,EAAE,EAAE;IACZ,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,KAAK;IACjB,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,EAAE;IACd,kBAAkB,EAAE,KAAK;IACzB,cAAc,EAAE,EAAE;IAClB,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC,iBAAiB;QAC7B,GAAG,EAAE,MAAM,CAAC,iBAAiB;KAChC;CACJ,CAAA;AAED,SAAS,oBAAoB,CACzB,KAA2B,EAC3B,MAAsB;IAEtB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QAClB,KAAK,OAAO;YACR,OAAO;gBACH,GAAG,KAAK;gBACR,WAAW,EAAE,IAAI;gBACjB,QAAQ,EAAE,KAAK;gBACf,UAAU,EAAE,CAAC;gBACb,IAAI,EAAE,CAAC;gBACP,WAAW,EAAE,SAAS;gBACtB,YAAY,EAAE,eAAe;aAChC,CAAA;QACL,KAAK,MAAM;YACP,OAAO;gBACH,GAAG,KAAK;gBACR,WAAW,EAAE,KAAK;gBAClB,QAAQ,EAAE,KAAK;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CAAC,WAAW;QAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;KACnC,CAAA;AACL,CAAC","sourcesContent":["// src/useAudioRecorder.ts\nimport { EventSubscription, Platform } from 'expo-modules-core'\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioDataEvent,\n AudioRecording,\n AudioStreamStatus,\n CompressionInfo,\n ConsoleLike,\n RecordingConfig,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\nimport {\n addAudioAnalysisListener,\n addAudioEventListener,\n AudioEventPayload,\n} from './events'\n\nexport interface UseAudioRecorderProps {\n logger?: ConsoleLike\n audioWorkletUrl?: string\n featuresExtratorUrl?: string\n}\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n stopRecording: () => Promise<AudioRecording>\n pauseRecording: () => Promise<void>\n resumeRecording: () => Promise<void>\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ninterface RecorderReducerState {\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ntype RecorderAction =\n | { type: 'START' | 'STOP' | 'PAUSE' | 'RESUME' }\n | {\n type: 'UPDATE_RECORDING_STATE'\n payload: {\n isRecording: boolean\n isPaused: boolean\n }\n }\n | {\n type: 'UPDATE_STATUS'\n payload: {\n durationMs: number\n size: number\n compression?: CompressionInfo\n }\n }\n | { type: 'UPDATE_ANALYSIS'; payload: AudioAnalysis }\n\nconst defaultAnalysis: AudioAnalysis = {\n pointsPerSecond: 10,\n bitDepth: 32,\n numberOfChannels: 1,\n durationMs: 0,\n sampleRate: 44100,\n samples: 0,\n dataPoints: [],\n amplitudeAlgorithm: 'rms',\n speakerChanges: [],\n amplitudeRange: {\n min: Number.POSITIVE_INFINITY,\n max: Number.NEGATIVE_INFINITY,\n },\n}\n\nfunction audioRecorderReducer(\n state: RecorderReducerState,\n action: RecorderAction\n): RecorderReducerState {\n switch (action.type) {\n case 'START':\n return {\n ...state,\n isRecording: true,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: defaultAnalysis,\n }\n case 'STOP':\n return {\n ...state,\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n }\n case 'PAUSE':\n return { ...state, isPaused: true, isRecording: false }\n case 'RESUME':\n return { ...state, isPaused: false, isRecording: true }\n case 'UPDATE_RECORDING_STATE':\n return {\n ...state,\n isPaused: action.payload.isPaused,\n isRecording: action.payload.isRecording,\n }\n case 'UPDATE_STATUS': {\n const newState = {\n ...state,\n durationMs: action.payload.durationMs,\n size: action.payload.size,\n compression: action.payload.compression\n ? {\n size: action.payload.compression.size,\n mimeType: action.payload.compression.mimeType,\n bitrate: action.payload.compression.bitrate,\n format: action.payload.compression.format,\n }\n : undefined,\n }\n return newState\n }\n case 'UPDATE_ANALYSIS':\n return {\n ...state,\n analysisData: action.payload,\n }\n default:\n return state\n }\n}\n\ninterface HandleAudioAnalysisProps {\n analysis: AudioAnalysis\n visualizationDuration: number\n}\n\nexport function useAudioRecorder({\n logger,\n audioWorkletUrl,\n featuresExtratorUrl,\n}: UseAudioRecorderProps = {}): UseAudioRecorderState {\n const [state, dispatch] = useReducer(audioRecorderReducer, {\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n })\n\n const startResultRef = useRef<StartRecordingResult | null>(null)\n\n const analysisListenerRef = useRef<EventSubscription | null>(null)\n // analysisRef is the current analysis data (last 10 seconds by default)\n const analysisRef = useRef<AudioAnalysis>({ ...defaultAnalysis })\n // fullAnalysisRef is the full analysis data (all data points)\n const fullAnalysisRef = useRef<AudioAnalysis>({\n ...defaultAnalysis,\n })\n\n // Instantiate the module for web with URLs\n const ExpoAudioStream =\n Platform.OS === 'web'\n ? ExpoAudioStreamModule({\n audioWorkletUrl,\n featuresExtratorUrl,\n logger,\n })\n : ExpoAudioStreamModule\n\n const onAudioStreamRef = useRef<\n ((_: AudioDataEvent) => Promise<void>) | null\n >(null)\n\n const stateRef = useRef({\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined as CompressionInfo | undefined,\n })\n\n const handleAudioAnalysis = useCallback(\n async ({\n analysis,\n visualizationDuration,\n }: HandleAudioAnalysisProps) => {\n const savedAnalysisData = analysisRef.current || {\n ...defaultAnalysis,\n }\n\n const maxDuration = visualizationDuration\n\n logger?.debug(\n `[handleAudioAnalysis] Received audio analysis: maxDuration=${maxDuration} analysis.dataPoints=${analysis.dataPoints.length} analysisData.dataPoints=${savedAnalysisData.dataPoints.length}`,\n analysis\n )\n\n // Combine data points\n const combinedDataPoints = [\n ...savedAnalysisData.dataPoints,\n ...analysis.dataPoints,\n ]\n\n const fullCombinedDataPoints = [\n ...(fullAnalysisRef.current?.dataPoints ?? []),\n ...analysis.dataPoints,\n ]\n\n // Calculate the new duration\n const pointsPerSecond =\n analysis.pointsPerSecond || savedAnalysisData.pointsPerSecond\n const maxDataPoints =\n (pointsPerSecond * visualizationDuration) / 1000\n\n logger?.debug(\n `[handleAudioAnalysis] Combined data points before trimming: pointsPerSecond=${pointsPerSecond} visualizationDuration=${visualizationDuration} combinedDataPointsLength=${combinedDataPoints.length} vs maxDataPoints=${maxDataPoints}`\n )\n\n // Trim data points to keep within the maximum number of data points\n if (combinedDataPoints.length > maxDataPoints) {\n combinedDataPoints.splice(\n 0,\n combinedDataPoints.length - maxDataPoints\n )\n }\n\n // Keep the full data points\n fullAnalysisRef.current = {\n ...fullAnalysisRef.current,\n dataPoints: fullCombinedDataPoints,\n }\n fullAnalysisRef.current.durationMs =\n fullCombinedDataPoints.length * (1000 / pointsPerSecond)\n savedAnalysisData.dataPoints = combinedDataPoints\n savedAnalysisData.bitDepth =\n analysis.bitDepth || savedAnalysisData.bitDepth\n savedAnalysisData.durationMs =\n combinedDataPoints.length * (1000 / pointsPerSecond)\n\n // Update amplitude range\n const newMin = Math.min(\n savedAnalysisData.amplitudeRange.min,\n analysis.amplitudeRange.min\n )\n const newMax = Math.max(\n savedAnalysisData.amplitudeRange.max,\n analysis.amplitudeRange.max\n )\n\n savedAnalysisData.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n fullAnalysisRef.current.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n\n logger?.debug(\n `[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`,\n savedAnalysisData\n )\n\n // Update the ref\n analysisRef.current = savedAnalysisData\n\n // Dispatch the updated analysis data to state to trigger re-render\n // need to use spread operator otherwise it doesnt trigger update.\n dispatch({\n type: 'UPDATE_ANALYSIS',\n payload: { ...savedAnalysisData },\n })\n },\n [dispatch]\n )\n\n const handleAudioEvent = useCallback(\n async (eventData: AudioEventPayload) => {\n const {\n fileUri,\n deltaSize,\n totalSize,\n lastEmittedSize,\n position,\n streamUuid,\n encoded,\n mimeType,\n buffer,\n compression,\n } = eventData\n logger?.debug(`[handleAudioEvent] Received audio event:`, {\n fileUri,\n deltaSize,\n totalSize,\n position,\n mimeType,\n lastEmittedSize,\n streamUuid,\n encodedLength: encoded?.length,\n compression,\n })\n if (deltaSize === 0) {\n // Ignore packet with no data\n return\n }\n try {\n // Coming from native ( ios / android ) otherwise buffer is set\n if (Platform.OS !== 'web') {\n // Read the audio file as a base64 string for comparison\n if (!encoded) {\n logger?.error(`Encoded audio data is missing`)\n throw new Error('Encoded audio data is missing')\n }\n onAudioStreamRef.current?.({\n data: encoded,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n })\n } else if (buffer) {\n // Coming from web\n const webEvent: AudioDataEvent = {\n data: buffer,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n }\n onAudioStreamRef.current?.(webEvent)\n logger?.debug(\n `[handleAudioEvent] Audio data sent to onAudioStream`,\n webEvent\n )\n }\n } catch (error) {\n logger?.error(`Error processing audio event:`, error)\n }\n },\n []\n )\n\n const checkStatus = useCallback(async () => {\n try {\n const status: AudioStreamStatus = ExpoAudioStream.status()\n logger?.debug(\n `Status: paused: ${status.isPaused} isRecording: ${status.isRecording} durationMs: ${status.durationMs} size: ${status.size}`,\n status.compression\n )\n\n // Only dispatch if values actually changed\n if (\n status.isRecording !== stateRef.current.isRecording ||\n status.isPaused !== stateRef.current.isPaused\n ) {\n stateRef.current.isRecording = status.isRecording\n stateRef.current.isPaused = status.isPaused\n dispatch({\n type: 'UPDATE_RECORDING_STATE',\n payload: {\n isRecording: status.isRecording,\n isPaused: status.isPaused,\n },\n })\n }\n\n if (\n status.durationMs !== stateRef.current.durationMs ||\n status.size !== stateRef.current.size\n ) {\n stateRef.current.durationMs = status.durationMs\n stateRef.current.size = status.size\n stateRef.current.compression = status.compression\n dispatch({\n type: 'UPDATE_STATUS',\n payload: {\n durationMs: status.durationMs,\n size: status.size,\n compression: status.compression,\n },\n })\n }\n } catch (error) {\n logger?.error(`Error getting status:`, error)\n }\n }, [ExpoAudioStream, logger]) // Only depend on ExpoAudioStream and logger\n\n // Update ref when state changes\n useEffect(() => {\n stateRef.current = {\n isRecording: state.isRecording,\n isPaused: state.isPaused,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n }\n }, [\n state.isRecording,\n state.isPaused,\n state.durationMs,\n state.size,\n state.compression,\n ])\n\n const startRecording = useCallback(\n async (recordingOptions: RecordingConfig) => {\n logger?.debug(`start recoding`, recordingOptions)\n\n analysisRef.current = { ...defaultAnalysis } // Reset analysis data\n fullAnalysisRef.current = { ...defaultAnalysis }\n const { onAudioStream, ...options } = recordingOptions\n const { enableProcessing } = options\n\n const maxRecentDataDuration = 10000 // TODO compute maxRecentDataDuration based on screen dimensions\n if (typeof onAudioStream === 'function') {\n onAudioStreamRef.current = onAudioStream\n } else {\n logger?.warn(`onAudioStream is not a function`, onAudioStream)\n onAudioStreamRef.current = null\n }\n const startResult: StartRecordingResult =\n await ExpoAudioStream.startRecording(options)\n dispatch({ type: 'START' })\n\n startResultRef.current = startResult\n\n if (enableProcessing) {\n logger?.debug(`Enabling audio analysis listener`)\n const listener = addAudioAnalysisListener(\n async (analysisData) => {\n try {\n await handleAudioAnalysis({\n analysis: analysisData,\n visualizationDuration: maxRecentDataDuration,\n })\n } catch (error) {\n logger?.warn(\n `Error processing audio analysis:`,\n error\n )\n }\n }\n )\n\n analysisListenerRef.current = listener\n }\n\n return startResult\n },\n [handleAudioAnalysis, dispatch]\n )\n\n const stopRecording = useCallback(async () => {\n logger?.debug(`stoping recording`)\n\n const stopResult: AudioRecording = await ExpoAudioStream.stopRecording()\n stopResult.analysisData = fullAnalysisRef.current\n\n if (analysisListenerRef.current) {\n analysisListenerRef.current.remove()\n analysisListenerRef.current = null\n }\n onAudioStreamRef.current = null\n logger?.debug(`recording stopped`, stopResult)\n dispatch({ type: 'STOP' })\n return stopResult\n }, [dispatch])\n\n const pauseRecording = useCallback(async () => {\n logger?.debug(`pause recording`)\n const pauseResult = await ExpoAudioStream.pauseRecording()\n dispatch({ type: 'PAUSE' })\n return pauseResult\n }, [dispatch])\n\n const resumeRecording = useCallback(async () => {\n logger?.debug(`resume recording`)\n const resumeResult = await ExpoAudioStream.resumeRecording()\n dispatch({ type: 'RESUME' })\n return resumeResult\n }, [dispatch])\n\n useEffect(() => {\n let intervalId: NodeJS.Timeout | undefined\n\n if (state.isRecording || state.isPaused) {\n // Immediately check status when starting\n checkStatus()\n\n // Start interval\n intervalId = setInterval(checkStatus, 1000)\n }\n\n return () => {\n if (intervalId) {\n clearInterval(intervalId)\n intervalId = undefined\n }\n }\n }, [checkStatus, state.isRecording, state.isPaused])\n\n useEffect(() => {\n logger?.debug(`Registering audio event listener`)\n const subscribeAudio = addAudioEventListener(handleAudioEvent)\n\n logger?.debug(\n `Subscribed to audio event listener and analysis listener`,\n {\n subscribeAudio,\n }\n )\n\n return () => {\n logger?.debug(`Removing audio event listener`)\n subscribeAudio.remove()\n }\n }, [handleAudioEvent, handleAudioAnalysis])\n\n return {\n startRecording,\n stopRecording,\n pauseRecording,\n resumeRecording,\n isPaused: state.isPaused,\n isRecording: state.isRecording,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n analysisData: state.analysisData,\n }\n}\n"]}
1
+ {"version":3,"file":"useAudioRecorder.js","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAqB,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAYlE,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EACH,wBAAwB,EACxB,qBAAqB,EAErB,gCAAgC,GACnC,MAAM,UAAU,CAAA;AAiDjB,MAAM,eAAe,GAAkB;IACnC,eAAe,EAAE,EAAE;IACnB,QAAQ,EAAE,EAAE;IACZ,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,KAAK;IACjB,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,EAAE;IACd,kBAA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,CAAC;oBACb,MAAM,EAAE,KAAK,CACT,2CAA2C,EAC3C,KAAK,CACR,CAAA;gBACL,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,MAAM,EAAE,IAAI,CAAC,+CAA+C,CAAC,CAAA;YACjE,CAAC;QACL,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,EAAE;YACR,MAAM,EAAE,KAAK,CAAC,0CAA0C,CAAC,CAAA;YACzD,YAAY,CAAC,MAAM,EAAE,CAAA;QACzB,CAAC,CAAA;IACL,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,wDAAwD;IAE/D,OAAO;QACH,cAAc;QACd,aAAa;QACb,cAAc;QACd,eAAe;QACf,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;KACnC,CAAA;AACL,CAAC","sourcesContent":["// src/useAudioRecorder.ts\nimport { EventSubscription, Platform } from 'expo-modules-core'\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioDataEvent,\n AudioRecording,\n AudioStreamStatus,\n CompressionInfo,\n ConsoleLike,\n RecordingConfig,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\nimport {\n addAudioAnalysisListener,\n addAudioEventListener,\n AudioEventPayload,\n addRecordingInterruptionListener,\n} from './events'\n\nexport interface UseAudioRecorderProps {\n logger?: ConsoleLike\n audioWorkletUrl?: string\n featuresExtratorUrl?: string\n}\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n stopRecording: () => Promise<AudioRecording>\n pauseRecording: () => Promise<void>\n resumeRecording: () => Promise<void>\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ninterface RecorderReducerState {\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ntype RecorderAction =\n | { type: 'START' | 'STOP' | 'PAUSE' | 'RESUME' }\n | {\n type: 'UPDATE_RECORDING_STATE'\n payload: {\n isRecording: boolean\n isPaused: boolean\n }\n }\n | {\n type: 'UPDATE_STATUS'\n payload: {\n durationMs: number\n size: number\n compression?: CompressionInfo\n }\n }\n | { type: 'UPDATE_ANALYSIS'; payload: AudioAnalysis }\n\nconst defaultAnalysis: AudioAnalysis = {\n pointsPerSecond: 10,\n bitDepth: 32,\n numberOfChannels: 1,\n durationMs: 0,\n sampleRate: 44100,\n samples: 0,\n dataPoints: [],\n amplitudeAlgorithm: 'rms',\n speakerChanges: [],\n amplitudeRange: {\n min: Number.POSITIVE_INFINITY,\n max: Number.NEGATIVE_INFINITY,\n },\n}\n\nfunction audioRecorderReducer(\n state: RecorderReducerState,\n action: RecorderAction\n): RecorderReducerState {\n switch (action.type) {\n case 'START':\n return {\n ...state,\n isRecording: true,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: defaultAnalysis,\n }\n case 'STOP':\n return {\n ...state,\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n }\n case 'PAUSE':\n return { ...state, isPaused: true, isRecording: false }\n case 'RESUME':\n return { ...state, isPaused: false, isRecording: true }\n case 'UPDATE_RECORDING_STATE':\n return {\n ...state,\n isPaused: action.payload.isPaused,\n isRecording: action.payload.isRecording,\n }\n case 'UPDATE_STATUS': {\n const newState = {\n ...state,\n durationMs: action.payload.durationMs,\n size: action.payload.size,\n compression: action.payload.compression\n ? {\n size: action.payload.compression.size,\n mimeType: action.payload.compression.mimeType,\n bitrate: action.payload.compression.bitrate,\n format: action.payload.compression.format,\n }\n : undefined,\n }\n return newState\n }\n case 'UPDATE_ANALYSIS':\n return {\n ...state,\n analysisData: action.payload,\n }\n default:\n return state\n }\n}\n\ninterface HandleAudioAnalysisProps {\n analysis: AudioAnalysis\n visualizationDuration: number\n}\n\nexport function useAudioRecorder({\n logger,\n audioWorkletUrl,\n featuresExtratorUrl,\n}: UseAudioRecorderProps = {}): UseAudioRecorderState {\n const [state, dispatch] = useReducer(audioRecorderReducer, {\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n })\n\n const startResultRef = useRef<StartRecordingResult | null>(null)\n\n const analysisListenerRef = useRef<EventSubscription | null>(null)\n // analysisRef is the current analysis data (last 10 seconds by default)\n const analysisRef = useRef<AudioAnalysis>({ ...defaultAnalysis })\n // fullAnalysisRef is the full analysis data (all data points)\n const fullAnalysisRef = useRef<AudioAnalysis>({\n ...defaultAnalysis,\n })\n\n // Instantiate the module for web with URLs\n const ExpoAudioStream =\n Platform.OS === 'web'\n ? ExpoAudioStreamModule({\n audioWorkletUrl,\n featuresExtratorUrl,\n logger,\n })\n : ExpoAudioStreamModule\n\n const onAudioStreamRef = useRef<\n ((_: AudioDataEvent) => Promise<void>) | null\n >(null)\n\n const stateRef = useRef({\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined as CompressionInfo | undefined,\n })\n\n const recordingConfigRef = useRef<RecordingConfig | null>(null)\n\n const handleAudioAnalysis = useCallback(\n async ({\n analysis,\n visualizationDuration,\n }: HandleAudioAnalysisProps) => {\n const savedAnalysisData = analysisRef.current || {\n ...defaultAnalysis,\n }\n\n const maxDuration = visualizationDuration\n\n logger?.debug(\n `[handleAudioAnalysis] Received audio analysis: maxDuration=${maxDuration} analysis.dataPoints=${analysis.dataPoints.length} analysisData.dataPoints=${savedAnalysisData.dataPoints.length}`,\n analysis\n )\n\n // Combine data points\n const combinedDataPoints = [\n ...savedAnalysisData.dataPoints,\n ...analysis.dataPoints,\n ]\n\n const fullCombinedDataPoints = [\n ...(fullAnalysisRef.current?.dataPoints ?? []),\n ...analysis.dataPoints,\n ]\n\n // Calculate the new duration\n const pointsPerSecond =\n analysis.pointsPerSecond || savedAnalysisData.pointsPerSecond\n const maxDataPoints =\n (pointsPerSecond * visualizationDuration) / 1000\n\n logger?.debug(\n `[handleAudioAnalysis] Combined data points before trimming: pointsPerSecond=${pointsPerSecond} visualizationDuration=${visualizationDuration} combinedDataPointsLength=${combinedDataPoints.length} vs maxDataPoints=${maxDataPoints}`\n )\n\n // Trim data points to keep within the maximum number of data points\n if (combinedDataPoints.length > maxDataPoints) {\n combinedDataPoints.splice(\n 0,\n combinedDataPoints.length - maxDataPoints\n )\n }\n\n // Keep the full data points\n fullAnalysisRef.current = {\n ...fullAnalysisRef.current,\n dataPoints: fullCombinedDataPoints,\n }\n fullAnalysisRef.current.durationMs =\n fullCombinedDataPoints.length * (1000 / pointsPerSecond)\n savedAnalysisData.dataPoints = combinedDataPoints\n savedAnalysisData.bitDepth =\n analysis.bitDepth || savedAnalysisData.bitDepth\n savedAnalysisData.durationMs =\n combinedDataPoints.length * (1000 / pointsPerSecond)\n\n // Update amplitude range\n const newMin = Math.min(\n savedAnalysisData.amplitudeRange.min,\n analysis.amplitudeRange.min\n )\n const newMax = Math.max(\n savedAnalysisData.amplitudeRange.max,\n analysis.amplitudeRange.max\n )\n\n savedAnalysisData.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n fullAnalysisRef.current.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n\n logger?.debug(\n `[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`,\n savedAnalysisData\n )\n\n // Call the onAudioAnalysis callback if it exists in the recording config\n if (recordingConfigRef.current?.onAudioAnalysis) {\n try {\n await recordingConfigRef.current.onAudioAnalysis(analysis)\n } catch (error) {\n logger?.error('Error in onAudioAnalysis callback:', error)\n }\n }\n\n // Update the ref\n analysisRef.current = savedAnalysisData\n\n // Dispatch the updated analysis data to state to trigger re-render\n dispatch({\n type: 'UPDATE_ANALYSIS',\n payload: { ...savedAnalysisData },\n })\n },\n [dispatch]\n )\n\n const handleAudioEvent = useCallback(\n async (eventData: AudioEventPayload) => {\n const {\n fileUri,\n deltaSize,\n totalSize,\n lastEmittedSize,\n position,\n streamUuid,\n encoded,\n mimeType,\n buffer,\n compression,\n } = eventData\n logger?.debug(`[handleAudioEvent] Received audio event:`, {\n fileUri,\n deltaSize,\n totalSize,\n position,\n mimeType,\n lastEmittedSize,\n streamUuid,\n encodedLength: encoded?.length,\n compression,\n })\n if (deltaSize === 0) {\n // Ignore packet with no data\n return\n }\n try {\n // Coming from native ( ios / android ) otherwise buffer is set\n if (Platform.OS !== 'web') {\n // Read the audio file as a base64 string for comparison\n if (!encoded) {\n logger?.error(`Encoded audio data is missing`)\n throw new Error('Encoded audio data is missing')\n }\n onAudioStreamRef.current?.({\n data: encoded,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n })\n } else if (buffer) {\n // Coming from web\n const webEvent: AudioDataEvent = {\n data: buffer,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n }\n onAudioStreamRef.current?.(webEvent)\n logger?.debug(\n `[handleAudioEvent] Audio data sent to onAudioStream`,\n webEvent\n )\n }\n } catch (error) {\n logger?.error(`Error processing audio event:`, error)\n }\n },\n []\n )\n\n const checkStatus = useCallback(async () => {\n try {\n const status: AudioStreamStatus = ExpoAudioStream.status()\n logger?.debug(\n `Status: paused: ${status.isPaused} isRecording: ${status.isRecording} durationMs: ${status.durationMs} size: ${status.size}`,\n status.compression\n )\n\n // Only dispatch if values actually changed\n if (\n status.isRecording !== stateRef.current.isRecording ||\n status.isPaused !== stateRef.current.isPaused\n ) {\n stateRef.current.isRecording = status.isRecording\n stateRef.current.isPaused = status.isPaused\n dispatch({\n type: 'UPDATE_RECORDING_STATE',\n payload: {\n isRecording: status.isRecording,\n isPaused: status.isPaused,\n },\n })\n }\n\n if (\n status.durationMs !== stateRef.current.durationMs ||\n status.size !== stateRef.current.size\n ) {\n stateRef.current.durationMs = status.durationMs\n stateRef.current.size = status.size\n stateRef.current.compression = status.compression\n dispatch({\n type: 'UPDATE_STATUS',\n payload: {\n durationMs: status.durationMs,\n size: status.size,\n compression: status.compression,\n },\n })\n }\n } catch (error) {\n logger?.error(`Error getting status:`, error)\n }\n }, [ExpoAudioStream, logger]) // Only depend on ExpoAudioStream and logger\n\n // Update ref when state changes\n useEffect(() => {\n stateRef.current = {\n isRecording: state.isRecording,\n isPaused: state.isPaused,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n }\n }, [\n state.isRecording,\n state.isPaused,\n state.durationMs,\n state.size,\n state.compression,\n ])\n\n const startRecording = useCallback(\n async (recordingOptions: RecordingConfig) => {\n recordingConfigRef.current = recordingOptions\n logger?.debug(`start recoding`, recordingOptions)\n\n analysisRef.current = { ...defaultAnalysis } // Reset analysis data\n fullAnalysisRef.current = { ...defaultAnalysis }\n const { onAudioStream, ...options } = recordingOptions\n const { enableProcessing } = options\n\n const maxRecentDataDuration = 10000 // TODO compute maxRecentDataDuration based on screen dimensions\n if (typeof onAudioStream === 'function') {\n onAudioStreamRef.current = onAudioStream\n } else {\n logger?.warn(`onAudioStream is not a function`, onAudioStream)\n onAudioStreamRef.current = null\n }\n const startResult: StartRecordingResult =\n await ExpoAudioStream.startRecording(options)\n dispatch({ type: 'START' })\n\n startResultRef.current = startResult\n\n if (enableProcessing) {\n logger?.debug(`Enabling audio analysis listener`)\n const listener = addAudioAnalysisListener(\n async (analysisData) => {\n try {\n await handleAudioAnalysis({\n analysis: analysisData,\n visualizationDuration: maxRecentDataDuration,\n })\n } catch (error) {\n logger?.warn(\n `Error processing audio analysis:`,\n error\n )\n }\n }\n )\n\n analysisListenerRef.current = listener\n }\n\n return startResult\n },\n [handleAudioAnalysis, dispatch]\n )\n\n const stopRecording = useCallback(async () => {\n logger?.debug(`stoping recording`)\n\n const stopResult: AudioRecording = await ExpoAudioStream.stopRecording()\n stopResult.analysisData = fullAnalysisRef.current\n\n if (analysisListenerRef.current) {\n analysisListenerRef.current.remove()\n analysisListenerRef.current = null\n }\n onAudioStreamRef.current = null\n logger?.debug(`recording stopped`, stopResult)\n dispatch({ type: 'STOP' })\n return stopResult\n }, [dispatch])\n\n const pauseRecording = useCallback(async () => {\n logger?.debug(`pause recording`)\n const pauseResult = await ExpoAudioStream.pauseRecording()\n dispatch({ type: 'PAUSE' })\n return pauseResult\n }, [dispatch])\n\n const resumeRecording = useCallback(async () => {\n logger?.debug(`resume recording`)\n const resumeResult = await ExpoAudioStream.resumeRecording()\n dispatch({ type: 'RESUME' })\n return resumeResult\n }, [dispatch])\n\n useEffect(() => {\n let intervalId: NodeJS.Timeout | undefined\n\n if (state.isRecording || state.isPaused) {\n // Immediately check status when starting\n checkStatus()\n\n // Start interval\n intervalId = setInterval(checkStatus, 1000)\n }\n\n return () => {\n if (intervalId) {\n clearInterval(intervalId)\n intervalId = undefined\n }\n }\n }, [checkStatus, state.isRecording, state.isPaused])\n\n useEffect(() => {\n logger?.debug(`Registering audio event listener`)\n const subscribeAudio = addAudioEventListener(handleAudioEvent)\n\n logger?.debug(\n `Subscribed to audio event listener and analysis listener`,\n {\n subscribeAudio,\n }\n )\n\n return () => {\n logger?.debug(`Removing audio event listener`)\n subscribeAudio.remove()\n }\n }, [handleAudioEvent, handleAudioAnalysis])\n\n useEffect(() => {\n // Add event subscription for recording interruptions\n logger?.debug('Setting up recording interruption listener')\n\n const subscription = addRecordingInterruptionListener((event) => {\n logger?.debug('Received recording interruption event:', event)\n\n // Check if we have a callback configured\n if (recordingConfigRef.current?.onRecordingInterrupted) {\n try {\n recordingConfigRef.current.onRecordingInterrupted(event)\n } catch (error) {\n logger?.error(\n 'Error in recording interruption callback:',\n error\n )\n }\n } else {\n logger?.warn('No recording interruption callback configured')\n }\n })\n\n return () => {\n logger?.debug('Removing recording interruption listener')\n subscription.remove()\n }\n }, []) // Empty dependency array since we want this to run once\n\n return {\n startRecording,\n stopRecording,\n pauseRecording,\n resumeRecording,\n isPaused: state.isPaused,\n isRecording: state.isRecording,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n analysisData: state.analysisData,\n }\n}\n"]}
@@ -163,13 +163,13 @@ class AudioStreamManager: NSObject {
163
163
  // Configure audio session
164
164
  do {
165
165
  let session = AVAudioSession.sharedInstance()
166
- try session.setActive(false, options: .notifyOthersOnDeactivation)
167
166
  try session.setCategory(.playAndRecord, mode: .default, options: [.allowBluetooth, .mixWithOthers])
168
167
  try session.setActive(true, options: .notifyOthersOnDeactivation)
169
168
 
170
169
  // Resume if we're still recording and paused
171
170
  if self.isRecording && self.isPaused {
172
171
  Logger.debug("Resuming recording after phone call interruption")
172
+ self.audioEngine.prepare()
173
173
  self.resumeRecording()
174
174
  } else {
175
175
  Logger.debug("Cannot resume - recording state invalid: isRecording=\(self.isRecording), isPaused=\(self.isPaused)")
@@ -3,8 +3,6 @@ import AVFoundation
3
3
 
4
4
  let audioDataEvent: String = "AudioData"
5
5
  let audioAnalysisEvent: String = "AudioAnalysis"
6
- let recordingStateChangedEvent: String = "recordingStateChanged"
7
- let notificationStateChangedEvent: String = "notificationStateChanged"
8
6
  let recordingInterruptedEvent: String = "onRecordingInterrupted"
9
7
 
10
8
  public class ExpoAudioStreamModule: Module, AudioStreamManagerDelegate {
@@ -19,8 +17,6 @@ public class ExpoAudioStreamModule: Module, AudioStreamManagerDelegate {
19
17
  Events([
20
18
  audioDataEvent,
21
19
  audioAnalysisEvent,
22
- recordingStateChangedEvent,
23
- notificationStateChangedEvent,
24
20
  recordingInterruptedEvent
25
21
  ])
26
22
 
@@ -419,23 +415,63 @@ public class ExpoAudioStreamModule: Module, AudioStreamManagerDelegate {
419
415
  }
420
416
  }
421
417
 
418
+ func audioStreamManager(_ manager: AudioStreamManager, didReceiveInterruption info: [String: Any]) {
419
+ // Convert iOS interruption events to match the TypeScript types
420
+ var reason: String
421
+ var isPaused: Bool = true
422
+
423
+ if let type = info["type"] as? String {
424
+ switch type {
425
+ case "began":
426
+ // Phone call or other audio session interruption began
427
+ reason = "audioFocusLoss"
428
+ case "ended":
429
+ reason = "audioFocusGain"
430
+ isPaused = false
431
+ // Check if this was from a phone call
432
+ if let wasSuspended = info["wasSuspended"] as? Bool, wasSuspended {
433
+ reason = "phoneCallEnded"
434
+ }
435
+ default:
436
+ return
437
+ }
438
+ } else if let specificReason = info["reason"] as? String {
439
+ // Handle specific reasons that are already properly formatted
440
+ reason = specificReason
441
+ isPaused = info["isPaused"] as? Bool ?? true
442
+ } else {
443
+ return
444
+ }
445
+
446
+ // Send event in the correct format
447
+ sendEvent(recordingInterruptedEvent, [
448
+ "reason": reason,
449
+ "isPaused": isPaused,
450
+ "timestamp": Date().timeIntervalSince1970 * 1000
451
+ ])
452
+ }
453
+
422
454
  func audioStreamManager(_ manager: AudioStreamManager, didPauseRecording pauseTime: Date) {
423
- sendEvent(recordingStateChangedEvent, [
424
- "state": "paused",
455
+ sendEvent(recordingInterruptedEvent, [
456
+ "reason": "userPaused",
457
+ "isPaused": true,
425
458
  "timestamp": pauseTime.timeIntervalSince1970 * 1000
426
459
  ])
427
460
  }
428
461
 
429
462
  func audioStreamManager(_ manager: AudioStreamManager, didResumeRecording resumeTime: Date) {
430
- sendEvent(recordingStateChangedEvent, [
431
- "state": "recording",
463
+ sendEvent(recordingInterruptedEvent, [
464
+ "reason": "userResumed",
465
+ "isPaused": false,
432
466
  "timestamp": resumeTime.timeIntervalSince1970 * 1000
433
467
  ])
434
468
  }
435
469
 
436
470
  func audioStreamManager(_ manager: AudioStreamManager, didUpdateNotificationState isPaused: Bool) {
437
- sendEvent(notificationStateChangedEvent, [
438
- "isPaused": isPaused
471
+ sendEvent(recordingInterruptedEvent, [
472
+ "reason": "notification",
473
+ "isPaused": isPaused,
474
+ "timestamp": Date().timeIntervalSince1970 * 1000
439
475
  ])
440
476
  }
441
477
 
@@ -568,10 +604,6 @@ public class ExpoAudioStreamModule: Module, AudioStreamManagerDelegate {
568
604
  }
569
605
  }
570
606
 
571
- func audioStreamManager(_ manager: AudioStreamManager, didReceiveInterruption info: [String: Any]) {
572
- sendEvent(recordingInterruptedEvent, info)
573
- }
574
-
575
607
  func audioStreamManager(_ manager: AudioStreamManager, didFailWithError error: String) {
576
608
  // Send error event to JavaScript
577
609
  sendEvent("error", [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siteed/expo-audio-stream",
3
- "version": "1.14.2",
3
+ "version": "1.15.0",
4
4
  "description": "stream audio crossplatform",
5
5
  "license": "MIT",
6
6
  "main": "build/index.js",
@@ -11,7 +11,7 @@ function debugLog(message, ...args) {
11
11
  }
12
12
  const withRecordingPermission = (config, props) => {
13
13
  const options = {
14
- enablePhoneStateHandling: true,
14
+ enablePhoneStateHandling: true, // Default to true for backward compatibility
15
15
  enableNotifications: true,
16
16
  enableBackgroundAudio: true,
17
17
  iosBackgroundModes: {
@@ -17,7 +17,7 @@ function debugLog(message: string, ...args: unknown[]): void {
17
17
  }
18
18
 
19
19
  interface AudioStreamPluginOptions {
20
- enablePhoneStateHandling?: boolean
20
+ enablePhoneStateHandling?: boolean // Controls READ_PHONE_STATE permission
21
21
  enableNotifications?: boolean
22
22
  enableBackgroundAudio?: boolean
23
23
  iosBackgroundModes?: {
@@ -38,7 +38,7 @@ const withRecordingPermission: ConfigPlugin<AudioStreamPluginOptions> = (
38
38
  props: AudioStreamPluginOptions | void
39
39
  ) => {
40
40
  const options: AudioStreamPluginOptions = {
41
- enablePhoneStateHandling: true,
41
+ enablePhoneStateHandling: true, // Default to true for backward compatibility
42
42
  enableNotifications: true,
43
43
  enableBackgroundAudio: true,
44
44
  iosBackgroundModes: {
@@ -126,6 +126,7 @@ export type RecordingInterruptionReason =
126
126
  | 'audioFocusGain'
127
127
  | 'phoneCall'
128
128
  | 'phoneCallEnded'
129
+ | 'recordingStopped'
129
130
 
130
131
  // Add new interface for interruption events
131
132
  export interface RecordingInterruptionEvent {
package/src/events.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'
4
4
 
5
5
  import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'
6
+ import { RecordingInterruptionEvent } from './ExpoAudioStream.types'
6
7
  import ExpoAudioStreamModule from './ExpoAudioStreamModule'
7
8
 
8
9
  const emitter = new LegacyEventEmitter(ExpoAudioStreamModule)
@@ -40,3 +41,20 @@ export function addAudioAnalysisListener(
40
41
  ): EventSubscription {
41
42
  return emitter.addListener<AudioAnalysisEvent>('AudioAnalysis', listener)
42
43
  }
44
+
45
+ export function addRecordingInterruptionListener(
46
+ listener: (event: RecordingInterruptionEvent) => void
47
+ ): EventSubscription {
48
+ // Add debug logging
49
+ console.debug('Adding recording interruption listener')
50
+
51
+ const subscription = emitter.addListener<RecordingInterruptionEvent>(
52
+ 'onRecordingInterrupted', // Make sure this matches the native event name
53
+ (event) => {
54
+ console.debug('Recording interruption event received:', event)
55
+ listener(event)
56
+ }
57
+ )
58
+
59
+ return subscription
60
+ }
@@ -17,6 +17,7 @@ import {
17
17
  addAudioAnalysisListener,
18
18
  addAudioEventListener,
19
19
  AudioEventPayload,
20
+ addRecordingInterruptionListener,
20
21
  } from './events'
21
22
 
22
23
  export interface UseAudioRecorderProps {
@@ -194,6 +195,8 @@ export function useAudioRecorder({
194
195
  compression: undefined as CompressionInfo | undefined,
195
196
  })
196
197
 
198
+ const recordingConfigRef = useRef<RecordingConfig | null>(null)
199
+
197
200
  const handleAudioAnalysis = useCallback(
198
201
  async ({
199
202
  analysis,
@@ -276,11 +279,19 @@ export function useAudioRecorder({
276
279
  savedAnalysisData
277
280
  )
278
281
 
282
+ // Call the onAudioAnalysis callback if it exists in the recording config
283
+ if (recordingConfigRef.current?.onAudioAnalysis) {
284
+ try {
285
+ await recordingConfigRef.current.onAudioAnalysis(analysis)
286
+ } catch (error) {
287
+ logger?.error('Error in onAudioAnalysis callback:', error)
288
+ }
289
+ }
290
+
279
291
  // Update the ref
280
292
  analysisRef.current = savedAnalysisData
281
293
 
282
294
  // Dispatch the updated analysis data to state to trigger re-render
283
- // need to use spread operator otherwise it doesnt trigger update.
284
295
  dispatch({
285
296
  type: 'UPDATE_ANALYSIS',
286
297
  payload: { ...savedAnalysisData },
@@ -449,6 +460,7 @@ export function useAudioRecorder({
449
460
 
450
461
  const startRecording = useCallback(
451
462
  async (recordingOptions: RecordingConfig) => {
463
+ recordingConfigRef.current = recordingOptions
452
464
  logger?.debug(`start recoding`, recordingOptions)
453
465
 
454
466
  analysisRef.current = { ...defaultAnalysis } // Reset analysis data
@@ -561,6 +573,34 @@ export function useAudioRecorder({
561
573
  }
562
574
  }, [handleAudioEvent, handleAudioAnalysis])
563
575
 
576
+ useEffect(() => {
577
+ // Add event subscription for recording interruptions
578
+ logger?.debug('Setting up recording interruption listener')
579
+
580
+ const subscription = addRecordingInterruptionListener((event) => {
581
+ logger?.debug('Received recording interruption event:', event)
582
+
583
+ // Check if we have a callback configured
584
+ if (recordingConfigRef.current?.onRecordingInterrupted) {
585
+ try {
586
+ recordingConfigRef.current.onRecordingInterrupted(event)
587
+ } catch (error) {
588
+ logger?.error(
589
+ 'Error in recording interruption callback:',
590
+ error
591
+ )
592
+ }
593
+ } else {
594
+ logger?.warn('No recording interruption callback configured')
595
+ }
596
+ })
597
+
598
+ return () => {
599
+ logger?.debug('Removing recording interruption listener')
600
+ subscription.remove()
601
+ }
602
+ }, []) // Empty dependency array since we want this to run once
603
+
564
604
  return {
565
605
  startRecording,
566
606
  stopRecording,