@siteed/expo-audio-studio 2.18.5 → 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 -493
  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 -666
  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 -2352
  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 -1013
  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,704 +0,0 @@
1
- // src/ExpoAudioStreamModule.web.ts
2
- import { LegacyEventEmitter } from 'expo-modules-core';
3
- import { WebRecorder } from './WebRecorder.web';
4
- import { encodingToBitDepth } from './utils/encodingToBitDepth';
5
- export class ExpoAudioStreamWeb extends LegacyEventEmitter {
6
- customRecorder;
7
- audioChunks;
8
- isRecording;
9
- isPaused;
10
- recordingStartTime;
11
- pausedTime;
12
- currentDurationMs;
13
- currentSize;
14
- currentInterval;
15
- currentIntervalAnalysis;
16
- lastEmittedSize;
17
- lastEmittedTime;
18
- lastEmittedCompressionSize;
19
- lastEmittedAnalysisTime;
20
- streamUuid;
21
- extension = 'wav'; // Default extension is 'wav'
22
- recordingConfig;
23
- bitDepth; // Bit depth of the audio
24
- audioWorkletUrl;
25
- featuresExtratorUrl;
26
- logger;
27
- latestPosition = 0;
28
- totalCompressedSize = 0;
29
- maxBufferSize;
30
- eventCallback;
31
- constructor({ audioWorkletUrl, featuresExtratorUrl, logger, maxBufferSize = 100, // Default to storing last 100 chunks (1 chunk = 0.5 seconds)
32
- }) {
33
- const mockNativeModule = {
34
- addListener: () => { },
35
- removeListeners: () => { },
36
- };
37
- super(mockNativeModule); // Pass the mock native module to the parent class
38
- this.logger = logger;
39
- this.customRecorder = null;
40
- this.audioChunks = [];
41
- this.isRecording = false;
42
- this.isPaused = false;
43
- this.recordingStartTime = 0;
44
- this.pausedTime = 0;
45
- this.currentDurationMs = 0;
46
- this.currentSize = 0;
47
- this.bitDepth = 32; // Default
48
- this.currentInterval = 1000; // Default interval in ms
49
- this.currentIntervalAnalysis = 500; // Default analysis interval in ms
50
- this.lastEmittedSize = 0;
51
- this.lastEmittedTime = 0;
52
- this.latestPosition = 0;
53
- this.lastEmittedCompressionSize = 0;
54
- this.lastEmittedAnalysisTime = 0;
55
- this.streamUuid = null; // Initialize UUID on first recording start
56
- this.audioWorkletUrl = audioWorkletUrl;
57
- this.featuresExtratorUrl = featuresExtratorUrl;
58
- this.maxBufferSize = maxBufferSize;
59
- }
60
- // Utility to handle user media stream
61
- async getMediaStream() {
62
- try {
63
- this.logger?.debug('Requesting user media (microphone)...');
64
- // First check if the browser supports the necessary audio APIs
65
- if (!navigator?.mediaDevices?.getUserMedia) {
66
- this.logger?.error('Browser does not support mediaDevices.getUserMedia');
67
- throw new Error('Browser does not support audio recording');
68
- }
69
- // Get media with detailed audio constraints for better diagnostics
70
- const constraints = {
71
- audio: {
72
- echoCancellation: true,
73
- noiseSuppression: true,
74
- autoGainControl: true,
75
- // Add deviceId constraint if specified
76
- ...(this.recordingConfig?.deviceId
77
- ? {
78
- deviceId: {
79
- exact: this.recordingConfig.deviceId,
80
- },
81
- }
82
- : {}),
83
- },
84
- };
85
- this.logger?.debug('Media constraints:', constraints);
86
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
87
- // Get detailed info about the audio track for debugging
88
- const audioTracks = stream.getAudioTracks();
89
- if (audioTracks.length > 0) {
90
- const track = audioTracks[0];
91
- const settings = track.getSettings();
92
- this.logger?.debug('Audio track obtained:', {
93
- label: track.label,
94
- id: track.id,
95
- enabled: track.enabled,
96
- muted: track.muted,
97
- readyState: track.readyState,
98
- settings,
99
- });
100
- }
101
- else {
102
- this.logger?.warn('Stream has no audio tracks!');
103
- }
104
- return stream;
105
- }
106
- catch (error) {
107
- this.logger?.error('Failed to get media stream:', error);
108
- throw error;
109
- }
110
- }
111
- // Prepare recording with options
112
- async prepareRecording(recordingConfig = {}) {
113
- if (this.isRecording) {
114
- this.logger?.warn('Cannot prepare: Recording is already in progress');
115
- return false;
116
- }
117
- try {
118
- // Check permissions and initialize basic settings
119
- await this.getMediaStream().then((stream) => {
120
- // Just verify we can access the microphone by getting a stream, then release it
121
- stream.getTracks().forEach((track) => track.stop());
122
- });
123
- this.bitDepth = encodingToBitDepth({
124
- encoding: recordingConfig.encoding ?? 'pcm_32bit',
125
- });
126
- // Store recording configuration for later use
127
- this.recordingConfig = recordingConfig;
128
- // Use custom filename if provided, otherwise fallback to timestamp
129
- if (recordingConfig.filename) {
130
- // Remove any existing extension from the filename
131
- this.streamUuid = recordingConfig.filename.replace(/\.[^/.]+$/, '');
132
- }
133
- else {
134
- this.streamUuid = Date.now().toString();
135
- }
136
- this.logger?.debug('Recording preparation completed successfully');
137
- return true;
138
- }
139
- catch (error) {
140
- this.logger?.error('Error preparing recording:', error);
141
- return false;
142
- }
143
- }
144
- // Start recording with options
145
- async startRecording(recordingConfig = {}) {
146
- if (this.isRecording) {
147
- throw new Error('Recording is already in progress');
148
- }
149
- // If we haven't prepared or have different settings, prepare now
150
- if (!this.recordingConfig ||
151
- this.recordingConfig.sampleRate !== recordingConfig.sampleRate ||
152
- this.recordingConfig.channels !== recordingConfig.channels ||
153
- this.recordingConfig.encoding !== recordingConfig.encoding) {
154
- await this.prepareRecording(recordingConfig);
155
- }
156
- else {
157
- this.logger?.debug('Using previously prepared recording configuration');
158
- }
159
- // Save recording config for reference
160
- this.recordingConfig = recordingConfig;
161
- const audioContext = new (window.AudioContext ||
162
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
163
- // @ts-ignore - Allow webkitAudioContext for Safari
164
- window.webkitAudioContext)();
165
- const stream = await this.getMediaStream();
166
- const source = audioContext.createMediaStreamSource(stream);
167
- this.customRecorder = new WebRecorder({
168
- logger: this.logger,
169
- audioContext,
170
- source,
171
- recordingConfig,
172
- emitAudioEventCallback: this.customRecorderEventCallback.bind(this),
173
- emitAudioAnalysisCallback: this.customRecorderAnalysisCallback.bind(this),
174
- onInterruption: this.handleRecordingInterruption.bind(this),
175
- });
176
- await this.customRecorder.init();
177
- this.customRecorder.start();
178
- this.isRecording = true;
179
- this.recordingStartTime = Date.now();
180
- this.pausedTime = 0;
181
- this.isPaused = false;
182
- this.lastEmittedSize = 0;
183
- this.lastEmittedTime = 0;
184
- this.lastEmittedCompressionSize = 0;
185
- this.currentInterval = recordingConfig.interval ?? 1000;
186
- this.currentIntervalAnalysis = recordingConfig.intervalAnalysis ?? 500;
187
- this.lastEmittedAnalysisTime = Date.now();
188
- // Use custom filename if provided, otherwise fallback to timestamp
189
- if (recordingConfig.filename) {
190
- // Remove any existing extension from the filename
191
- this.streamUuid = recordingConfig.filename.replace(/\.[^/.]+$/, '');
192
- }
193
- else {
194
- this.streamUuid = Date.now().toString();
195
- }
196
- const fileUri = `${this.streamUuid}.${this.extension}`;
197
- const streamConfig = {
198
- fileUri,
199
- mimeType: `audio/${this.extension}`,
200
- bitDepth: this.bitDepth,
201
- channels: recordingConfig.channels ?? 1,
202
- sampleRate: recordingConfig.sampleRate ?? 44100,
203
- compression: recordingConfig.output?.compressed?.enabled
204
- ? {
205
- ...recordingConfig.output.compressed,
206
- bitrate: recordingConfig.output.compressed.bitrate ?? 128000,
207
- size: 0,
208
- mimeType: 'audio/webm',
209
- format: recordingConfig.output.compressed.format ?? 'opus',
210
- compressedFileUri: '',
211
- }
212
- : undefined,
213
- };
214
- return streamConfig;
215
- }
216
- /**
217
- * Centralized handler for recording interruptions
218
- */
219
- handleRecordingInterruption(event) {
220
- this.logger?.debug(`Received recording interruption: ${event.reason}`);
221
- // Update local state if the interruption should pause recording
222
- if (event.isPaused) {
223
- this.isPaused = true;
224
- // If this is a device disconnection, handle according to behavior setting
225
- if (event.reason === 'deviceDisconnected') {
226
- this.pausedTime = Date.now();
227
- // Check if we should try fallback to another device
228
- if (this.recordingConfig?.deviceDisconnectionBehavior ===
229
- 'fallback') {
230
- this.logger?.debug('Device disconnected with fallback behavior - attempting to switch to default device');
231
- // Try to restart with default device
232
- this.handleDeviceFallback().catch((error) => {
233
- // If fallback fails, emit warning
234
- this.logger?.error('Device fallback failed:', error);
235
- this.emit('onRecordingInterrupted', {
236
- reason: 'deviceSwitchFailed',
237
- isPaused: true,
238
- timestamp: Date.now(),
239
- message: 'Failed to switch to fallback device. Recording paused.',
240
- });
241
- });
242
- }
243
- else {
244
- // Just warn about disconnection if fallback not enabled
245
- this.logger?.warn('Device disconnected - recording paused automatically');
246
- this.emit('onRecordingInterrupted', event);
247
- }
248
- }
249
- else {
250
- // For other interruption types, just emit the event
251
- this.emit('onRecordingInterrupted', event);
252
- }
253
- }
254
- else {
255
- // If not causing a pause, just forward the event
256
- this.emit('onRecordingInterrupted', event);
257
- }
258
- }
259
- /**
260
- * Handler for audio events from the WebRecorder
261
- */
262
- customRecorderEventCallback({ data, position, compression, }) {
263
- // Keep only the latest chunks based on maxBufferSize
264
- this.audioChunks.push(new Float32Array(data));
265
- if (this.audioChunks.length > this.maxBufferSize) {
266
- this.audioChunks.shift(); // Remove oldest chunk
267
- }
268
- this.currentSize += data.byteLength;
269
- this.emitAudioEvent({ data, position, compression });
270
- this.lastEmittedTime = Date.now();
271
- this.lastEmittedSize = this.currentSize;
272
- this.lastEmittedCompressionSize = compression?.size ?? 0;
273
- }
274
- /**
275
- * Handler for audio analysis events from the WebRecorder
276
- */
277
- customRecorderAnalysisCallback(audioAnalysisData) {
278
- this.emit('AudioAnalysis', audioAnalysisData);
279
- }
280
- // Get recording duration
281
- getRecordingDuration() {
282
- if (!this.isRecording) {
283
- return 0;
284
- }
285
- return this.currentDurationMs;
286
- }
287
- emitAudioEvent({ data, position, compression }) {
288
- const fileUri = `${this.streamUuid}.${this.extension}`;
289
- if (compression?.size) {
290
- this.lastEmittedCompressionSize = compression.size;
291
- this.totalCompressedSize = compression.totalSize;
292
- }
293
- // Update latest position for tracking
294
- this.latestPosition = position;
295
- // Calculate duration of this chunk in ms
296
- const sampleRate = this.recordingConfig?.sampleRate || 44100;
297
- const chunkDurationMs = (data.length / sampleRate) * 1000;
298
- // Handle duration calculation
299
- if (this.customRecorder?.isFirstChunkAfterSwitch) {
300
- this.logger?.debug(`Processing first chunk after device switch, duration preserved at ${this.currentDurationMs}ms`);
301
- this.customRecorder.isFirstChunkAfterSwitch = false;
302
- }
303
- else {
304
- this.currentDurationMs += chunkDurationMs;
305
- }
306
- const audioEventPayload = {
307
- fileUri,
308
- mimeType: `audio/${this.extension}`,
309
- lastEmittedSize: this.lastEmittedSize,
310
- deltaSize: data.byteLength,
311
- position,
312
- totalSize: this.currentSize,
313
- buffer: data,
314
- streamUuid: this.streamUuid ?? '',
315
- compression: compression
316
- ? {
317
- data: compression?.data,
318
- totalSize: this.totalCompressedSize,
319
- eventDataSize: compression?.size ?? 0,
320
- position,
321
- }
322
- : undefined,
323
- };
324
- this.emit('AudioData', audioEventPayload);
325
- }
326
- // Stop recording
327
- async stopRecording() {
328
- if (!this.customRecorder) {
329
- throw new Error('Recorder is not initialized');
330
- }
331
- this.logger?.debug('Starting stop process');
332
- try {
333
- const { compressedBlob, uncompressedBlob } = await this.customRecorder.stop();
334
- this.isRecording = false;
335
- this.isPaused = false;
336
- let compression;
337
- let fileUri = `${this.streamUuid}.${this.extension}`;
338
- let mimeType = `audio/${this.extension}`;
339
- // Handle both compressed and uncompressed blobs according to new output configuration
340
- const primaryEnabled = this.recordingConfig?.output?.primary?.enabled ?? true;
341
- const compressedEnabled = this.recordingConfig?.output?.compressed?.enabled ?? false;
342
- // Process compressed blob if available and enabled
343
- if (compressedBlob && compressedEnabled) {
344
- const compressedUri = URL.createObjectURL(compressedBlob);
345
- const compressedInfo = {
346
- compressedFileUri: compressedUri,
347
- size: compressedBlob.size,
348
- mimeType: 'audio/webm',
349
- format: this.recordingConfig?.output?.compressed?.format ??
350
- 'opus',
351
- bitrate: this.recordingConfig?.output?.compressed?.bitrate ??
352
- 128000,
353
- };
354
- // Store compression info
355
- compression = compressedInfo;
356
- // If primary is disabled, use compressed as main file
357
- if (!primaryEnabled) {
358
- this.logger?.debug('Using compressed audio as primary output (primary disabled)');
359
- fileUri = compressedUri;
360
- mimeType = 'audio/webm';
361
- }
362
- }
363
- // Process uncompressed WAV if available and primary is enabled
364
- if (uncompressedBlob && primaryEnabled) {
365
- const wavUri = URL.createObjectURL(uncompressedBlob);
366
- fileUri = wavUri;
367
- mimeType = 'audio/wav';
368
- }
369
- else if (!primaryEnabled && !compressedEnabled) {
370
- // No outputs enabled - streaming only mode
371
- this.logger?.debug('No outputs enabled - streaming only mode');
372
- fileUri = '';
373
- mimeType = 'audio/wav';
374
- }
375
- // Use the stored streamUuid for the final filename
376
- const filename = fileUri
377
- ? `${this.streamUuid}.${this.extension}`
378
- : 'stream-only';
379
- const result = {
380
- fileUri,
381
- filename,
382
- bitDepth: this.bitDepth,
383
- createdAt: this.recordingStartTime,
384
- channels: this.recordingConfig?.channels ?? 1,
385
- sampleRate: this.recordingConfig?.sampleRate ?? 44100,
386
- durationMs: this.currentDurationMs,
387
- size: primaryEnabled ? this.currentSize : 0,
388
- mimeType,
389
- compression,
390
- };
391
- // Reset after creating the result
392
- this.streamUuid = null;
393
- // Reset recording state variables to prepare for next recording
394
- this.currentDurationMs = 0;
395
- this.currentSize = 0;
396
- this.lastEmittedSize = 0;
397
- this.totalCompressedSize = 0;
398
- this.lastEmittedCompressionSize = 0;
399
- this.audioChunks = [];
400
- return result;
401
- }
402
- catch (error) {
403
- this.logger?.error('Error stopping recording:', error);
404
- throw error;
405
- }
406
- }
407
- // Pause recording
408
- async pauseRecording() {
409
- if (!this.isRecording) {
410
- throw new Error('Recording is not active');
411
- }
412
- if (this.isPaused) {
413
- this.logger?.debug('Recording already paused, skipping');
414
- return;
415
- }
416
- try {
417
- if (this.customRecorder) {
418
- this.customRecorder.pause();
419
- }
420
- this.isPaused = true;
421
- this.pausedTime = Date.now();
422
- }
423
- catch (error) {
424
- this.logger?.error('Error in pauseRecording', error);
425
- // Even if the pause operation failed, make sure our state is consistent
426
- this.isPaused = true;
427
- this.pausedTime = Date.now();
428
- }
429
- }
430
- // Resume recording
431
- async resumeRecording() {
432
- if (!this.isPaused) {
433
- throw new Error('Recording is not paused');
434
- }
435
- this.logger?.debug('Resuming recording', {
436
- deviceDisconnectionBehavior: this.recordingConfig?.deviceDisconnectionBehavior,
437
- isDeviceDisconnected: this.customRecorder?.isDeviceDisconnected,
438
- });
439
- try {
440
- // If we have no recorder, or if the device is disconnected, always attempt fallback
441
- if (!this.customRecorder ||
442
- this.customRecorder.isDeviceDisconnected) {
443
- this.logger?.debug('No recorder exists or device disconnected - attempting fallback on resume');
444
- await this.handleDeviceFallback();
445
- // handleDeviceFallback will manage resuming if successful, or emit error if failed.
446
- return;
447
- }
448
- // Normal resume path - device is still connected
449
- this.customRecorder.resume();
450
- this.isPaused = false;
451
- // Adjust the recording start time to account for the pause duration
452
- const pauseDuration = Date.now() - this.pausedTime;
453
- this.recordingStartTime += pauseDuration;
454
- this.pausedTime = 0;
455
- this.emit('onRecordingInterrupted', {
456
- reason: 'userResumed',
457
- isPaused: false,
458
- timestamp: Date.now(),
459
- });
460
- }
461
- catch (error) {
462
- this.logger?.error('Resume failed:', error);
463
- // Fallback to emitting a general failure if resume fails unexpectedly
464
- this.emit('onRecordingInterrupted', {
465
- reason: 'resumeFailed', // Use a more specific reason
466
- isPaused: true, // Remain paused if resume fails
467
- timestamp: Date.now(),
468
- message: 'Failed to resume recording. Please stop and start again.',
469
- });
470
- }
471
- }
472
- // Get current status
473
- status() {
474
- const durationMs = this.getRecordingDuration();
475
- const status = {
476
- isRecording: this.isRecording,
477
- isPaused: this.isPaused,
478
- durationMs,
479
- size: this.currentSize,
480
- interval: this.currentInterval,
481
- intervalAnalysis: this.currentIntervalAnalysis,
482
- mimeType: `audio/${this.extension}`,
483
- compression: this.recordingConfig?.output?.compressed?.enabled
484
- ? {
485
- size: this.totalCompressedSize,
486
- mimeType: 'audio/webm',
487
- format: this.recordingConfig.output.compressed.format ??
488
- 'opus',
489
- bitrate: this.recordingConfig.output.compressed.bitrate ??
490
- 128000,
491
- compressedFileUri: `${this.streamUuid}.webm`,
492
- }
493
- : undefined,
494
- };
495
- return status;
496
- }
497
- /**
498
- * Handles device fallback when the current device is disconnected
499
- */
500
- async handleDeviceFallback() {
501
- this.logger?.debug('Starting device fallback procedure');
502
- if (!this.isRecording) {
503
- return false;
504
- }
505
- try {
506
- // Save important state before switching
507
- const currentPosition = this.latestPosition;
508
- const existingAudioChunks = [...this.audioChunks];
509
- // Save compressed chunks if available
510
- let compressedChunks = [];
511
- if (this.customRecorder) {
512
- try {
513
- compressedChunks = this.customRecorder.getCompressedChunks();
514
- }
515
- catch (err) {
516
- this.logger?.warn('Failed to get compressed chunks:', err);
517
- }
518
- }
519
- // Save the current counter value for continuity
520
- let currentDataPointCounter = 0;
521
- if (this.customRecorder) {
522
- currentDataPointCounter =
523
- this.customRecorder.getDataPointCounter();
524
- }
525
- // Clean up existing recorder
526
- if (this.customRecorder) {
527
- try {
528
- this.customRecorder.cleanup();
529
- }
530
- catch (cleanupError) {
531
- this.logger?.warn('Error during cleanup:', cleanupError);
532
- }
533
- }
534
- // Keep recording state true but mark as paused
535
- this.isPaused = true;
536
- this.pausedTime = Date.now();
537
- // Store current size and other stats
538
- const previousTotalSize = this.currentSize;
539
- const previousLastEmittedSize = this.lastEmittedSize;
540
- const previousCompressedSize = this.totalCompressedSize;
541
- // Try to get a fallback device
542
- const fallbackDeviceInfo = await this.getFallbackDevice();
543
- if (!fallbackDeviceInfo) {
544
- this.emit('onRecordingInterrupted', {
545
- reason: 'deviceSwitchFailed',
546
- isPaused: true,
547
- timestamp: Date.now(),
548
- message: 'Failed to switch to fallback device. Recording paused.',
549
- });
550
- return false;
551
- }
552
- // Start recording with the new device
553
- try {
554
- const stream = await this.requestPermissionsAndGetUserMedia(fallbackDeviceInfo.deviceId);
555
- const audioContext = new (window.AudioContext ||
556
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
557
- // @ts-ignore - Allow webkitAudioContext for Safari
558
- window.webkitAudioContext)();
559
- const source = audioContext.createMediaStreamSource(stream);
560
- // Create a new recorder with the fallback device
561
- this.customRecorder = new WebRecorder({
562
- logger: this.logger,
563
- audioContext,
564
- source,
565
- recordingConfig: this.recordingConfig || {},
566
- emitAudioEventCallback: this.customRecorderEventCallback.bind(this),
567
- emitAudioAnalysisCallback: this.customRecorderAnalysisCallback.bind(this),
568
- onInterruption: this.handleRecordingInterruption.bind(this),
569
- });
570
- await this.customRecorder.init();
571
- // Set the initial position to continue from the previous device
572
- this.customRecorder.setPosition(currentPosition);
573
- // Reset the data point counter to continue from where the previous device left off
574
- if (currentDataPointCounter > 0) {
575
- this.customRecorder.resetDataPointCounter(currentDataPointCounter);
576
- }
577
- // Prepare the recorder to handle the device switch properly
578
- this.customRecorder.prepareForDeviceSwitch();
579
- // Restore the existing audio chunks
580
- if (existingAudioChunks.length > 0) {
581
- this.audioChunks = existingAudioChunks;
582
- }
583
- // Restore compressed chunks if available
584
- if (compressedChunks.length > 0) {
585
- this.customRecorder.setCompressedChunks(compressedChunks);
586
- }
587
- // Start the new recorder while preserving counters
588
- this.customRecorder.start(true);
589
- // Update recording state
590
- this.isPaused = false;
591
- this.recordingStartTime = Date.now();
592
- // Restore size counters to maintain continuity
593
- this.currentSize = previousTotalSize;
594
- this.lastEmittedSize = previousLastEmittedSize;
595
- this.totalCompressedSize = previousCompressedSize;
596
- // Notify that we switched to a fallback device
597
- if (this.eventCallback) {
598
- this.eventCallback({
599
- type: 'deviceFallback',
600
- device: fallbackDeviceInfo.deviceId,
601
- timestamp: new Date(),
602
- });
603
- }
604
- return true;
605
- }
606
- catch (error) {
607
- this.logger?.error('Failed to start recording with fallback device', error);
608
- this.isPaused = true;
609
- this.emit('onRecordingInterrupted', {
610
- reason: 'deviceSwitchFailed',
611
- isPaused: true,
612
- timestamp: Date.now(),
613
- message: 'Failed to switch to fallback device. Recording paused.',
614
- });
615
- return false;
616
- }
617
- }
618
- catch (error) {
619
- this.logger?.error('Failed to use fallback device', error);
620
- this.isPaused = true;
621
- this.emit('onRecordingInterrupted', {
622
- reason: 'deviceSwitchFailed',
623
- isPaused: true,
624
- timestamp: Date.now(),
625
- message: 'Failed to switch to fallback device. Recording paused.',
626
- });
627
- return false;
628
- }
629
- }
630
- /**
631
- * Attempts to get a fallback audio device
632
- */
633
- async getFallbackDevice() {
634
- try {
635
- // Get list of available audio input devices
636
- const devices = await navigator.mediaDevices.enumerateDevices();
637
- const audioInputDevices = devices.filter((device) => device.kind === 'audioinput');
638
- if (audioInputDevices.length === 0) {
639
- return null;
640
- }
641
- // Try to find a device that's not the current one
642
- if (this.customRecorder) {
643
- try {
644
- // Use mediaDevices.enumerateDevices to find the current active device
645
- const tracks = navigator.mediaDevices
646
- .getUserMedia({ audio: true })
647
- .then((stream) => {
648
- const track = stream.getAudioTracks()[0];
649
- return track ? track.label : '';
650
- })
651
- .catch(() => '');
652
- const currentTrackLabel = await tracks;
653
- if (currentTrackLabel) {
654
- // Find a device with a different label
655
- const differentDevice = audioInputDevices.find((device) => device.label &&
656
- device.label !== currentTrackLabel);
657
- if (differentDevice) {
658
- return differentDevice;
659
- }
660
- }
661
- }
662
- catch (err) {
663
- this.logger?.warn('Error determining current device, using default', err);
664
- }
665
- }
666
- // Return the first available device (default device)
667
- return audioInputDevices[0];
668
- }
669
- catch (error) {
670
- this.logger?.error('Error finding fallback device:', error);
671
- return null;
672
- }
673
- }
674
- /**
675
- * Gets user media with specific device ID
676
- */
677
- async requestPermissionsAndGetUserMedia(deviceId) {
678
- try {
679
- // Request the specific device
680
- return await navigator.mediaDevices.getUserMedia({
681
- audio: {
682
- deviceId: { exact: deviceId },
683
- },
684
- });
685
- }
686
- catch (error) {
687
- this.logger?.error(`Failed to get media for device ${deviceId}`, error);
688
- // Try with default constraints as fallback
689
- return await navigator.mediaDevices.getUserMedia({ audio: true });
690
- }
691
- }
692
- init(options) {
693
- try {
694
- this.logger = options?.logger;
695
- this.eventCallback = options?.eventCallback;
696
- return Promise.resolve();
697
- }
698
- catch (error) {
699
- this.logger?.error('Error initializing ExpoAudioStream', error);
700
- return Promise.reject(error);
701
- }
702
- }
703
- }
704
- //# sourceMappingURL=ExpoAudioStream.web.js.map