@siteed/expo-audio-studio 2.18.6 → 3.0.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.
Files changed (329) hide show
  1. package/README.md +13 -297
  2. package/index.d.ts +1 -0
  3. package/index.js +1 -0
  4. package/package.json +6 -135
  5. package/CHANGELOG.md +0 -501
  6. package/LICENSE +0 -21
  7. package/android/build.gradle +0 -129
  8. package/android/src/androidTest/assets/chorus.wav +0 -0
  9. package/android/src/androidTest/assets/jfk.wav +0 -0
  10. package/android/src/androidTest/assets/osr_us_000_0010_8k.wav +0 -0
  11. package/android/src/androidTest/assets/recorder_hello_world.wav +0 -0
  12. package/android/src/androidTest/java/net/siteed/audiostream/AudioProcessorInstrumentedTest.kt +0 -197
  13. package/android/src/androidTest/java/net/siteed/audiostream/AudioRecorderInstrumentedTest.kt +0 -541
  14. package/android/src/androidTest/java/net/siteed/audiostream/AudioRecorderPerformanceInstrumentedTest.kt +0 -234
  15. package/android/src/androidTest/java/net/siteed/audiostream/integration/AudioFocusStrategyIntegrationTest.kt +0 -332
  16. package/android/src/androidTest/java/net/siteed/audiostream/integration/BufferDurationIntegrationTest.kt +0 -324
  17. package/android/src/androidTest/java/net/siteed/audiostream/integration/CompressedOnlyOutputTest.kt +0 -253
  18. package/android/src/androidTest/java/net/siteed/audiostream/integration/DeviceDisconnectionFallbackTest.kt +0 -218
  19. package/android/src/androidTest/java/net/siteed/audiostream/integration/EventEmissionIntervalTest.kt +0 -120
  20. package/android/src/androidTest/java/net/siteed/audiostream/integration/M4aFormatTest.kt +0 -345
  21. package/android/src/androidTest/java/net/siteed/audiostream/integration/OutputControlIntegrationTest.kt +0 -340
  22. package/android/src/androidTest/java/net/siteed/audiostream/integration/PcmStreamingDurationTest.kt +0 -252
  23. package/android/src/androidTest/java/net/siteed/audiostream/integration/README.md +0 -95
  24. package/android/src/androidTest/java/net/siteed/audiostream/integration/run_integration_tests.sh +0 -43
  25. package/android/src/main/AndroidManifest.xml +0 -30
  26. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +0 -188
  27. package/android/src/main/java/net/siteed/audiostream/AudioDataEncoder.kt +0 -9
  28. package/android/src/main/java/net/siteed/audiostream/AudioDeviceManager.kt +0 -1741
  29. package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +0 -136
  30. package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +0 -354
  31. package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +0 -439
  32. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +0 -2237
  33. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +0 -2141
  34. package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +0 -167
  35. package/android/src/main/java/net/siteed/audiostream/AudioTrimmer.kt +0 -1099
  36. package/android/src/main/java/net/siteed/audiostream/Constants.kt +0 -37
  37. package/android/src/main/java/net/siteed/audiostream/EventSender.kt +0 -7
  38. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +0 -1113
  39. package/android/src/main/java/net/siteed/audiostream/FFT.kt +0 -99
  40. package/android/src/main/java/net/siteed/audiostream/Features.kt +0 -98
  41. package/android/src/main/java/net/siteed/audiostream/LogUtils.kt +0 -93
  42. package/android/src/main/java/net/siteed/audiostream/NotificationConfig.kt +0 -72
  43. package/android/src/main/java/net/siteed/audiostream/PermissionUtils.kt +0 -68
  44. package/android/src/main/java/net/siteed/audiostream/RecordingActionReceiver.kt +0 -59
  45. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +0 -257
  46. package/android/src/main/java/net/siteed/audiostream/WaveformConfig.kt +0 -19
  47. package/android/src/main/java/net/siteed/audiostream/WaveformRenderer.kt +0 -159
  48. package/android/src/main/res/drawable/ic_default_action_icon.xml +0 -16
  49. package/android/src/main/res/drawable/ic_microphone.xml +0 -13
  50. package/android/src/main/res/drawable/ic_pause.xml +0 -10
  51. package/android/src/main/res/drawable/ic_play.xml +0 -10
  52. package/android/src/main/res/drawable/ic_stop.xml +0 -10
  53. package/android/src/main/res/layout/notification_recording.xml +0 -37
  54. package/android/src/test/java/net/siteed/audiostream/AudioFileHandlerTest.kt +0 -279
  55. package/android/src/test/java/net/siteed/audiostream/AudioFocusStrategyTest.kt +0 -249
  56. package/android/src/test/java/net/siteed/audiostream/AudioFormatTest.kt +0 -151
  57. package/android/src/test/java/net/siteed/audiostream/AudioFormatUtilsTest.kt +0 -273
  58. package/android/src/test/java/net/siteed/audiostream/DeviceDisconnectionFallbackUnitTest.kt +0 -140
  59. package/android/src/test/resources/chorus.wav +0 -0
  60. package/android/src/test/resources/generate_test_audio.py +0 -94
  61. package/android/src/test/resources/jfk.wav +0 -0
  62. package/android/src/test/resources/osr_us_000_0010_8k.wav +0 -0
  63. package/android/src/test/resources/recorder_hello_world.wav +0 -0
  64. package/app.plugin.js +0 -3
  65. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js +0 -4
  66. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  67. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js +0 -210
  68. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  69. package/build/cjs/AudioAnalysis/extractAudioData.js +0 -21
  70. package/build/cjs/AudioAnalysis/extractAudioData.js.map +0 -1
  71. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js +0 -92
  72. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js.map +0 -1
  73. package/build/cjs/AudioAnalysis/extractPreview.js +0 -28
  74. package/build/cjs/AudioAnalysis/extractPreview.js.map +0 -1
  75. package/build/cjs/AudioAnalysis/extractWaveform.js +0 -18
  76. package/build/cjs/AudioAnalysis/extractWaveform.js.map +0 -1
  77. package/build/cjs/AudioDeviceManager.js +0 -689
  78. package/build/cjs/AudioDeviceManager.js.map +0 -1
  79. package/build/cjs/AudioRecorder.provider.js +0 -78
  80. package/build/cjs/AudioRecorder.provider.js.map +0 -1
  81. package/build/cjs/ExpoAudioStream.native.js +0 -8
  82. package/build/cjs/ExpoAudioStream.native.js.map +0 -1
  83. package/build/cjs/ExpoAudioStream.types.js +0 -11
  84. package/build/cjs/ExpoAudioStream.types.js.map +0 -1
  85. package/build/cjs/ExpoAudioStream.web.js +0 -708
  86. package/build/cjs/ExpoAudioStream.web.js.map +0 -1
  87. package/build/cjs/ExpoAudioStreamModule.js +0 -718
  88. package/build/cjs/ExpoAudioStreamModule.js.map +0 -1
  89. package/build/cjs/WebRecorder.web.js +0 -777
  90. package/build/cjs/WebRecorder.web.js.map +0 -1
  91. package/build/cjs/constants/platformLimitations.js +0 -99
  92. package/build/cjs/constants/platformLimitations.js.map +0 -1
  93. package/build/cjs/constants.js +0 -17
  94. package/build/cjs/constants.js.map +0 -1
  95. package/build/cjs/events.js +0 -29
  96. package/build/cjs/events.js.map +0 -1
  97. package/build/cjs/hooks/useAudioDevices.js +0 -179
  98. package/build/cjs/hooks/useAudioDevices.js.map +0 -1
  99. package/build/cjs/index.js +0 -58
  100. package/build/cjs/index.js.map +0 -1
  101. package/build/cjs/trimAudio.js +0 -76
  102. package/build/cjs/trimAudio.js.map +0 -1
  103. package/build/cjs/useAudioRecorder.js +0 -518
  104. package/build/cjs/useAudioRecorder.js.map +0 -1
  105. package/build/cjs/utils/BlobFix.js +0 -502
  106. package/build/cjs/utils/BlobFix.js.map +0 -1
  107. package/build/cjs/utils/audioProcessing.js +0 -136
  108. package/build/cjs/utils/audioProcessing.js.map +0 -1
  109. package/build/cjs/utils/cleanNativeOptions.js +0 -22
  110. package/build/cjs/utils/cleanNativeOptions.js.map +0 -1
  111. package/build/cjs/utils/concatenateBuffers.js +0 -25
  112. package/build/cjs/utils/concatenateBuffers.js.map +0 -1
  113. package/build/cjs/utils/convertPCMToFloat32.js +0 -124
  114. package/build/cjs/utils/convertPCMToFloat32.js.map +0 -1
  115. package/build/cjs/utils/crc32.js +0 -52
  116. package/build/cjs/utils/crc32.js.map +0 -1
  117. package/build/cjs/utils/encodingToBitDepth.js +0 -17
  118. package/build/cjs/utils/encodingToBitDepth.js.map +0 -1
  119. package/build/cjs/utils/getWavFileInfo.js +0 -96
  120. package/build/cjs/utils/getWavFileInfo.js.map +0 -1
  121. package/build/cjs/utils/writeWavHeader.js +0 -88
  122. package/build/cjs/utils/writeWavHeader.js.map +0 -1
  123. package/build/cjs/workers/InlineFeaturesExtractor.web.js +0 -859
  124. package/build/cjs/workers/InlineFeaturesExtractor.web.js.map +0 -1
  125. package/build/cjs/workers/inlineAudioWebWorker.web.js +0 -184
  126. package/build/cjs/workers/inlineAudioWebWorker.web.js.map +0 -1
  127. package/build/esm/AudioAnalysis/AudioAnalysis.types.js +0 -3
  128. package/build/esm/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  129. package/build/esm/AudioAnalysis/extractAudioAnalysis.js +0 -202
  130. package/build/esm/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  131. package/build/esm/AudioAnalysis/extractAudioData.js +0 -14
  132. package/build/esm/AudioAnalysis/extractAudioData.js.map +0 -1
  133. package/build/esm/AudioAnalysis/extractMelSpectrogram.js +0 -89
  134. package/build/esm/AudioAnalysis/extractMelSpectrogram.js.map +0 -1
  135. package/build/esm/AudioAnalysis/extractPreview.js +0 -25
  136. package/build/esm/AudioAnalysis/extractPreview.js.map +0 -1
  137. package/build/esm/AudioAnalysis/extractWaveform.js +0 -11
  138. package/build/esm/AudioAnalysis/extractWaveform.js.map +0 -1
  139. package/build/esm/AudioDeviceManager.js +0 -682
  140. package/build/esm/AudioDeviceManager.js.map +0 -1
  141. package/build/esm/AudioRecorder.provider.js +0 -40
  142. package/build/esm/AudioRecorder.provider.js.map +0 -1
  143. package/build/esm/ExpoAudioStream.native.js +0 -6
  144. package/build/esm/ExpoAudioStream.native.js.map +0 -1
  145. package/build/esm/ExpoAudioStream.types.js +0 -8
  146. package/build/esm/ExpoAudioStream.types.js.map +0 -1
  147. package/build/esm/ExpoAudioStream.web.js +0 -704
  148. package/build/esm/ExpoAudioStream.web.js.map +0 -1
  149. package/build/esm/ExpoAudioStreamModule.js +0 -713
  150. package/build/esm/ExpoAudioStreamModule.js.map +0 -1
  151. package/build/esm/WebRecorder.web.js +0 -773
  152. package/build/esm/WebRecorder.web.js.map +0 -1
  153. package/build/esm/constants/platformLimitations.js +0 -90
  154. package/build/esm/constants/platformLimitations.js.map +0 -1
  155. package/build/esm/constants.js +0 -14
  156. package/build/esm/constants.js.map +0 -1
  157. package/build/esm/events.js +0 -21
  158. package/build/esm/events.js.map +0 -1
  159. package/build/esm/hooks/useAudioDevices.js +0 -176
  160. package/build/esm/hooks/useAudioDevices.js.map +0 -1
  161. package/build/esm/index.js +0 -20
  162. package/build/esm/index.js.map +0 -1
  163. package/build/esm/trimAudio.js +0 -69
  164. package/build/esm/trimAudio.js.map +0 -1
  165. package/build/esm/useAudioRecorder.js +0 -512
  166. package/build/esm/useAudioRecorder.js.map +0 -1
  167. package/build/esm/utils/BlobFix.js +0 -498
  168. package/build/esm/utils/BlobFix.js.map +0 -1
  169. package/build/esm/utils/audioProcessing.js +0 -133
  170. package/build/esm/utils/audioProcessing.js.map +0 -1
  171. package/build/esm/utils/cleanNativeOptions.js +0 -19
  172. package/build/esm/utils/cleanNativeOptions.js.map +0 -1
  173. package/build/esm/utils/concatenateBuffers.js +0 -21
  174. package/build/esm/utils/concatenateBuffers.js.map +0 -1
  175. package/build/esm/utils/convertPCMToFloat32.js +0 -120
  176. package/build/esm/utils/convertPCMToFloat32.js.map +0 -1
  177. package/build/esm/utils/crc32.js +0 -50
  178. package/build/esm/utils/crc32.js.map +0 -1
  179. package/build/esm/utils/encodingToBitDepth.js +0 -13
  180. package/build/esm/utils/encodingToBitDepth.js.map +0 -1
  181. package/build/esm/utils/getWavFileInfo.js +0 -92
  182. package/build/esm/utils/getWavFileInfo.js.map +0 -1
  183. package/build/esm/utils/writeWavHeader.js +0 -84
  184. package/build/esm/utils/writeWavHeader.js.map +0 -1
  185. package/build/esm/workers/InlineFeaturesExtractor.web.js +0 -856
  186. package/build/esm/workers/InlineFeaturesExtractor.web.js.map +0 -1
  187. package/build/esm/workers/inlineAudioWebWorker.web.js +0 -181
  188. package/build/esm/workers/inlineAudioWebWorker.web.js.map +0 -1
  189. package/build/types/AudioAnalysis/AudioAnalysis.types.d.ts +0 -196
  190. package/build/types/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  191. package/build/types/AudioAnalysis/extractAudioAnalysis.d.ts +0 -74
  192. package/build/types/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  193. package/build/types/AudioAnalysis/extractAudioData.d.ts +0 -3
  194. package/build/types/AudioAnalysis/extractAudioData.d.ts.map +0 -1
  195. package/build/types/AudioAnalysis/extractMelSpectrogram.d.ts +0 -14
  196. package/build/types/AudioAnalysis/extractMelSpectrogram.d.ts.map +0 -1
  197. package/build/types/AudioAnalysis/extractPreview.d.ts +0 -11
  198. package/build/types/AudioAnalysis/extractPreview.d.ts.map +0 -1
  199. package/build/types/AudioAnalysis/extractWaveform.d.ts +0 -8
  200. package/build/types/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  201. package/build/types/AudioDeviceManager.d.ts +0 -187
  202. package/build/types/AudioDeviceManager.d.ts.map +0 -1
  203. package/build/types/AudioRecorder.provider.d.ts +0 -11
  204. package/build/types/AudioRecorder.provider.d.ts.map +0 -1
  205. package/build/types/ExpoAudioStream.native.d.ts +0 -3
  206. package/build/types/ExpoAudioStream.native.d.ts.map +0 -1
  207. package/build/types/ExpoAudioStream.types.d.ts +0 -738
  208. package/build/types/ExpoAudioStream.types.d.ts.map +0 -1
  209. package/build/types/ExpoAudioStream.web.d.ts +0 -96
  210. package/build/types/ExpoAudioStream.web.d.ts.map +0 -1
  211. package/build/types/ExpoAudioStreamModule.d.ts +0 -3
  212. package/build/types/ExpoAudioStreamModule.d.ts.map +0 -1
  213. package/build/types/WebRecorder.web.d.ts +0 -198
  214. package/build/types/WebRecorder.web.d.ts.map +0 -1
  215. package/build/types/constants/platformLimitations.d.ts +0 -40
  216. package/build/types/constants/platformLimitations.d.ts.map +0 -1
  217. package/build/types/constants.d.ts +0 -11
  218. package/build/types/constants.d.ts.map +0 -1
  219. package/build/types/events.d.ts +0 -26
  220. package/build/types/events.d.ts.map +0 -1
  221. package/build/types/hooks/useAudioDevices.d.ts +0 -15
  222. package/build/types/hooks/useAudioDevices.d.ts.map +0 -1
  223. package/build/types/index.d.ts +0 -18
  224. package/build/types/index.d.ts.map +0 -1
  225. package/build/types/trimAudio.d.ts +0 -25
  226. package/build/types/trimAudio.d.ts.map +0 -1
  227. package/build/types/useAudioRecorder.d.ts +0 -22
  228. package/build/types/useAudioRecorder.d.ts.map +0 -1
  229. package/build/types/utils/BlobFix.d.ts +0 -9
  230. package/build/types/utils/BlobFix.d.ts.map +0 -1
  231. package/build/types/utils/audioProcessing.d.ts +0 -24
  232. package/build/types/utils/audioProcessing.d.ts.map +0 -1
  233. package/build/types/utils/cleanNativeOptions.d.ts +0 -15
  234. package/build/types/utils/cleanNativeOptions.d.ts.map +0 -1
  235. package/build/types/utils/concatenateBuffers.d.ts +0 -8
  236. package/build/types/utils/concatenateBuffers.d.ts.map +0 -1
  237. package/build/types/utils/convertPCMToFloat32.d.ts +0 -13
  238. package/build/types/utils/convertPCMToFloat32.d.ts.map +0 -1
  239. package/build/types/utils/crc32.d.ts +0 -7
  240. package/build/types/utils/crc32.d.ts.map +0 -1
  241. package/build/types/utils/encodingToBitDepth.d.ts +0 -5
  242. package/build/types/utils/encodingToBitDepth.d.ts.map +0 -1
  243. package/build/types/utils/getWavFileInfo.d.ts +0 -26
  244. package/build/types/utils/getWavFileInfo.d.ts.map +0 -1
  245. package/build/types/utils/writeWavHeader.d.ts +0 -34
  246. package/build/types/utils/writeWavHeader.d.ts.map +0 -1
  247. package/build/types/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  248. package/build/types/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  249. package/build/types/workers/inlineAudioWebWorker.web.d.ts +0 -2
  250. package/build/types/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  251. package/expo-module.config.json +0 -10
  252. package/ios/AudioAnalysisData.swift +0 -74
  253. package/ios/AudioDeviceManager.swift +0 -670
  254. package/ios/AudioNotificationManager.swift +0 -154
  255. package/ios/AudioProcessingHelpers.swift +0 -743
  256. package/ios/AudioProcessor.swift +0 -1151
  257. package/ios/AudioStreamError.swift +0 -7
  258. package/ios/AudioStreamManager.swift +0 -2369
  259. package/ios/AudioStreamManagerDelegate.swift +0 -16
  260. package/ios/DataPoint.swift +0 -54
  261. package/ios/DecodingConfig.swift +0 -59
  262. package/ios/ExpoAudioStream.podspec +0 -33
  263. package/ios/ExpoAudioStreamModule.swift +0 -1019
  264. package/ios/ExpoAudioStudioTests/AudioFileHandlerTests.swift +0 -338
  265. package/ios/ExpoAudioStudioTests/AudioFormatUtilsTests.swift +0 -331
  266. package/ios/ExpoAudioStudioTests/AudioTestHelpers.swift +0 -130
  267. package/ios/ExpoAudioStudioTests/CompressedOnlyOutputTests.swift +0 -294
  268. package/ios/ExpoAudioStudioTests/EventEmissionIntervalTests.swift +0 -105
  269. package/ios/ExpoAudioStudioTests/Info.plist +0 -22
  270. package/ios/ExpoAudioStudioTests/README.md +0 -39
  271. package/ios/ExpoAudioStudioTests/SimpleAudioTest.swift +0 -98
  272. package/ios/ExpoAudioStudioTests/TestAudioGenerator.swift +0 -75
  273. package/ios/FFT.swift +0 -62
  274. package/ios/Features.swift +0 -95
  275. package/ios/ISSUE_IOS.md +0 -68
  276. package/ios/Logger.swift +0 -39
  277. package/ios/NotificationExtension.swift +0 -15
  278. package/ios/RecordingResult.swift +0 -22
  279. package/ios/RecordingSettings.swift +0 -308
  280. package/ios/WaveformExtractor.swift +0 -105
  281. package/ios/tests/README.md +0 -41
  282. package/ios/tests/integration/buffer_and_fallback_test.swift +0 -178
  283. package/ios/tests/integration/buffer_duration_test.swift +0 -185
  284. package/ios/tests/integration/compressed_only_output_test.swift +0 -271
  285. package/ios/tests/integration/output_control_test.swift +0 -322
  286. package/ios/tests/integration/run_integration_tests.sh +0 -37
  287. package/ios/tests/opus_support_test_macos.swift +0 -154
  288. package/ios/tests/standalone/audio_processing_test.swift +0 -144
  289. package/ios/tests/standalone/audio_recording_test.swift +0 -277
  290. package/ios/tests/standalone/audio_streaming_test.swift +0 -249
  291. package/ios/tests/standalone/standalone_test.swift +0 -144
  292. package/plugin/build/index.cjs +0 -194
  293. package/plugin/build/index.d.cts +0 -22
  294. package/plugin/build/index.js +0 -194
  295. package/plugin/src/index.ts +0 -285
  296. package/plugin/tsconfig.json +0 -10
  297. package/plugin/tsconfig.tsbuildinfo +0 -1
  298. package/src/AudioAnalysis/AudioAnalysis.types.ts +0 -224
  299. package/src/AudioAnalysis/extractAudioAnalysis.ts +0 -344
  300. package/src/AudioAnalysis/extractAudioData.ts +0 -17
  301. package/src/AudioAnalysis/extractMelSpectrogram.ts +0 -154
  302. package/src/AudioAnalysis/extractPreview.ts +0 -34
  303. package/src/AudioAnalysis/extractWaveform.ts +0 -22
  304. package/src/AudioDeviceManager.ts +0 -803
  305. package/src/AudioRecorder.provider.tsx +0 -57
  306. package/src/ExpoAudioStream.native.ts +0 -6
  307. package/src/ExpoAudioStream.types.ts +0 -874
  308. package/src/ExpoAudioStream.web.ts +0 -905
  309. package/src/ExpoAudioStreamModule.ts +0 -990
  310. package/src/WebRecorder.web.ts +0 -1005
  311. package/src/constants/platformLimitations.ts +0 -118
  312. package/src/constants.ts +0 -18
  313. package/src/events.ts +0 -60
  314. package/src/hooks/useAudioDevices.ts +0 -213
  315. package/src/index.ts +0 -54
  316. package/src/trimAudio.ts +0 -94
  317. package/src/types/crc-32.d.ts +0 -9
  318. package/src/useAudioRecorder.tsx +0 -766
  319. package/src/utils/BlobFix.ts +0 -561
  320. package/src/utils/audioProcessing.ts +0 -205
  321. package/src/utils/cleanNativeOptions.ts +0 -18
  322. package/src/utils/concatenateBuffers.ts +0 -24
  323. package/src/utils/convertPCMToFloat32.ts +0 -170
  324. package/src/utils/crc32.ts +0 -59
  325. package/src/utils/encodingToBitDepth.ts +0 -18
  326. package/src/utils/getWavFileInfo.ts +0 -132
  327. package/src/utils/writeWavHeader.ts +0 -115
  328. package/src/workers/InlineFeaturesExtractor.web.tsx +0 -855
  329. package/src/workers/inlineAudioWebWorker.web.tsx +0 -180
@@ -1,76 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.trimAudio = trimAudio;
7
- exports.trimAudioSimple = trimAudioSimple;
8
- const expo_modules_core_1 = require("expo-modules-core");
9
- const ExpoAudioStreamModule_1 = __importDefault(require("./ExpoAudioStreamModule"));
10
- const cleanNativeOptions_1 = require("./utils/cleanNativeOptions");
11
- // Create a single emitter instance
12
- const emitter = new expo_modules_core_1.LegacyEventEmitter(ExpoAudioStreamModule_1.default);
13
- /**
14
- * Trims an audio file based on the provided options.
15
- *
16
- * @experimental This API is experimental and not fully optimized for production use.
17
- * Performance may vary based on file size and device capabilities.
18
- * Future versions may include breaking changes.
19
- *
20
- * @param options Configuration options for the trimming operation
21
- * @param progressCallback Optional callback to receive progress updates
22
- * @returns Promise resolving to the trimmed audio file information, including processing time
23
- */
24
- async function trimAudio(options, progressCallback) {
25
- // Validation
26
- if (!options.fileUri) {
27
- throw new Error('fileUri is required');
28
- }
29
- const mode = options.mode ?? 'single';
30
- if (mode === 'single') {
31
- if (options.startTimeMs === undefined &&
32
- options.endTimeMs === undefined) {
33
- throw new Error('At least one of startTimeMs or endTimeMs must be provided in single mode');
34
- }
35
- }
36
- else if (mode === 'keep' || mode === 'remove') {
37
- if (!options.ranges || options.ranges.length === 0) {
38
- throw new Error('ranges must be provided and non-empty for keep or remove modes');
39
- }
40
- }
41
- else {
42
- throw new Error(`Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`);
43
- }
44
- // Set up progress event listener if callback is provided
45
- let subscription;
46
- if (progressCallback) {
47
- subscription = emitter.addListener('TrimProgress', (event) => {
48
- progressCallback(event);
49
- });
50
- }
51
- try {
52
- // Clean non-serializable/undefined values to avoid Android Kotlin bridge crash
53
- const result = await ExpoAudioStreamModule_1.default.trimAudio((0, cleanNativeOptions_1.cleanNativeOptions)(options));
54
- return result;
55
- }
56
- finally {
57
- if (subscription) {
58
- subscription.remove();
59
- }
60
- }
61
- }
62
- /**
63
- * Simplified version of trimAudio that returns only the URI of the trimmed file.
64
- *
65
- * @experimental This API is experimental and not fully optimized for production use.
66
- * Performance may vary based on file size and device capabilities.
67
- * Future versions may include breaking changes.
68
- *
69
- * @param options Configuration options for the trimming operation
70
- * @returns Promise resolving to the URI of the trimmed audio file
71
- */
72
- async function trimAudioSimple(options) {
73
- const result = await trimAudio(options);
74
- return result.uri;
75
- }
76
- //# sourceMappingURL=trimAudio.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trimAudio.js","sourceRoot":"","sources":["../../src/trimAudio.ts"],"names":[],"mappings":";;;;;AAwBA,8BAoDC;AAYD,0CAKC;AA7FD,yDAA8E;AAO9E,oFAA2D;AAC3D,mEAA+D;AAE/D,mCAAmC;AACnC,MAAM,OAAO,GAAG,IAAI,sCAAkB,CAAC,+BAAqB,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACI,KAAK,UAAU,SAAS,CAC3B,OAAyB,EACzB,gBAAqD;IAErD,aAAa;IACb,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAC1C,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAA;IACrC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpB,IACI,OAAO,CAAC,WAAW,KAAK,SAAS;YACjC,OAAO,CAAC,SAAS,KAAK,SAAS,EACjC,CAAC;YACC,MAAM,IAAI,KAAK,CACX,0EAA0E,CAC7E,CAAA;QACL,CAAC;IACL,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CACX,gEAAgE,CACnE,CAAA;QACL,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CACX,iBAAiB,IAAI,yCAAyC,CACjE,CAAA;IACL,CAAC;IAED,yDAAyD;IACzD,IAAI,YAA2C,CAAA;IAC/C,IAAI,gBAAgB,EAAE,CAAC;QACnB,YAAY,GAAG,OAAO,CAAC,WAAW,CAC9B,cAAc,EACd,CAAC,KAAwB,EAAE,EAAE;YACzB,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC,CACJ,CAAA;IACL,CAAC;IAED,IAAI,CAAC;QACD,+EAA+E;QAC/E,MAAM,MAAM,GAAG,MAAM,+BAAqB,CAAC,SAAS,CAChD,IAAA,uCAAkB,EAAC,OAAO,CAAC,CAC9B,CAAA;QACD,OAAO,MAAM,CAAA;IACjB,CAAC;YAAS,CAAC;QACP,IAAI,YAAY,EAAE,CAAC;YACf,YAAY,CAAC,MAAM,EAAE,CAAA;QACzB,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACI,KAAK,UAAU,eAAe,CACjC,OAAyB;IAEzB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,MAAM,CAAC,GAAG,CAAA;AACrB,CAAC","sourcesContent":["import { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'\n\nimport {\n TrimAudioOptions,\n TrimAudioResult,\n TrimProgressEvent,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\nimport { cleanNativeOptions } from './utils/cleanNativeOptions'\n\n// Create a single emitter instance\nconst emitter = new LegacyEventEmitter(ExpoAudioStreamModule)\n\n/**\n * Trims an audio file based on the provided options.\n *\n * @experimental This API is experimental and not fully optimized for production use.\n * Performance may vary based on file size and device capabilities.\n * Future versions may include breaking changes.\n *\n * @param options Configuration options for the trimming operation\n * @param progressCallback Optional callback to receive progress updates\n * @returns Promise resolving to the trimmed audio file information, including processing time\n */\nexport async function trimAudio(\n options: TrimAudioOptions,\n progressCallback?: (event: TrimProgressEvent) => void\n): Promise<TrimAudioResult> {\n // Validation\n if (!options.fileUri) {\n throw new Error('fileUri is required')\n }\n const mode = options.mode ?? 'single'\n if (mode === 'single') {\n if (\n options.startTimeMs === undefined &&\n options.endTimeMs === undefined\n ) {\n throw new Error(\n 'At least one of startTimeMs or endTimeMs must be provided in single mode'\n )\n }\n } else if (mode === 'keep' || mode === 'remove') {\n if (!options.ranges || options.ranges.length === 0) {\n throw new Error(\n 'ranges must be provided and non-empty for keep or remove modes'\n )\n }\n } else {\n throw new Error(\n `Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`\n )\n }\n\n // Set up progress event listener if callback is provided\n let subscription: EventSubscription | undefined\n if (progressCallback) {\n subscription = emitter.addListener(\n 'TrimProgress',\n (event: TrimProgressEvent) => {\n progressCallback(event)\n }\n )\n }\n\n try {\n // Clean non-serializable/undefined values to avoid Android Kotlin bridge crash\n const result = await ExpoAudioStreamModule.trimAudio(\n cleanNativeOptions(options)\n )\n return result\n } finally {\n if (subscription) {\n subscription.remove()\n }\n }\n}\n\n/**\n * Simplified version of trimAudio that returns only the URI of the trimmed file.\n *\n * @experimental This API is experimental and not fully optimized for production use.\n * Performance may vary based on file size and device capabilities.\n * Future versions may include breaking changes.\n *\n * @param options Configuration options for the trimming operation\n * @returns Promise resolving to the URI of the trimmed audio file\n */\nexport async function trimAudioSimple(\n options: TrimAudioOptions\n): Promise<string> {\n const result = await trimAudio(options)\n return result.uri\n}\n"]}
@@ -1,518 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useAudioRecorder = useAudioRecorder;
7
- // src/useAudioRecorder.ts
8
- const expo_modules_core_1 = require("expo-modules-core");
9
- const react_1 = require("react");
10
- const AudioDeviceManager_1 = require("./AudioDeviceManager");
11
- const ExpoAudioStreamModule_1 = __importDefault(require("./ExpoAudioStreamModule"));
12
- const platformLimitations_1 = require("./constants/platformLimitations");
13
- const events_1 = require("./events");
14
- const cleanNativeOptions_1 = require("./utils/cleanNativeOptions");
15
- const defaultAnalysis = {
16
- segmentDurationMs: 100,
17
- bitDepth: 32,
18
- numberOfChannels: 1,
19
- durationMs: 0,
20
- sampleRate: 44100,
21
- samples: 0,
22
- dataPoints: [],
23
- rmsRange: {
24
- min: Number.POSITIVE_INFINITY,
25
- max: Number.NEGATIVE_INFINITY,
26
- },
27
- amplitudeRange: {
28
- min: Number.POSITIVE_INFINITY,
29
- max: Number.NEGATIVE_INFINITY,
30
- },
31
- extractionTimeMs: 0,
32
- };
33
- function audioRecorderReducer(state, action) {
34
- switch (action.type) {
35
- case 'START':
36
- return {
37
- ...state,
38
- isRecording: true,
39
- isPaused: false,
40
- durationMs: 0,
41
- size: 0,
42
- compression: undefined,
43
- analysisData: defaultAnalysis,
44
- };
45
- case 'STOP':
46
- return {
47
- ...state,
48
- isRecording: false,
49
- isPaused: false,
50
- durationMs: 0,
51
- size: 0,
52
- compression: undefined,
53
- analysisData: undefined,
54
- };
55
- case 'PAUSE':
56
- return { ...state, isPaused: true, isRecording: false };
57
- case 'RESUME':
58
- return { ...state, isPaused: false, isRecording: true };
59
- case 'UPDATE_RECORDING_STATE':
60
- return {
61
- ...state,
62
- isPaused: action.payload.isPaused,
63
- isRecording: action.payload.isRecording,
64
- };
65
- case 'UPDATE_STATUS': {
66
- const newState = {
67
- ...state,
68
- durationMs: action.payload.durationMs,
69
- size: action.payload.size,
70
- compression: action.payload.compression
71
- ? {
72
- size: action.payload.compression.size,
73
- mimeType: action.payload.compression.mimeType,
74
- bitrate: action.payload.compression.bitrate,
75
- format: action.payload.compression.format,
76
- }
77
- : undefined,
78
- };
79
- return newState;
80
- }
81
- case 'UPDATE_ANALYSIS':
82
- return {
83
- ...state,
84
- analysisData: action.payload,
85
- };
86
- default:
87
- return state;
88
- }
89
- }
90
- function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl, } = {}) {
91
- // Initialize AudioDeviceManager with logger (once)
92
- if (logger) {
93
- AudioDeviceManager_1.audioDeviceManager.setLogger(logger);
94
- }
95
- const [state, dispatch] = (0, react_1.useReducer)(audioRecorderReducer, {
96
- isRecording: false,
97
- isPaused: false,
98
- durationMs: 0,
99
- size: 0,
100
- compression: undefined,
101
- analysisData: undefined,
102
- });
103
- const startResultRef = (0, react_1.useRef)(null);
104
- const analysisListenerRef = (0, react_1.useRef)(null);
105
- // analysisRef is the current analysis data (last 10 seconds by default)
106
- const analysisRef = (0, react_1.useRef)({ ...defaultAnalysis });
107
- // fullAnalysisRef is the full analysis data (all data points)
108
- const fullAnalysisRef = (0, react_1.useRef)({
109
- ...defaultAnalysis,
110
- });
111
- // Instantiate the module for web with URLs
112
- const ExpoAudioStream = expo_modules_core_1.Platform.OS === 'web'
113
- ? (0, ExpoAudioStreamModule_1.default)({
114
- audioWorkletUrl,
115
- featuresExtratorUrl,
116
- logger,
117
- })
118
- : ExpoAudioStreamModule_1.default;
119
- const onAudioStreamRef = (0, react_1.useRef)(null);
120
- const stateRef = (0, react_1.useRef)({
121
- isRecording: false,
122
- isPaused: false,
123
- durationMs: 0,
124
- size: 0,
125
- compression: undefined,
126
- });
127
- const recordingConfigRef = (0, react_1.useRef)(null);
128
- // Generate unique instance ID for debugging
129
- const instanceId = (0, react_1.useId)().replace(/:/g, '').slice(0, 5);
130
- const handleAudioAnalysis = (0, react_1.useCallback)(async ({ analysis, visualizationDuration, }) => {
131
- const savedAnalysisData = analysisRef.current || {
132
- ...defaultAnalysis,
133
- };
134
- const maxDuration = visualizationDuration;
135
- logger?.debug(`[handleAudioAnalysis] Received audio analysis: maxDuration=${maxDuration} analysis.dataPoints=${analysis.dataPoints.length} analysisData.dataPoints=${savedAnalysisData.dataPoints.length}`);
136
- // Combine data points
137
- const combinedDataPoints = [
138
- ...savedAnalysisData.dataPoints,
139
- ...analysis.dataPoints,
140
- ];
141
- const fullCombinedDataPoints = [
142
- ...(fullAnalysisRef.current?.dataPoints ?? []),
143
- ...analysis.dataPoints,
144
- ];
145
- // Calculate the new duration
146
- // The number of segments is based on how many segments of segmentDurationMs can fit in visualizationDuration
147
- const numberOfSegments = Math.ceil(visualizationDuration / analysis.segmentDurationMs);
148
- // maxDataPoints should be the number of data points, not milliseconds
149
- const maxDataPoints = numberOfSegments;
150
- logger?.debug(`[handleAudioAnalysis] Combined data points before trimming: numberOfSegments=${numberOfSegments} visualizationDuration=${visualizationDuration} combinedDataPointsLength=${combinedDataPoints.length} vs maxDataPoints=${maxDataPoints}`);
151
- // Trim data points to keep within the maximum number of data points
152
- if (combinedDataPoints.length > maxDataPoints) {
153
- combinedDataPoints.splice(0, combinedDataPoints.length - maxDataPoints);
154
- }
155
- // Keep the full data points
156
- fullAnalysisRef.current = {
157
- ...fullAnalysisRef.current,
158
- dataPoints: fullCombinedDataPoints,
159
- };
160
- fullAnalysisRef.current.durationMs =
161
- fullCombinedDataPoints.length * analysis.segmentDurationMs;
162
- savedAnalysisData.dataPoints = combinedDataPoints;
163
- savedAnalysisData.bitDepth =
164
- analysis.bitDepth || savedAnalysisData.bitDepth;
165
- savedAnalysisData.durationMs =
166
- combinedDataPoints.length * analysis.segmentDurationMs;
167
- // Update amplitude range
168
- const newMin = Math.min(savedAnalysisData.amplitudeRange.min, analysis.amplitudeRange.min);
169
- const newMax = Math.max(savedAnalysisData.amplitudeRange.max, analysis.amplitudeRange.max);
170
- savedAnalysisData.amplitudeRange = {
171
- min: newMin,
172
- max: newMax,
173
- };
174
- fullAnalysisRef.current.amplitudeRange = {
175
- min: newMin,
176
- max: newMax,
177
- };
178
- logger?.debug(`[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`, { dataPoints: savedAnalysisData.dataPoints.length });
179
- // Call the onAudioAnalysis callback if it exists in the recording config
180
- if (recordingConfigRef.current?.onAudioAnalysis) {
181
- recordingConfigRef.current
182
- .onAudioAnalysis(analysis)
183
- .catch((error) => {
184
- logger?.warn(`Error processing audio analysis:`, error);
185
- });
186
- }
187
- // Update the ref
188
- analysisRef.current = savedAnalysisData;
189
- // Dispatch the updated analysis data to state to trigger re-render
190
- dispatch({
191
- type: 'UPDATE_ANALYSIS',
192
- payload: { ...savedAnalysisData },
193
- });
194
- }, [dispatch]);
195
- const handleAudioEvent = (0, react_1.useCallback)(async (eventData) => {
196
- const { fileUri, deltaSize, totalSize, lastEmittedSize, position, streamUuid, encoded, mimeType, buffer, compression, } = eventData;
197
- logger?.debug(`[handleAudioEvent] Received audio event:`, {
198
- fileUri,
199
- deltaSize,
200
- totalSize,
201
- position,
202
- mimeType,
203
- lastEmittedSize,
204
- streamUuid,
205
- encodedLength: encoded?.length,
206
- compression,
207
- });
208
- if (deltaSize === 0) {
209
- // Ignore packet with no data
210
- return;
211
- }
212
- try {
213
- // Coming from native ( ios / android ) otherwise buffer is set
214
- if (expo_modules_core_1.Platform.OS !== 'web') {
215
- // Read the audio file as a base64 string for comparison
216
- if (!encoded) {
217
- logger?.error(`Encoded audio data is missing`);
218
- throw new Error('Encoded audio data is missing');
219
- }
220
- onAudioStreamRef.current?.({
221
- data: encoded,
222
- position,
223
- fileUri,
224
- eventDataSize: deltaSize,
225
- totalSize,
226
- compression: compression && startResultRef.current?.compression
227
- ? {
228
- data: compression.data,
229
- size: compression.totalSize,
230
- mimeType: startResultRef.current.compression
231
- ?.mimeType,
232
- bitrate: startResultRef.current.compression
233
- ?.bitrate,
234
- format: startResultRef.current.compression
235
- ?.format,
236
- }
237
- : undefined,
238
- });
239
- }
240
- else if (buffer) {
241
- // Coming from web
242
- const webEvent = {
243
- data: buffer,
244
- position,
245
- fileUri,
246
- eventDataSize: deltaSize,
247
- totalSize,
248
- compression: compression && startResultRef.current?.compression
249
- ? {
250
- data: compression.data,
251
- size: compression.totalSize,
252
- mimeType: startResultRef.current.compression
253
- ?.mimeType,
254
- bitrate: startResultRef.current.compression
255
- ?.bitrate,
256
- format: startResultRef.current.compression
257
- ?.format,
258
- }
259
- : undefined,
260
- };
261
- onAudioStreamRef.current?.(webEvent);
262
- logger?.debug(`[handleAudioEvent] Audio data sent to onAudioStream`, webEvent);
263
- }
264
- }
265
- catch (error) {
266
- logger?.error(`Error processing audio event:`, error);
267
- }
268
- }, []);
269
- const checkStatus = (0, react_1.useCallback)(async () => {
270
- try {
271
- const status = ExpoAudioStream.status();
272
- logger?.debug(`Status: paused: ${status.isPaused} isRecording: ${status.isRecording} durationMs: ${status.durationMs} size: ${status.size}`, status.compression);
273
- // Only dispatch if values actually changed
274
- if (status.isRecording !== stateRef.current.isRecording ||
275
- status.isPaused !== stateRef.current.isPaused) {
276
- stateRef.current.isRecording = status.isRecording;
277
- stateRef.current.isPaused = status.isPaused;
278
- dispatch({
279
- type: 'UPDATE_RECORDING_STATE',
280
- payload: {
281
- isRecording: status.isRecording,
282
- isPaused: status.isPaused,
283
- },
284
- });
285
- }
286
- if (status.durationMs !== stateRef.current.durationMs ||
287
- status.size !== stateRef.current.size) {
288
- stateRef.current.durationMs = status.durationMs;
289
- stateRef.current.size = status.size;
290
- stateRef.current.compression = status.compression;
291
- dispatch({
292
- type: 'UPDATE_STATUS',
293
- payload: {
294
- durationMs: status.durationMs,
295
- size: status.size,
296
- compression: status.compression,
297
- },
298
- });
299
- }
300
- }
301
- catch (error) {
302
- logger?.error(`Error getting status:`, error);
303
- }
304
- }, [ExpoAudioStream, logger]); // Only depend on ExpoAudioStream and logger
305
- // Update ref when state changes
306
- (0, react_1.useEffect)(() => {
307
- stateRef.current = {
308
- isRecording: state.isRecording,
309
- isPaused: state.isPaused,
310
- durationMs: state.durationMs,
311
- size: state.size,
312
- compression: state.compression,
313
- };
314
- }, [
315
- state.isRecording,
316
- state.isPaused,
317
- state.durationMs,
318
- state.size,
319
- state.compression,
320
- ]);
321
- const startRecording = (0, react_1.useCallback)(async (recordingOptions) => {
322
- // Validate the encoding configuration
323
- const validationResult = (0, platformLimitations_1.validateRecordingConfig)({
324
- encoding: recordingOptions.encoding,
325
- });
326
- // Log warnings if any
327
- if (validationResult.warnings.length > 0) {
328
- validationResult.warnings.forEach((warning) => {
329
- logger?.warn(warning);
330
- });
331
- }
332
- // Update recording options with validated values
333
- const validatedOptions = {
334
- ...recordingOptions,
335
- encoding: validationResult.encoding,
336
- };
337
- recordingConfigRef.current = validatedOptions;
338
- logger?.debug(`start recording with validated config`, validatedOptions);
339
- analysisRef.current = { ...defaultAnalysis }; // Reset analysis data
340
- fullAnalysisRef.current = { ...defaultAnalysis };
341
- const { onAudioStream, onRecordingInterrupted, onAudioAnalysis, ...options } = validatedOptions;
342
- const { enableProcessing } = options;
343
- const maxRecentDataDuration = 10000; // TODO compute maxRecentDataDuration based on screen dimensions
344
- if (typeof onAudioStream === 'function') {
345
- onAudioStreamRef.current = onAudioStream;
346
- }
347
- else {
348
- logger?.warn(`onAudioStream is not a function`, onAudioStream);
349
- onAudioStreamRef.current = null;
350
- }
351
- // Strip undefined values and functions that can't cross the native bridge
352
- const cleanOptions = (0, cleanNativeOptions_1.cleanNativeOptions)(options);
353
- const startResult = await ExpoAudioStream.startRecording(cleanOptions);
354
- dispatch({ type: 'START' });
355
- startResultRef.current = startResult;
356
- if (enableProcessing) {
357
- logger?.debug(`Enabling audio analysis listener`);
358
- const listener = (0, events_1.addAudioAnalysisListener)(async (analysisData) => {
359
- try {
360
- await handleAudioAnalysis({
361
- analysis: analysisData,
362
- visualizationDuration: maxRecentDataDuration,
363
- });
364
- }
365
- catch (error) {
366
- logger?.warn(`Error processing audio analysis:`, error);
367
- }
368
- });
369
- analysisListenerRef.current = listener;
370
- }
371
- return startResult;
372
- }, [handleAudioAnalysis, dispatch]);
373
- const prepareRecording = (0, react_1.useCallback)(async (recordingOptions) => {
374
- recordingConfigRef.current = recordingOptions;
375
- logger?.debug(`preparing recording`, recordingOptions);
376
- analysisRef.current = { ...defaultAnalysis }; // Reset analysis data
377
- fullAnalysisRef.current = { ...defaultAnalysis };
378
- const { onAudioStream, onRecordingInterrupted, onAudioAnalysis, ...options } = recordingOptions;
379
- // Store onAudioStream for later use when recording starts
380
- if (typeof onAudioStream === 'function') {
381
- onAudioStreamRef.current = onAudioStream;
382
- }
383
- else {
384
- logger?.warn(`onAudioStream is not a function`, onAudioStream);
385
- onAudioStreamRef.current = null;
386
- }
387
- // Strip undefined values and functions that can't cross the native bridge
388
- const cleanOptions = (0, cleanNativeOptions_1.cleanNativeOptions)(options);
389
- // Call the native prepareRecording method
390
- await ExpoAudioStream.prepareRecording(cleanOptions);
391
- logger?.debug(`recording prepared successfully`);
392
- }, []);
393
- const stopRecording = (0, react_1.useCallback)(async () => {
394
- logger?.debug(`stoping recording`);
395
- const stopResult = await ExpoAudioStream.stopRecording();
396
- stopResult.analysisData = fullAnalysisRef.current;
397
- if (analysisListenerRef.current) {
398
- analysisListenerRef.current.remove();
399
- analysisListenerRef.current = null;
400
- }
401
- onAudioStreamRef.current = null;
402
- // Note: We deliberately DON'T clear recordingConfigRef here to preserve interruption callback
403
- logger?.debug(`recording stopped`, stopResult);
404
- dispatch({ type: 'STOP' });
405
- return stopResult;
406
- }, [dispatch]);
407
- const pauseRecording = (0, react_1.useCallback)(async () => {
408
- logger?.debug(`pause recording`);
409
- const pauseResult = await ExpoAudioStream.pauseRecording();
410
- dispatch({ type: 'PAUSE' });
411
- return pauseResult;
412
- }, [dispatch]);
413
- const resumeRecording = (0, react_1.useCallback)(async () => {
414
- logger?.debug(`resume recording`);
415
- const resumeResult = await ExpoAudioStream.resumeRecording();
416
- dispatch({ type: 'RESUME' });
417
- return resumeResult;
418
- }, [dispatch]);
419
- (0, react_1.useEffect)(() => {
420
- let intervalId;
421
- if (state.isRecording || state.isPaused) {
422
- // Immediately check status when starting
423
- checkStatus();
424
- // Start interval
425
- intervalId = setInterval(checkStatus, 1000);
426
- }
427
- return () => {
428
- if (intervalId) {
429
- clearInterval(intervalId);
430
- intervalId = undefined;
431
- }
432
- };
433
- }, [checkStatus, state.isRecording, state.isPaused]);
434
- (0, react_1.useEffect)(() => {
435
- logger?.debug(`Registering audio event listener`);
436
- const subscribeAudio = (0, events_1.addAudioEventListener)(handleAudioEvent);
437
- logger?.debug(`Subscribed to audio event listener and analysis listener`, {
438
- subscribeAudio,
439
- });
440
- return () => {
441
- logger?.debug(`Removing audio event listener`);
442
- subscribeAudio.remove();
443
- };
444
- }, [handleAudioEvent, handleAudioAnalysis]);
445
- (0, react_1.useEffect)(() => {
446
- // Add event subscription for recording interruptions
447
- logger?.debug(`Setting up recording interruption listener [${instanceId}]`);
448
- const subscription = (0, events_1.addRecordingInterruptionListener)((event) => {
449
- logger?.debug(`[${instanceId}] Received recording interruption event:`, event);
450
- // Handle device disconnection for UI updates
451
- if (event.reason === 'deviceDisconnected') {
452
- logger?.debug(`[${instanceId}] Device disconnected - temporarily hiding last device from UI`);
453
- // Get current device list before the native layer updates
454
- const currentDevices = AudioDeviceManager_1.audioDeviceManager.getRawDevices();
455
- // Wait a moment for native layer to update, then compare
456
- setTimeout(async () => {
457
- try {
458
- // Get updated devices without notifying yet
459
- const updatedDevices = await AudioDeviceManager_1.audioDeviceManager.getAvailableDevices({
460
- refresh: true,
461
- });
462
- // Find missing devices by comparing lists
463
- const missingDevices = currentDevices.filter((oldDevice) => !updatedDevices.some((newDevice) => newDevice.id === oldDevice.id));
464
- if (missingDevices.length > 0) {
465
- // Mark all missing devices as disconnected (silently)
466
- missingDevices.forEach((missingDevice) => {
467
- logger?.debug(`[${instanceId}] Confirmed disconnected device: ${missingDevice.name} (${missingDevice.id})`);
468
- AudioDeviceManager_1.audioDeviceManager.markDeviceAsDisconnected(missingDevice.id, false);
469
- });
470
- }
471
- // Notify listeners once with the final filtered state
472
- AudioDeviceManager_1.audioDeviceManager.notifyListeners();
473
- }
474
- catch (error) {
475
- logger?.warn(`[${instanceId}] Error in delayed device disconnection handling:`, error);
476
- }
477
- }, 500); // 500ms delay to let native layer update
478
- }
479
- else if (event.reason === 'deviceConnected') {
480
- // Device reconnected - force refresh to show it immediately
481
- logger?.debug(`[${instanceId}] Device connected, forcing refresh`);
482
- AudioDeviceManager_1.audioDeviceManager.forceRefreshDevices();
483
- }
484
- // Check if we have a callback configured
485
- logger?.debug(`[${instanceId}] recordingConfigRef.current exists:`, !!recordingConfigRef.current);
486
- if (recordingConfigRef.current?.onRecordingInterrupted) {
487
- try {
488
- logger?.debug(`[${instanceId}] Calling recording interruption callback`);
489
- recordingConfigRef.current.onRecordingInterrupted(event);
490
- }
491
- catch (error) {
492
- logger?.error(`[${instanceId}] Error in recording interruption callback:`, error);
493
- }
494
- }
495
- else {
496
- logger?.debug(`[${instanceId}] No recording interruption callback configured`);
497
- }
498
- });
499
- return () => {
500
- logger?.debug(`[${instanceId}] Removing recording interruption listener`);
501
- subscription.remove();
502
- };
503
- }, [instanceId, logger]); // Include instanceId and logger in dependencies
504
- return {
505
- prepareRecording,
506
- startRecording,
507
- stopRecording,
508
- pauseRecording,
509
- resumeRecording,
510
- isPaused: state.isPaused,
511
- isRecording: state.isRecording,
512
- durationMs: state.durationMs,
513
- size: state.size,
514
- compression: state.compression,
515
- analysisData: state.analysisData,
516
- };
517
- }
518
- //# sourceMappingURL=useAudioRecorder.js.map