@siteed/audio-studio 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 (375) hide show
  1. package/CHANGELOG.md +535 -0
  2. package/LICENSE +21 -0
  3. package/README.md +167 -0
  4. package/android/build.gradle +143 -0
  5. package/android/src/androidTest/assets/chorus.wav +0 -0
  6. package/android/src/androidTest/assets/jfk.wav +0 -0
  7. package/android/src/androidTest/assets/osr_us_000_0010_8k.wav +0 -0
  8. package/android/src/androidTest/assets/recorder_hello_world.wav +0 -0
  9. package/android/src/androidTest/java/net/siteed/audiostudio/AudioProcessorInstrumentedTest.kt +197 -0
  10. package/android/src/androidTest/java/net/siteed/audiostudio/AudioRecorderInstrumentedTest.kt +541 -0
  11. package/android/src/androidTest/java/net/siteed/audiostudio/AudioRecorderPerformanceInstrumentedTest.kt +234 -0
  12. package/android/src/androidTest/java/net/siteed/audiostudio/integration/AudioFocusStrategyIntegrationTest.kt +332 -0
  13. package/android/src/androidTest/java/net/siteed/audiostudio/integration/BufferDurationIntegrationTest.kt +324 -0
  14. package/android/src/androidTest/java/net/siteed/audiostudio/integration/CompressedOnlyOutputTest.kt +253 -0
  15. package/android/src/androidTest/java/net/siteed/audiostudio/integration/DeviceDisconnectionFallbackTest.kt +218 -0
  16. package/android/src/androidTest/java/net/siteed/audiostudio/integration/EventEmissionIntervalTest.kt +120 -0
  17. package/android/src/androidTest/java/net/siteed/audiostudio/integration/M4aFormatTest.kt +345 -0
  18. package/android/src/androidTest/java/net/siteed/audiostudio/integration/OutputControlIntegrationTest.kt +340 -0
  19. package/android/src/androidTest/java/net/siteed/audiostudio/integration/PcmStreamingDurationTest.kt +252 -0
  20. package/android/src/androidTest/java/net/siteed/audiostudio/integration/README.md +95 -0
  21. package/android/src/androidTest/java/net/siteed/audiostudio/integration/run_integration_tests.sh +43 -0
  22. package/android/src/main/AndroidManifest.xml +30 -0
  23. package/android/src/main/CMakeLists.txt +29 -0
  24. package/android/src/main/java/net/siteed/audiostudio/AudioAnalysisData.kt +188 -0
  25. package/android/src/main/java/net/siteed/audiostudio/AudioDataEncoder.kt +9 -0
  26. package/android/src/main/java/net/siteed/audiostudio/AudioDeviceManager.kt +1741 -0
  27. package/android/src/main/java/net/siteed/audiostudio/AudioFeaturesNative.kt +26 -0
  28. package/android/src/main/java/net/siteed/audiostudio/AudioFileHandler.kt +136 -0
  29. package/android/src/main/java/net/siteed/audiostudio/AudioFormatUtils.kt +354 -0
  30. package/android/src/main/java/net/siteed/audiostudio/AudioNotificationsManager.kt +439 -0
  31. package/android/src/main/java/net/siteed/audiostudio/AudioProcessor.kt +2237 -0
  32. package/android/src/main/java/net/siteed/audiostudio/AudioRecorderManager.kt +2163 -0
  33. package/android/src/main/java/net/siteed/audiostudio/AudioRecordingService.kt +167 -0
  34. package/android/src/main/java/net/siteed/audiostudio/AudioStudioModule.kt +1112 -0
  35. package/android/src/main/java/net/siteed/audiostudio/AudioTrimmer.kt +1099 -0
  36. package/android/src/main/java/net/siteed/audiostudio/Constants.kt +37 -0
  37. package/android/src/main/java/net/siteed/audiostudio/EventSender.kt +7 -0
  38. package/android/src/main/java/net/siteed/audiostudio/FFT.kt +100 -0
  39. package/android/src/main/java/net/siteed/audiostudio/Features.kt +98 -0
  40. package/android/src/main/java/net/siteed/audiostudio/LogUtils.kt +93 -0
  41. package/android/src/main/java/net/siteed/audiostudio/MelSpectrogramNative.kt +36 -0
  42. package/android/src/main/java/net/siteed/audiostudio/NotificationConfig.kt +72 -0
  43. package/android/src/main/java/net/siteed/audiostudio/PermissionUtils.kt +68 -0
  44. package/android/src/main/java/net/siteed/audiostudio/RecordingActionReceiver.kt +59 -0
  45. package/android/src/main/java/net/siteed/audiostudio/RecordingConfig.kt +259 -0
  46. package/android/src/main/java/net/siteed/audiostudio/WaveformConfig.kt +19 -0
  47. package/android/src/main/java/net/siteed/audiostudio/WaveformRenderer.kt +159 -0
  48. package/android/src/main/jni/AudioFeaturesJNI.cpp +152 -0
  49. package/android/src/main/jni/MelSpectrogramJNI.cpp +165 -0
  50. package/android/src/main/res/drawable/ic_default_action_icon.xml +16 -0
  51. package/android/src/main/res/drawable/ic_microphone.xml +13 -0
  52. package/android/src/main/res/drawable/ic_pause.xml +10 -0
  53. package/android/src/main/res/drawable/ic_play.xml +10 -0
  54. package/android/src/main/res/drawable/ic_stop.xml +10 -0
  55. package/android/src/main/res/layout/notification_recording.xml +37 -0
  56. package/android/src/test/java/net/siteed/audiostudio/AudioFileHandlerTest.kt +279 -0
  57. package/android/src/test/java/net/siteed/audiostudio/AudioFocusStrategyTest.kt +249 -0
  58. package/android/src/test/java/net/siteed/audiostudio/AudioFormatTest.kt +151 -0
  59. package/android/src/test/java/net/siteed/audiostudio/AudioFormatUtilsTest.kt +273 -0
  60. package/android/src/test/java/net/siteed/audiostudio/DeviceDisconnectionFallbackUnitTest.kt +140 -0
  61. package/android/src/test/resources/chorus.wav +0 -0
  62. package/android/src/test/resources/generate_test_audio.py +94 -0
  63. package/android/src/test/resources/jfk.wav +0 -0
  64. package/android/src/test/resources/osr_us_000_0010_8k.wav +0 -0
  65. package/android/src/test/resources/recorder_hello_world.wav +0 -0
  66. package/app.plugin.js +3 -0
  67. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js +4 -0
  68. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  69. package/build/cjs/AudioAnalysis/audioFeaturesWasm.js +164 -0
  70. package/build/cjs/AudioAnalysis/audioFeaturesWasm.js.map +1 -0
  71. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js +213 -0
  72. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  73. package/build/cjs/AudioAnalysis/extractAudioData.js +21 -0
  74. package/build/cjs/AudioAnalysis/extractAudioData.js.map +1 -0
  75. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js +90 -0
  76. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
  77. package/build/cjs/AudioAnalysis/extractPreview.js +28 -0
  78. package/build/cjs/AudioAnalysis/extractPreview.js.map +1 -0
  79. package/build/cjs/AudioAnalysis/extractWaveform.js +18 -0
  80. package/build/cjs/AudioAnalysis/extractWaveform.js.map +1 -0
  81. package/build/cjs/AudioAnalysis/melSpectrogramWasm.js +149 -0
  82. package/build/cjs/AudioAnalysis/melSpectrogramWasm.js.map +1 -0
  83. package/build/cjs/AudioDeviceManager.js +688 -0
  84. package/build/cjs/AudioDeviceManager.js.map +1 -0
  85. package/build/cjs/AudioRecorder.provider.js +78 -0
  86. package/build/cjs/AudioRecorder.provider.js.map +1 -0
  87. package/build/cjs/AudioStudio.native.js +8 -0
  88. package/build/cjs/AudioStudio.native.js.map +1 -0
  89. package/build/cjs/AudioStudio.types.js +11 -0
  90. package/build/cjs/AudioStudio.types.js.map +1 -0
  91. package/build/cjs/AudioStudio.web.js +708 -0
  92. package/build/cjs/AudioStudio.web.js.map +1 -0
  93. package/build/cjs/AudioStudioModule.js +718 -0
  94. package/build/cjs/AudioStudioModule.js.map +1 -0
  95. package/build/cjs/WebRecorder.web.js +865 -0
  96. package/build/cjs/WebRecorder.web.js.map +1 -0
  97. package/build/cjs/constants/platformLimitations.js +99 -0
  98. package/build/cjs/constants/platformLimitations.js.map +1 -0
  99. package/build/cjs/constants.js +20 -0
  100. package/build/cjs/constants.js.map +1 -0
  101. package/build/cjs/events.js +29 -0
  102. package/build/cjs/events.js.map +1 -0
  103. package/build/cjs/hooks/useAudioDevices.js +179 -0
  104. package/build/cjs/hooks/useAudioDevices.js.map +1 -0
  105. package/build/cjs/index.js +64 -0
  106. package/build/cjs/index.js.map +1 -0
  107. package/build/cjs/trimAudio.js +76 -0
  108. package/build/cjs/trimAudio.js.map +1 -0
  109. package/build/cjs/useAudioRecorder.js +535 -0
  110. package/build/cjs/useAudioRecorder.js.map +1 -0
  111. package/build/cjs/utils/BlobFix.js +502 -0
  112. package/build/cjs/utils/BlobFix.js.map +1 -0
  113. package/build/cjs/utils/audioProcessing.js +136 -0
  114. package/build/cjs/utils/audioProcessing.js.map +1 -0
  115. package/build/cjs/utils/cleanNativeOptions.js +22 -0
  116. package/build/cjs/utils/cleanNativeOptions.js.map +1 -0
  117. package/build/cjs/utils/concatenateBuffers.js +25 -0
  118. package/build/cjs/utils/concatenateBuffers.js.map +1 -0
  119. package/build/cjs/utils/convertPCMToFloat32.js +124 -0
  120. package/build/cjs/utils/convertPCMToFloat32.js.map +1 -0
  121. package/build/cjs/utils/crc32.js +52 -0
  122. package/build/cjs/utils/crc32.js.map +1 -0
  123. package/build/cjs/utils/encodingToBitDepth.js +17 -0
  124. package/build/cjs/utils/encodingToBitDepth.js.map +1 -0
  125. package/build/cjs/utils/getWavFileInfo.js +96 -0
  126. package/build/cjs/utils/getWavFileInfo.js.map +1 -0
  127. package/build/cjs/utils/writeWavHeader.js +88 -0
  128. package/build/cjs/utils/writeWavHeader.js.map +1 -0
  129. package/build/cjs/workers/InlineFeaturesExtractor.web.js +294 -0
  130. package/build/cjs/workers/InlineFeaturesExtractor.web.js.map +1 -0
  131. package/build/cjs/workers/inlineAudioWebWorker.web.js +190 -0
  132. package/build/cjs/workers/inlineAudioWebWorker.web.js.map +1 -0
  133. package/build/cjs/workers/wasmGlueString.web.js +27 -0
  134. package/build/cjs/workers/wasmGlueString.web.js.map +1 -0
  135. package/build/esm/AudioAnalysis/AudioAnalysis.types.js +3 -0
  136. package/build/esm/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  137. package/build/esm/AudioAnalysis/audioFeaturesWasm.js +126 -0
  138. package/build/esm/AudioAnalysis/audioFeaturesWasm.js.map +1 -0
  139. package/build/esm/AudioAnalysis/extractAudioAnalysis.js +205 -0
  140. package/build/esm/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  141. package/build/esm/AudioAnalysis/extractAudioData.js +14 -0
  142. package/build/esm/AudioAnalysis/extractAudioData.js.map +1 -0
  143. package/build/esm/AudioAnalysis/extractMelSpectrogram.js +86 -0
  144. package/build/esm/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
  145. package/build/esm/AudioAnalysis/extractPreview.js +25 -0
  146. package/build/esm/AudioAnalysis/extractPreview.js.map +1 -0
  147. package/build/esm/AudioAnalysis/extractWaveform.js +11 -0
  148. package/build/esm/AudioAnalysis/extractWaveform.js.map +1 -0
  149. package/build/esm/AudioAnalysis/melSpectrogramWasm.js +111 -0
  150. package/build/esm/AudioAnalysis/melSpectrogramWasm.js.map +1 -0
  151. package/build/esm/AudioDeviceManager.js +681 -0
  152. package/build/esm/AudioDeviceManager.js.map +1 -0
  153. package/build/esm/AudioRecorder.provider.js +40 -0
  154. package/build/esm/AudioRecorder.provider.js.map +1 -0
  155. package/build/esm/AudioStudio.native.js +6 -0
  156. package/build/esm/AudioStudio.native.js.map +1 -0
  157. package/build/esm/AudioStudio.types.js +8 -0
  158. package/build/esm/AudioStudio.types.js.map +1 -0
  159. package/build/esm/AudioStudio.web.js +704 -0
  160. package/build/esm/AudioStudio.web.js.map +1 -0
  161. package/build/esm/AudioStudioModule.js +713 -0
  162. package/build/esm/AudioStudioModule.js.map +1 -0
  163. package/build/esm/WebRecorder.web.js +861 -0
  164. package/build/esm/WebRecorder.web.js.map +1 -0
  165. package/build/esm/constants/platformLimitations.js +90 -0
  166. package/build/esm/constants/platformLimitations.js.map +1 -0
  167. package/build/esm/constants.js +17 -0
  168. package/build/esm/constants.js.map +1 -0
  169. package/build/esm/events.js +21 -0
  170. package/build/esm/events.js.map +1 -0
  171. package/build/esm/hooks/useAudioDevices.js +176 -0
  172. package/build/esm/hooks/useAudioDevices.js.map +1 -0
  173. package/build/esm/index.js +23 -0
  174. package/build/esm/index.js.map +1 -0
  175. package/build/esm/trimAudio.js +69 -0
  176. package/build/esm/trimAudio.js.map +1 -0
  177. package/build/esm/useAudioRecorder.js +529 -0
  178. package/build/esm/useAudioRecorder.js.map +1 -0
  179. package/build/esm/utils/BlobFix.js +498 -0
  180. package/build/esm/utils/BlobFix.js.map +1 -0
  181. package/build/esm/utils/audioProcessing.js +133 -0
  182. package/build/esm/utils/audioProcessing.js.map +1 -0
  183. package/build/esm/utils/cleanNativeOptions.js +19 -0
  184. package/build/esm/utils/cleanNativeOptions.js.map +1 -0
  185. package/build/esm/utils/concatenateBuffers.js +21 -0
  186. package/build/esm/utils/concatenateBuffers.js.map +1 -0
  187. package/build/esm/utils/convertPCMToFloat32.js +120 -0
  188. package/build/esm/utils/convertPCMToFloat32.js.map +1 -0
  189. package/build/esm/utils/crc32.js +50 -0
  190. package/build/esm/utils/crc32.js.map +1 -0
  191. package/build/esm/utils/encodingToBitDepth.js +13 -0
  192. package/build/esm/utils/encodingToBitDepth.js.map +1 -0
  193. package/build/esm/utils/getWavFileInfo.js +92 -0
  194. package/build/esm/utils/getWavFileInfo.js.map +1 -0
  195. package/build/esm/utils/writeWavHeader.js +84 -0
  196. package/build/esm/utils/writeWavHeader.js.map +1 -0
  197. package/build/esm/workers/InlineFeaturesExtractor.web.js +291 -0
  198. package/build/esm/workers/InlineFeaturesExtractor.web.js.map +1 -0
  199. package/build/esm/workers/inlineAudioWebWorker.web.js +187 -0
  200. package/build/esm/workers/inlineAudioWebWorker.web.js.map +1 -0
  201. package/build/esm/workers/wasmGlueString.web.js +24 -0
  202. package/build/esm/workers/wasmGlueString.web.js.map +1 -0
  203. package/build/types/AudioAnalysis/AudioAnalysis.types.d.ts +198 -0
  204. package/build/types/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
  205. package/build/types/AudioAnalysis/audioFeaturesWasm.d.ts +24 -0
  206. package/build/types/AudioAnalysis/audioFeaturesWasm.d.ts.map +1 -0
  207. package/build/types/AudioAnalysis/extractAudioAnalysis.d.ts +74 -0
  208. package/build/types/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
  209. package/build/types/AudioAnalysis/extractAudioData.d.ts +3 -0
  210. package/build/types/AudioAnalysis/extractAudioData.d.ts.map +1 -0
  211. package/build/types/AudioAnalysis/extractMelSpectrogram.d.ts +20 -0
  212. package/build/types/AudioAnalysis/extractMelSpectrogram.d.ts.map +1 -0
  213. package/build/types/AudioAnalysis/extractPreview.d.ts +11 -0
  214. package/build/types/AudioAnalysis/extractPreview.d.ts.map +1 -0
  215. package/build/types/AudioAnalysis/extractWaveform.d.ts +8 -0
  216. package/build/types/AudioAnalysis/extractWaveform.d.ts.map +1 -0
  217. package/build/types/AudioAnalysis/melSpectrogramWasm.d.ts +16 -0
  218. package/build/types/AudioAnalysis/melSpectrogramWasm.d.ts.map +1 -0
  219. package/build/types/AudioDeviceManager.d.ts +187 -0
  220. package/build/types/AudioDeviceManager.d.ts.map +1 -0
  221. package/build/types/AudioRecorder.provider.d.ts +11 -0
  222. package/build/types/AudioRecorder.provider.d.ts.map +1 -0
  223. package/build/types/AudioStudio.native.d.ts +3 -0
  224. package/build/types/AudioStudio.native.d.ts.map +1 -0
  225. package/build/types/AudioStudio.types.d.ts +760 -0
  226. package/build/types/AudioStudio.types.d.ts.map +1 -0
  227. package/build/types/AudioStudio.web.d.ts +96 -0
  228. package/build/types/AudioStudio.web.d.ts.map +1 -0
  229. package/build/types/AudioStudioModule.d.ts +3 -0
  230. package/build/types/AudioStudioModule.d.ts.map +1 -0
  231. package/build/types/WebRecorder.web.d.ts +208 -0
  232. package/build/types/WebRecorder.web.d.ts.map +1 -0
  233. package/build/types/constants/platformLimitations.d.ts +40 -0
  234. package/build/types/constants/platformLimitations.d.ts.map +1 -0
  235. package/build/types/constants.d.ts +14 -0
  236. package/build/types/constants.d.ts.map +1 -0
  237. package/build/types/events.d.ts +29 -0
  238. package/build/types/events.d.ts.map +1 -0
  239. package/build/types/hooks/useAudioDevices.d.ts +15 -0
  240. package/build/types/hooks/useAudioDevices.d.ts.map +1 -0
  241. package/build/types/index.d.ts +21 -0
  242. package/build/types/index.d.ts.map +1 -0
  243. package/build/types/trimAudio.d.ts +25 -0
  244. package/build/types/trimAudio.d.ts.map +1 -0
  245. package/build/types/useAudioRecorder.d.ts +22 -0
  246. package/build/types/useAudioRecorder.d.ts.map +1 -0
  247. package/build/types/utils/BlobFix.d.ts +9 -0
  248. package/build/types/utils/BlobFix.d.ts.map +1 -0
  249. package/build/types/utils/audioProcessing.d.ts +24 -0
  250. package/build/types/utils/audioProcessing.d.ts.map +1 -0
  251. package/build/types/utils/cleanNativeOptions.d.ts +15 -0
  252. package/build/types/utils/cleanNativeOptions.d.ts.map +1 -0
  253. package/build/types/utils/concatenateBuffers.d.ts +8 -0
  254. package/build/types/utils/concatenateBuffers.d.ts.map +1 -0
  255. package/build/types/utils/convertPCMToFloat32.d.ts +13 -0
  256. package/build/types/utils/convertPCMToFloat32.d.ts.map +1 -0
  257. package/build/types/utils/crc32.d.ts +7 -0
  258. package/build/types/utils/crc32.d.ts.map +1 -0
  259. package/build/types/utils/encodingToBitDepth.d.ts +5 -0
  260. package/build/types/utils/encodingToBitDepth.d.ts.map +1 -0
  261. package/build/types/utils/getWavFileInfo.d.ts +26 -0
  262. package/build/types/utils/getWavFileInfo.d.ts.map +1 -0
  263. package/build/types/utils/writeWavHeader.d.ts +34 -0
  264. package/build/types/utils/writeWavHeader.d.ts.map +1 -0
  265. package/build/types/workers/InlineFeaturesExtractor.web.d.ts +2 -0
  266. package/build/types/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
  267. package/build/types/workers/inlineAudioWebWorker.web.d.ts +2 -0
  268. package/build/types/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
  269. package/build/types/workers/wasmGlueString.web.d.ts +2 -0
  270. package/build/types/workers/wasmGlueString.web.d.ts.map +1 -0
  271. package/cpp/AudioFeatures.cpp +274 -0
  272. package/cpp/AudioFeatures.h +85 -0
  273. package/cpp/AudioFeaturesBridge.cpp +146 -0
  274. package/cpp/AudioFeaturesBridge.h +47 -0
  275. package/cpp/MelSpectrogram.cpp +227 -0
  276. package/cpp/MelSpectrogram.h +82 -0
  277. package/cpp/MelSpectrogramBridge.cpp +112 -0
  278. package/cpp/MelSpectrogramBridge.h +33 -0
  279. package/cpp/kiss_fft/COPYING +11 -0
  280. package/cpp/kiss_fft/_kiss_fft_guts.h +167 -0
  281. package/cpp/kiss_fft/kiss_fft.c +424 -0
  282. package/cpp/kiss_fft/kiss_fft.h +160 -0
  283. package/cpp/kiss_fft/kiss_fft_log.h +36 -0
  284. package/cpp/kiss_fft/kiss_fftr.c +155 -0
  285. package/cpp/kiss_fft/kiss_fftr.h +54 -0
  286. package/expo-module.config.json +10 -0
  287. package/ios/AudioAnalysisData.swift +74 -0
  288. package/ios/AudioDeviceManager.swift +670 -0
  289. package/ios/AudioFeaturesWrapper.h +21 -0
  290. package/ios/AudioFeaturesWrapper.mm +63 -0
  291. package/ios/AudioNotificationManager.swift +154 -0
  292. package/ios/AudioProcessingHelpers.swift +797 -0
  293. package/ios/AudioProcessor.swift +1191 -0
  294. package/ios/AudioStreamError.swift +7 -0
  295. package/ios/AudioStreamManager.swift +2369 -0
  296. package/ios/AudioStreamManagerDelegate.swift +16 -0
  297. package/ios/AudioStudio.podspec +39 -0
  298. package/ios/AudioStudioModule.swift +1111 -0
  299. package/ios/AudioStudioTests/AudioFileHandlerTests.swift +338 -0
  300. package/ios/AudioStudioTests/AudioFormatUtilsTests.swift +331 -0
  301. package/ios/AudioStudioTests/AudioTestHelpers.swift +130 -0
  302. package/ios/AudioStudioTests/CompressedOnlyOutputTests.swift +294 -0
  303. package/ios/AudioStudioTests/EventEmissionIntervalTests.swift +105 -0
  304. package/ios/AudioStudioTests/Info.plist +22 -0
  305. package/ios/AudioStudioTests/README.md +39 -0
  306. package/ios/AudioStudioTests/SimpleAudioTest.swift +98 -0
  307. package/ios/AudioStudioTests/TestAudioGenerator.swift +75 -0
  308. package/ios/DataPoint.swift +54 -0
  309. package/ios/DecodingConfig.swift +59 -0
  310. package/ios/FFT.swift +62 -0
  311. package/ios/Features.swift +95 -0
  312. package/ios/ISSUE_IOS.md +68 -0
  313. package/ios/Logger.swift +39 -0
  314. package/ios/MelSpectrogramWrapper.h +30 -0
  315. package/ios/MelSpectrogramWrapper.mm +97 -0
  316. package/ios/NotificationExtension.swift +15 -0
  317. package/ios/RecordingResult.swift +22 -0
  318. package/ios/RecordingSettings.swift +311 -0
  319. package/ios/WaveformExtractor.swift +105 -0
  320. package/ios/tests/README.md +41 -0
  321. package/ios/tests/integration/buffer_and_fallback_test.swift +178 -0
  322. package/ios/tests/integration/buffer_duration_test.swift +185 -0
  323. package/ios/tests/integration/compressed_only_output_test.swift +271 -0
  324. package/ios/tests/integration/output_control_test.swift +322 -0
  325. package/ios/tests/integration/run_integration_tests.sh +37 -0
  326. package/ios/tests/opus_support_test_macos.swift +154 -0
  327. package/ios/tests/standalone/audio_processing_test.swift +144 -0
  328. package/ios/tests/standalone/audio_recording_test.swift +277 -0
  329. package/ios/tests/standalone/audio_streaming_test.swift +249 -0
  330. package/ios/tests/standalone/standalone_test.swift +144 -0
  331. package/package.json +146 -0
  332. package/plugin/build/index.cjs +194 -0
  333. package/plugin/build/index.d.cts +22 -0
  334. package/plugin/build/index.js +194 -0
  335. package/plugin/src/index.ts +285 -0
  336. package/plugin/tsconfig.json +10 -0
  337. package/plugin/tsconfig.tsbuildinfo +1 -0
  338. package/prebuilt/wasm/mel-spectrogram.js +18 -0
  339. package/src/AudioAnalysis/AudioAnalysis.types.ts +226 -0
  340. package/src/AudioAnalysis/audio-features-wasm.d.ts +37 -0
  341. package/src/AudioAnalysis/audioFeaturesWasm.ts +200 -0
  342. package/src/AudioAnalysis/extractAudioAnalysis.ts +350 -0
  343. package/src/AudioAnalysis/extractAudioData.ts +17 -0
  344. package/src/AudioAnalysis/extractMelSpectrogram.ts +140 -0
  345. package/src/AudioAnalysis/extractPreview.ts +34 -0
  346. package/src/AudioAnalysis/extractWaveform.ts +22 -0
  347. package/src/AudioAnalysis/mel-spectrogram-wasm.d.ts +48 -0
  348. package/src/AudioAnalysis/melSpectrogramWasm.ts +179 -0
  349. package/src/AudioDeviceManager.ts +800 -0
  350. package/src/AudioRecorder.provider.tsx +57 -0
  351. package/src/AudioStudio.native.ts +6 -0
  352. package/src/AudioStudio.types.ts +899 -0
  353. package/src/AudioStudio.web.ts +911 -0
  354. package/src/AudioStudioModule.ts +984 -0
  355. package/src/WebRecorder.web.ts +1114 -0
  356. package/src/constants/platformLimitations.ts +118 -0
  357. package/src/constants.ts +21 -0
  358. package/src/events.ts +63 -0
  359. package/src/hooks/useAudioDevices.ts +213 -0
  360. package/src/index.ts +67 -0
  361. package/src/trimAudio.ts +94 -0
  362. package/src/types/crc-32.d.ts +9 -0
  363. package/src/useAudioRecorder.tsx +784 -0
  364. package/src/utils/BlobFix.ts +561 -0
  365. package/src/utils/audioProcessing.ts +205 -0
  366. package/src/utils/cleanNativeOptions.ts +18 -0
  367. package/src/utils/concatenateBuffers.ts +24 -0
  368. package/src/utils/convertPCMToFloat32.ts +170 -0
  369. package/src/utils/crc32.ts +59 -0
  370. package/src/utils/encodingToBitDepth.ts +18 -0
  371. package/src/utils/getWavFileInfo.ts +132 -0
  372. package/src/utils/writeWavHeader.ts +115 -0
  373. package/src/workers/InlineFeaturesExtractor.web.tsx +291 -0
  374. package/src/workers/inlineAudioWebWorker.web.tsx +186 -0
  375. package/src/workers/wasmGlueString.web.ts +23 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebRecorder.web.js","sourceRoot":"","sources":["../../src/WebRecorder.web.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAG/C,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GACtB,MAAM,oCAAoC,CAAA;AAM3C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAA;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAmBzD,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAC/B,MAAM,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,CAAA;QACxE,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,2BAA2B,QAAQ,YAAY,CAAC,CAAA;QACtE,CAAC;IACL,CAAC;IAED;;;OAGG;IACH,WAAW;QACP,OAAO,IAAI,CAAC,QAAQ,CAAA;IACxB,CAAC;IAED;;;OAGG;IACH,mBAAmB;QACf,OAAO,CAAC,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAA;IACrC,CAAC;IAED;;;OAGG;IACH,mBAAmB,CAAC,MAAc;QAC9B,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,MAAM,EAAE,KAAK,CACd,UAAU,MAAM,CAAC,MAAM,yCAAyC,CACnE,CAAA;YACD,IAAI,CAAC,gBAAgB,GAAG,CAAC,GAAG,MAAM,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAA;YAC7D,cAAc;YACd,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAC9C,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,EAClC,CAAC,CACJ,CAAA;QACL,CAAC;IACL,CAAC;CACJ","sourcesContent":["// packages/audio-studio/src/WebRecorder.web.ts\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n initMelStreamingWasm,\n computeMelFrameWasm,\n} from './AudioAnalysis/melSpectrogramWasm'\nimport { ConsoleLike, RecordingConfig } from './AudioStudio.types'\nimport {\n EmitAudioAnalysisFunction,\n EmitAudioEventFunction,\n} from './AudioStudio.web'\nimport { encodingToBitDepth } from './utils/encodingToBitDepth'\nimport { writeWavHeader } from './utils/writeWavHeader'\nimport { InlineFeaturesExtractor } from './workers/InlineFeaturesExtractor.web'\nimport { InlineAudioWebWorker } from './workers/inlineAudioWebWorker.web'\nimport { wasmGlueJs } from './workers/wasmGlueString.web'\n\ninterface AudioWorkletEvent {\n data: {\n command: string\n recordedData?: Float32Array\n sampleRate?: number\n position?: number\n message?: string // For debug messages\n }\n}\n\ninterface AudioFeaturesEvent {\n data: {\n command: string\n result: AudioAnalysis\n }\n}\n\nconst DEFAULT_WEB_BITDEPTH = 32\nconst DEFAULT_SEGMENT_DURATION_MS = 100\nconst DEFAULT_WEB_INTERVAL = 500\nconst DEFAULT_WEB_NUMBER_OF_CHANNELS = 1\n\nconst TAG = 'WebRecorder'\n\nexport class WebRecorder {\n public audioContext: AudioContext\n private audioWorkletNode!: AudioWorkletNode\n private featureExtractorWorker?: Worker\n private featureExtractorWorkerUrl?: string\n private source: MediaStreamAudioSourceNode\n private emitAudioEventCallback: EmitAudioEventFunction\n private emitAudioAnalysisCallback: EmitAudioAnalysisFunction\n private config: RecordingConfig\n private position: number = 0\n private numberOfChannels: number // Number of audio channels\n private bitDepth: number // Bit depth of the audio\n private exportBitDepth: number // Bit depth of the audio\n private audioAnalysisData: AudioAnalysis // Keep updating the full audio analysis data with latest events\n private readonly logger?: ConsoleLike\n private compressedMediaRecorder: MediaRecorder | null = null\n private compressedChunks: Blob[] = []\n private compressedSize: number = 0\n private pendingCompressedChunk: Blob | null = null\n private dataPointIdCounter: number = 0 // Add this property to track the counter\n private deviceDisconnectionHandler: (() => void) | null = null\n private readonly mediaStream: MediaStream | null = null\n private readonly onInterruptionCallback?: (event: {\n reason: string\n isPaused: boolean\n timestamp: number\n }) => void\n private _isDeviceDisconnected: boolean = false\n private pcmData: Float32Array | null = null // Store original PCM data\n private totalSampleCount: number = 0\n private melWasmReady: boolean = false\n private melWasmInitPromise: Promise<void> | null = null\n private melPendingChunks: { chunk: Float32Array; sampleRate: number }[] = []\n private pendingMelFrames: (number[] | null)[] = [] // Queued mel frames to attach to datapoints\n\n /**\n * Flag to indicate whether this is the first audio chunk after a device switch\n * Used to maintain proper duration counting\n */\n public isFirstChunkAfterSwitch: boolean = false\n\n /**\n * Gets whether the recording device has been disconnected\n */\n get isDeviceDisconnected(): boolean {\n return this._isDeviceDisconnected\n }\n\n /**\n * Initializes a new WebRecorder instance for audio recording and processing\n * @param audioContext - The AudioContext to use for recording\n * @param source - The MediaStreamAudioSourceNode providing the audio input\n * @param recordingConfig - Configuration options for the recording\n * @param emitAudioEventCallback - Callback function for audio data events\n * @param emitAudioAnalysisCallback - Callback function for audio analysis events\n * @param onInterruption - Callback for recording interruptions\n * @param logger - Optional logger for debugging information\n */\n constructor({\n audioContext,\n source,\n recordingConfig,\n emitAudioEventCallback,\n emitAudioAnalysisCallback,\n onInterruption,\n logger,\n }: {\n audioContext: AudioContext\n source: MediaStreamAudioSourceNode\n recordingConfig: RecordingConfig\n emitAudioEventCallback: EmitAudioEventFunction\n emitAudioAnalysisCallback: EmitAudioAnalysisFunction\n onInterruption?: (event: {\n reason: string\n isPaused: boolean\n timestamp: number\n }) => void\n logger?: ConsoleLike\n }) {\n this.audioContext = audioContext\n this.source = source\n this.emitAudioEventCallback = emitAudioEventCallback\n this.emitAudioAnalysisCallback = emitAudioAnalysisCallback\n this.config = recordingConfig\n this.logger = logger\n\n const audioContextFormat = this.checkAudioContextFormat({\n sampleRate: this.audioContext.sampleRate,\n })\n this.logger?.debug('Initialized WebRecorder with config:', {\n sampleRate: audioContextFormat.sampleRate,\n bitDepth: audioContextFormat.bitDepth,\n numberOfChannels: audioContextFormat.numberOfChannels,\n })\n\n this.bitDepth = audioContextFormat.bitDepth\n this.numberOfChannels =\n audioContextFormat.numberOfChannels ||\n DEFAULT_WEB_NUMBER_OF_CHANNELS // Default to 1 if not available\n this.exportBitDepth =\n encodingToBitDepth({\n encoding: recordingConfig.encoding ?? 'pcm_32bit',\n }) ||\n audioContextFormat.bitDepth ||\n DEFAULT_WEB_BITDEPTH\n\n this.audioAnalysisData = {\n amplitudeRange: { min: 0, max: 0 },\n rmsRange: { min: 0, max: 0 },\n dataPoints: [],\n durationMs: 0,\n samples: 0,\n bitDepth: this.bitDepth,\n numberOfChannels: this.numberOfChannels,\n sampleRate: this.config.sampleRate || this.audioContext.sampleRate,\n segmentDurationMs:\n this.config.segmentDurationMs ?? DEFAULT_SEGMENT_DURATION_MS, // Default to 100ms segments\n extractionTimeMs: 0,\n }\n\n if (recordingConfig.enableProcessing) {\n this.initFeatureExtractorWorker()\n if (recordingConfig.features?.melSpectrogram) {\n const sr =\n this.config.sampleRate || this.audioContext.sampleRate\n const segMs =\n this.config.segmentDurationMs ?? DEFAULT_SEGMENT_DURATION_MS\n const windowSamples = Math.floor((sr * segMs) / 1000)\n this.melWasmInitPromise = initMelStreamingWasm(\n sr,\n 128,\n 2048,\n windowSamples,\n windowSamples\n )\n .then(() => {\n this.melWasmReady = true\n this.logger?.log('Mel WASM streaming processor ready')\n // Process any chunks that arrived during init\n for (const pending of this.melPendingChunks) {\n this.computeMelFrames(\n pending.chunk,\n pending.sampleRate\n )\n }\n this.melPendingChunks = []\n })\n .catch((err) => {\n console.error(`[${TAG}] Failed to init mel WASM:`, err)\n this.melWasmInitPromise = null\n this.melPendingChunks = []\n })\n }\n }\n\n // Initialize compressed recording if enabled\n if (recordingConfig.output?.compressed?.enabled) {\n this.initializeCompressedRecorder()\n }\n\n this.mediaStream = source.mediaStream\n this.onInterruptionCallback = onInterruption\n\n // Setup device disconnection detection\n this.setupDeviceDisconnectionDetection()\n }\n\n /**\n * Initializes the audio worklet using an inline script\n * Creates and connects the audio processing pipeline\n */\n async init() {\n try {\n // Create and use inline audio worklet\n const blob = new Blob([InlineAudioWebWorker], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n await this.audioContext.audioWorklet.addModule(url)\n\n this.audioWorkletNode = new AudioWorkletNode(\n this.audioContext,\n 'recorder-processor'\n )\n\n this.audioWorkletNode.port.onmessage = async (\n event: AudioWorkletEvent\n ) => {\n const command = event.data.command\n if (command === 'debug') {\n this.logger?.debug(`[AudioWorklet] ${event.data.message}`)\n return\n }\n\n if (command !== 'newData') return\n\n const pcmBufferFloat = event.data.recordedData\n if (!pcmBufferFloat) {\n this.logger?.warn('Received empty audio buffer', event)\n return\n }\n\n // Process data in smaller chunks and emit immediately\n const sampleRate =\n event.data.sampleRate ?? this.audioContext.sampleRate\n // Use chunk size from config interval or default to 2 seconds\n const intervalMs = this.config.interval ?? DEFAULT_WEB_INTERVAL\n const chunkSize = Math.floor(sampleRate * (intervalMs / 1000))\n const duration = pcmBufferFloat.length / sampleRate\n\n // Use incoming position if provided by worklet, otherwise use our tracked position\n const incomingPosition =\n typeof event.data.position === 'number'\n ? event.data.position\n : this.position\n\n // Simple position tracking for logging (no duplicate filtering)\n this.logger?.debug(\n `Audio chunk: position=${incomingPosition.toFixed(3)}s, size=${pcmBufferFloat.length}`\n )\n\n // Calculate bytes per sample based on bit depth\n const bytesPerSample = this.bitDepth / 8\n\n // Emit chunks without storing them\n for (let i = 0; i < pcmBufferFloat.length; i += chunkSize) {\n const chunk = pcmBufferFloat.slice(i, i + chunkSize)\n const chunkPosition = incomingPosition + i / sampleRate\n\n // Calculate byte positions and samples\n const startPosition = Math.floor(i * bytesPerSample)\n const endPosition = Math.floor(\n (i + chunk.length) * bytesPerSample\n )\n const samples = chunk.length // Number of samples in this chunk\n\n // Only store PCM data if primary output is enabled\n const shouldStoreUncompressed =\n this.config.output?.primary?.enabled ?? true\n\n // Store PCM chunks when needed - this is for the final WAV file\n if (shouldStoreUncompressed) {\n // Store the original Float32Array data for later WAV creation\n this.appendPcmData(chunk)\n this.totalSampleCount += chunk.length\n }\n\n this.computeMelFrames(chunk, sampleRate)\n\n // Process features if enabled\n if (\n this.config.enableProcessing &&\n this.featureExtractorWorker\n ) {\n this.featureExtractorWorker.postMessage({\n command: 'process',\n channelData: chunk,\n sampleRate,\n segmentDurationMs:\n this.config.segmentDurationMs ??\n DEFAULT_SEGMENT_DURATION_MS, // Default to 100ms\n bitDepth: this.bitDepth,\n fullAudioDurationMs: chunkPosition * 1000,\n numberOfChannels: this.numberOfChannels,\n features: this.config.features,\n intervalAnalysis: this.config.intervalAnalysis,\n startPosition,\n endPosition,\n samples,\n })\n }\n\n // Prepare compression data if available\n const compression = this.pendingCompressedChunk\n ? {\n data: this.pendingCompressedChunk,\n size: this.pendingCompressedChunk.size,\n totalSize: this.compressedSize,\n mimeType: 'audio/webm',\n format:\n this.config.output?.compressed?.format ??\n 'opus',\n bitrate:\n this.config.output?.compressed?.bitrate ??\n 128000,\n }\n : undefined\n\n // Emit chunk immediately - whether compressed or not\n this.emitAudioEventCallback({\n data: chunk,\n position: chunkPosition,\n compression,\n })\n\n // Reset pending compressed chunk after we've used it\n this.pendingCompressedChunk = null\n }\n\n // Update our position based on the worklet's position if provided\n this.position = incomingPosition + duration\n }\n\n // Ensure we use all relevant settings from config\n const recordSampleRate = this.audioContext.sampleRate\n const exportSampleRate =\n this.config.sampleRate ?? this.audioContext.sampleRate\n const channels = this.config.channels ?? this.numberOfChannels\n const interval = this.config.interval ?? DEFAULT_WEB_INTERVAL\n\n this.logger?.debug(`WebRecorder initialized with config:`, {\n recordSampleRate,\n exportSampleRate,\n bitDepth: this.bitDepth,\n exportBitDepth: this.exportBitDepth,\n channels,\n interval,\n position: this.position,\n deviceId: this.config.deviceId ?? 'default',\n compression: this.config.output?.compressed\n ? {\n enabled: this.config.output.compressed.enabled,\n format: this.config.output.compressed.format,\n bitrate: this.config.output.compressed.bitrate,\n }\n : 'disabled',\n })\n\n // Initialize the worklet with all settings from config\n this.audioWorkletNode.port.postMessage({\n command: 'init',\n recordSampleRate,\n exportSampleRate,\n bitDepth: this.bitDepth,\n exportBitDepth: this.exportBitDepth,\n channels,\n interval,\n position: this.position, // Pass the current position to the processor\n enableLogging: true,\n streamFormat: this.config.streamFormat,\n })\n\n // Connect the source to the AudioWorkletNode and start recording\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n } catch (error) {\n console.error(`[${TAG}] Failed to initialize WebRecorder`, error)\n }\n }\n\n /**\n * Append new PCM data to the existing buffer\n * @param newData New Float32Array data to append\n */\n private appendPcmData(newData: Float32Array): void {\n // Clone the incoming data to ensure it's not modified\n const dataToAdd = new Float32Array(newData)\n\n if (!this.pcmData) {\n // First chunk - create a copy to avoid references to original data\n this.pcmData = new Float32Array(dataToAdd)\n return\n }\n\n // Create a new buffer with increased size\n const newBuffer = new Float32Array(\n this.pcmData.length + dataToAdd.length\n )\n\n // Copy existing data\n newBuffer.set(this.pcmData)\n\n // Append new data\n newBuffer.set(dataToAdd, this.pcmData.length)\n\n // Replace existing buffer\n this.pcmData = newBuffer\n }\n\n /**\n * Initializes the feature extractor worker for audio analysis\n * Creates an inline worker from a blob for audio feature extraction\n */\n initFeatureExtractorWorker() {\n try {\n const blob = new Blob([wasmGlueJs, '\\n', InlineFeaturesExtractor], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n this.featureExtractorWorkerUrl = url\n this.featureExtractorWorker = new Worker(url)\n this.featureExtractorWorker.onmessage =\n this.handleFeatureExtractorMessage.bind(this)\n this.featureExtractorWorker.onerror = (error) => {\n console.error(`[${TAG}] Feature extractor worker error:`, error)\n }\n\n // Initialize worker with counter if needed\n if (this.dataPointIdCounter > 0) {\n this.featureExtractorWorker.postMessage({\n command: 'resetCounter',\n value: this.dataPointIdCounter,\n })\n this.logger?.debug(\n `Initialized worker with counter value ${this.dataPointIdCounter}`\n )\n }\n\n this.logger?.log(\n 'Feature extractor worker initialized successfully'\n )\n } catch (error) {\n console.error(\n `[${TAG}] Failed to initialize feature extractor worker`,\n error\n )\n }\n }\n\n /**\n * Processes audio analysis results from the feature extractor worker\n * Updates the audio analysis data and emits events\n * @param event - The event containing audio analysis results\n */\n handleFeatureExtractorMessage(event: AudioFeaturesEvent) {\n if (event.data.command !== 'features') return\n\n const segmentResult = event.data.result\n\n // Attach WASM-computed mel frames to datapoints\n if (this.pendingMelFrames.length > 0) {\n for (const dp of segmentResult.dataPoints) {\n if (this.pendingMelFrames.length === 0) break\n const melFrame = this.pendingMelFrames.shift()\n if (melFrame) {\n if (!dp.features) dp.features = {}\n dp.features.melSpectrogram = melFrame\n }\n }\n }\n\n const uniqueNewDataPoints = this.filterUniqueDataPoints(\n segmentResult.dataPoints\n )\n\n // Update counter based on the highest ID seen\n this.updateDataPointCounter(uniqueNewDataPoints)\n\n // Update analysis data with the new results\n this.updateAudioAnalysisData(segmentResult, uniqueNewDataPoints)\n\n // Send filtered result to avoid duplicate IDs\n const filteredSegmentResult = {\n ...segmentResult,\n dataPoints: uniqueNewDataPoints,\n }\n\n this.emitAudioAnalysisCallback(filteredSegmentResult)\n }\n\n /**\n * Compute mel spectrogram frames via WASM C++ for each segment in the chunk.\n * Frames are queued in pendingMelFrames and attached to datapoints in handleFeatureExtractorMessage.\n */\n private computeMelFrames(chunk: Float32Array, sampleRate: number): void {\n if (!this.config.features?.melSpectrogram) return\n if (!this.melWasmReady) {\n // Buffer chunks while WASM is still initializing\n if (this.melWasmInitPromise) {\n this.melPendingChunks.push({\n chunk: new Float32Array(chunk),\n sampleRate,\n })\n }\n return\n }\n const segMs =\n this.config.segmentDurationMs ?? DEFAULT_SEGMENT_DURATION_MS\n const samplesPerSeg = Math.floor((sampleRate * segMs) / 1000)\n const numSegs = Math.floor(chunk.length / samplesPerSeg)\n for (let s = 0; s < numSegs; s++) {\n const seg = chunk.slice(s * samplesPerSeg, (s + 1) * samplesPerSeg)\n this.pendingMelFrames.push(computeMelFrameWasm(seg))\n }\n const rem = chunk.length % samplesPerSeg\n if (rem > samplesPerSeg / 4) {\n const seg = chunk.slice(numSegs * samplesPerSeg)\n this.pendingMelFrames.push(computeMelFrameWasm(seg))\n }\n\n // Cap queue to prevent unbounded memory growth if consumer falls behind\n const MAX_PENDING_MEL_FRAMES = 200\n if (this.pendingMelFrames.length > MAX_PENDING_MEL_FRAMES) {\n this.pendingMelFrames = this.pendingMelFrames.slice(\n -MAX_PENDING_MEL_FRAMES\n )\n }\n }\n\n /**\n * Filters out data points with duplicate IDs\n */\n private filterUniqueDataPoints(dataPoints: any[]): any[] {\n // Track existing IDs to prevent duplicates\n const existingIds = new Set(\n this.audioAnalysisData.dataPoints.map((dp) => dp.id)\n )\n\n // Filter out datapoints with duplicate IDs\n const uniquePoints = dataPoints.filter((dp) => !existingIds.has(dp.id))\n\n // Log filtered duplicates if any\n if (uniquePoints.length < dataPoints.length && this.logger?.warn) {\n this.logger.warn(\n `Filtered ${dataPoints.length - uniquePoints.length} duplicate datapoints`\n )\n }\n\n return uniquePoints\n }\n\n /**\n * Updates the counter based on the highest ID in datapoints\n */\n private updateDataPointCounter(dataPoints: any[]): void {\n if (dataPoints.length === 0) return\n\n const lastDataPoint = dataPoints[dataPoints.length - 1]\n if (lastDataPoint && typeof lastDataPoint.id === 'number') {\n const nextIdValue = lastDataPoint.id + 1\n if (nextIdValue > this.dataPointIdCounter) {\n this.dataPointIdCounter = nextIdValue\n this.logger?.debug(\n `Counter updated to ${this.dataPointIdCounter}`\n )\n }\n }\n }\n\n /**\n * Updates audio analysis data with segment results\n */\n private updateAudioAnalysisData(\n segmentResult: AudioAnalysis,\n uniqueDataPoints: any[]\n ): void {\n // Add unique data points to our analysis data\n this.audioAnalysisData.dataPoints.push(...uniqueDataPoints)\n this.audioAnalysisData.durationMs += segmentResult.durationMs\n this.audioAnalysisData.sampleRate = segmentResult.sampleRate\n\n // Update amplitude range if present\n if (segmentResult.amplitudeRange) {\n this.audioAnalysisData.amplitudeRange = this.mergeRange(\n this.audioAnalysisData.amplitudeRange,\n segmentResult.amplitudeRange\n )\n }\n\n // Update RMS range if present\n if (segmentResult.rmsRange) {\n this.audioAnalysisData.rmsRange = this.mergeRange(\n this.audioAnalysisData.rmsRange,\n segmentResult.rmsRange\n )\n }\n }\n\n /**\n * Merges value ranges\n */\n private mergeRange(\n existing: { min: number; max: number } | undefined,\n newRange: { min: number; max: number }\n ): { min: number; max: number } {\n if (!existing) return { ...newRange }\n\n return {\n min: Math.min(existing.min, newRange.min),\n max: Math.max(existing.max, newRange.max),\n }\n }\n\n /**\n * Reset the data point counter to a specific value or zero\n * @param startCounterFrom Optional value to start the counter from (for continuing from previous recordings)\n */\n resetDataPointCounter(startCounterFrom?: number): void {\n // Set the counter with the passed value or 0\n this.dataPointIdCounter = startCounterFrom ?? 0\n this.logger?.debug(\n `Reset data point counter to ${this.dataPointIdCounter}`\n )\n\n // Update worker counter if available\n if (this.featureExtractorWorker) {\n this.featureExtractorWorker.postMessage({\n command: 'resetCounter',\n value: this.dataPointIdCounter,\n })\n } else {\n this.logger?.warn(\n 'No feature extractor worker available to update counter'\n )\n }\n }\n\n /**\n * Get the current data point counter value\n * @returns The current value of the data point counter\n */\n getDataPointCounter(): number {\n return this.dataPointIdCounter\n }\n\n /**\n * Prepares the recorder for continuity after device switch\n * Sets up all necessary state to maintain proper recording continuity\n */\n prepareForDeviceSwitch(): void {\n this.isFirstChunkAfterSwitch = true\n this.logger?.debug(\n `Prepared for device switch at position ${this.position}s`\n )\n }\n\n /**\n * Starts the audio recording process\n * Connects the audio nodes and begins capturing audio data\n * @param preserveCounters If true, do not reset the counter (used for device switching)\n */\n start(preserveCounters = false) {\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n\n // Only reset the counter when not preserving state (e.g., for a fresh recording)\n if (!preserveCounters) {\n this.logger?.debug(\n 'Starting fresh recording, resetting counter to 0'\n )\n this.resetDataPointCounter(0) // Explicitly reset to 0 for new recordings\n this.isFirstChunkAfterSwitch = false\n\n // Clear PCM data for new recording\n this.pcmData = null\n this.totalSampleCount = 0\n } else {\n this.logger?.debug(\n `Preserving counter at ${this.dataPointIdCounter} during device switch`\n )\n }\n\n if (this.compressedMediaRecorder) {\n this.compressedMediaRecorder.start(this.config.interval ?? 1000)\n }\n }\n\n /**\n * Creates a WAV file from the stored PCM data\n */\n private createWavFromPcmData(): Blob | null {\n try {\n // Check if we have PCM data\n if (!this.pcmData || this.pcmData.length === 0) {\n this.logger?.warn('No PCM data available to create WAV file')\n return null\n }\n\n const sampleRate =\n this.config.sampleRate ?? this.audioContext.sampleRate\n const channels = this.numberOfChannels || 1\n\n // Convert float32 PCM data to 16-bit PCM for WAV\n const bytesPerSample = 2 // 16-bit = 2 bytes\n const dataLength = this.pcmData.length * bytesPerSample\n const buffer = new ArrayBuffer(dataLength)\n const view = new DataView(buffer)\n\n // Convert Float32Array (-1 to 1) to Int16Array (-32768 to 32767)\n for (let i = 0; i < this.pcmData.length; i++) {\n const sample = Math.max(-1, Math.min(1, this.pcmData[i]))\n const int16Value = Math.round(sample * 32767)\n view.setInt16(i * 2, int16Value, true)\n }\n\n // Use the existing writeWavHeader utility to add a WAV header\n const wavBuffer = writeWavHeader({\n buffer,\n sampleRate,\n numChannels: channels,\n bitDepth: 16,\n isFloat: false,\n })\n\n return new Blob([wavBuffer], { type: 'audio/wav' })\n } catch (error) {\n this.logger?.error('Error creating WAV file from PCM data:', error)\n return null\n }\n }\n\n /**\n * Stops the audio recording process and returns the recorded data\n * @returns Promise resolving to an object containing compressed and/or uncompressed blobs\n */\n async stop(): Promise<{ compressedBlob?: Blob; uncompressedBlob?: Blob }> {\n try {\n // Stop any compressed recording first\n if (\n this.compressedMediaRecorder &&\n this.compressedMediaRecorder.state !== 'inactive'\n ) {\n this.compressedMediaRecorder.stop()\n }\n\n // Wait for any pending compressed chunks to be processed\n if (this.compressedMediaRecorder) {\n // Small delay to ensure all data is processed\n await new Promise((resolve) => setTimeout(resolve, 100))\n }\n\n // Create uncompressed WAV file from the PCM data\n let uncompressedBlob: Blob | undefined\n\n // Only create WAV if we have PCM data\n if (this.pcmData && this.pcmData.length > 0) {\n uncompressedBlob = this.createWavFromPcmData() || undefined\n }\n\n // Return the compressed and/or uncompressed blobs if available\n return {\n compressedBlob:\n this.compressedChunks.length > 0\n ? new Blob(this.compressedChunks, {\n type: 'audio/webm;codecs=opus',\n })\n : undefined,\n uncompressedBlob,\n }\n } finally {\n this.cleanup()\n // Reset the chunks array\n this.compressedChunks = []\n this.compressedSize = 0\n this.pendingCompressedChunk = null\n this.pcmData = null\n this.totalSampleCount = 0\n this.dataPointIdCounter = 0 // Reset counter\n }\n }\n\n /**\n * Cleans up resources when recording is stopped\n * Closes audio context and disconnects nodes\n */\n public cleanup() {\n // Remove device disconnection handler\n if (this.deviceDisconnectionHandler) {\n this.deviceDisconnectionHandler()\n this.deviceDisconnectionHandler = null\n }\n\n // Check if AudioContext is already closed before attempting to close it\n if (this.audioContext && this.audioContext.state !== 'closed') {\n this.audioContext.close().catch((e) => {\n // Log closure errors but continue cleanup\n this.logger?.warn('Error closing AudioContext:', e)\n })\n }\n\n // Safely disconnect audioWorkletNode if it exists\n if (this.audioWorkletNode) {\n try {\n this.audioWorkletNode.disconnect()\n } catch (e) {\n // Log disconnection errors but continue cleanup\n this.logger?.warn('Error disconnecting audioWorkletNode:', e)\n }\n }\n\n // Safely disconnect source if it exists\n if (this.source) {\n try {\n this.source.disconnect()\n } catch (e) {\n // Log disconnection errors but continue cleanup\n this.logger?.warn('Error disconnecting source:', e)\n }\n }\n\n // Terminate feature extractor worker and revoke blob URL\n if (this.featureExtractorWorker) {\n this.featureExtractorWorker.terminate()\n this.featureExtractorWorker = undefined\n }\n if (this.featureExtractorWorkerUrl) {\n URL.revokeObjectURL(this.featureExtractorWorkerUrl)\n this.featureExtractorWorkerUrl = undefined\n }\n\n // Always stop media stream tracks to release hardware resources\n this.stopMediaStreamTracks()\n\n // Mark as disconnected to prevent future errors\n this._isDeviceDisconnected = true\n }\n\n /**\n * Pauses the audio recording process\n * Disconnects audio nodes and pauses the media recorder\n */\n pause() {\n try {\n // Note: We're just pausing, not disconnecting the device\n // Simply disconnect nodes temporarily without marking device as disconnected\n this.source.disconnect(this.audioWorkletNode)\n this.audioWorkletNode.disconnect(this.audioContext.destination)\n this.audioWorkletNode.port.postMessage({ command: 'pause' })\n\n if (this.compressedMediaRecorder?.state === 'recording') {\n this.compressedMediaRecorder.pause()\n }\n\n this.logger?.debug('Recording paused successfully')\n } catch (error) {\n this.logger?.error('Error in pause(): ', error)\n // Already disconnected, just ignore and continue\n }\n }\n\n /**\n * Stops all media stream tracks to release hardware resources\n * Ensures recording indicators (like microphone icon) are turned off\n */\n public stopMediaStreamTracks() {\n // Stop all audio tracks to stop the recording icon\n if (this.mediaStream) {\n const tracks = this.mediaStream.getTracks()\n tracks.forEach((track) => track.stop())\n } else if (this.source?.mediaStream) {\n const tracks = this.source.mediaStream.getTracks()\n tracks.forEach((track) => track.stop())\n }\n }\n\n /**\n * Determines the audio format capabilities of the current audio context\n * @param sampleRate - The sample rate to check\n * @returns Object containing format information (sample rate, bit depth, channels)\n */\n private checkAudioContextFormat({ sampleRate }: { sampleRate: number }) {\n // Create a silent AudioBuffer\n const frameCount = sampleRate * 1.0 // 1 second buffer\n const audioBuffer = this.audioContext.createBuffer(\n 1,\n frameCount,\n sampleRate\n )\n\n // Check the format\n const channelData = audioBuffer.getChannelData(0)\n const bitDepth = channelData.BYTES_PER_ELEMENT * 8 // 4 bytes per element means 32-bit\n\n return {\n sampleRate: audioBuffer.sampleRate,\n bitDepth,\n numberOfChannels: audioBuffer.numberOfChannels,\n }\n }\n\n /**\n * Resumes a paused recording\n * Reconnects audio nodes and resumes the media recorder\n */\n resume() {\n // If device was disconnected, we can't resume\n if (this._isDeviceDisconnected) {\n this.logger?.warn('Cannot resume recording: device disconnected')\n return\n }\n\n try {\n this.source.connect(this.audioWorkletNode)\n this.audioWorkletNode.connect(this.audioContext.destination)\n this.audioWorkletNode.port.postMessage({ command: 'resume' })\n this.compressedMediaRecorder?.resume()\n } catch (error: unknown) {\n this.logger?.error('Error in resume(): ', error)\n // Rethrow the error to inform callers\n throw new Error(\n `Failed to resume recording: ${error instanceof Error ? error.message : 'unknown error'}`\n )\n }\n }\n\n /**\n * Initializes the compressed media recorder if compression is enabled\n * Sets up event handlers for compressed audio data\n */\n private initializeCompressedRecorder() {\n try {\n const mimeType = 'audio/webm;codecs=opus'\n if (!MediaRecorder.isTypeSupported(mimeType)) {\n this.logger?.warn(\n 'Opus compression not supported in this browser'\n )\n return\n }\n\n this.compressedMediaRecorder = new MediaRecorder(\n this.source.mediaStream,\n {\n mimeType,\n audioBitsPerSecond:\n this.config.output?.compressed?.bitrate ?? 128000,\n }\n )\n\n this.compressedMediaRecorder.ondataavailable = (event) => {\n if (event.data.size > 0) {\n // Store the compressed chunk for final blob creation\n this.compressedChunks.push(event.data)\n this.compressedSize += event.data.size\n\n // Store the pending compressed chunk for the next PCM chunk to use\n this.pendingCompressedChunk = event.data\n }\n }\n } catch (error) {\n this.logger?.error(\n 'Failed to initialize compressed recorder:',\n error\n )\n // Setting to null to indicate initialization failed\n this.compressedMediaRecorder = null\n }\n }\n\n /**\n * Processes features if enabled\n */\n processFeatures(\n chunk: Float32Array,\n sampleRate: number,\n chunkPosition: number,\n startPosition: number,\n endPosition: number,\n samples: number\n ) {\n this.computeMelFrames(chunk, sampleRate)\n\n if (this.config.enableProcessing && this.featureExtractorWorker) {\n this.featureExtractorWorker.postMessage({\n command: 'process',\n channelData: chunk,\n sampleRate,\n segmentDurationMs:\n this.config.segmentDurationMs ??\n DEFAULT_SEGMENT_DURATION_MS, // Default to 100ms\n bitDepth: this.bitDepth,\n fullAudioDurationMs: chunkPosition * 1000,\n numberOfChannels: this.numberOfChannels,\n features: this.config.features,\n intervalAnalysis: this.config.intervalAnalysis,\n startPosition,\n endPosition,\n samples,\n })\n }\n }\n\n /**\n * Sets up detection for device disconnection events\n */\n private setupDeviceDisconnectionDetection() {\n if (!this.mediaStream) return\n\n // Function to handle track ending (which happens on device disconnection)\n const handleTrackEnded = () => {\n this.logger?.warn('Audio track ended - device disconnected')\n this._isDeviceDisconnected = true\n\n // Use the callback to notify parent component about device disconnection\n if (this.onInterruptionCallback) {\n this.onInterruptionCallback({\n reason: 'deviceDisconnected',\n isPaused: true,\n timestamp: Date.now(),\n })\n this.logger?.debug('Notified about device disconnection')\n }\n\n // Ensure we disconnect nodes to prevent zombie recordings\n if (this.audioWorkletNode) {\n this.audioWorkletNode.port.postMessage({\n command: 'deviceDisconnected',\n })\n\n try {\n this.source.disconnect(this.audioWorkletNode)\n this.audioWorkletNode.disconnect()\n } catch (e) {\n // Ignore disconnection errors as the track might already be gone\n this.logger?.warn(\n 'Error disconnecting audioWorkletNode:',\n e\n )\n }\n }\n }\n\n // Add listeners to all audio tracks\n const tracks = this.mediaStream.getAudioTracks()\n tracks.forEach((track) => {\n track.addEventListener('ended', handleTrackEnded)\n })\n\n // Store the handler for cleanup\n this.deviceDisconnectionHandler = () => {\n tracks.forEach((track) => {\n track.removeEventListener('ended', handleTrackEnded)\n })\n }\n }\n\n /**\n * Explicitly set the position for continuous recording across device switches\n * @param position The position in seconds to continue from\n */\n setPosition(position: number): void {\n if (position >= 0) {\n this.position = position\n this.logger?.debug(`Position explicitly set to ${position} seconds`)\n } else {\n this.logger?.warn(`Invalid position value: ${position}, ignoring`)\n }\n }\n\n /**\n * Get the current position in seconds\n * @returns The current position\n */\n getPosition(): number {\n return this.position\n }\n\n /**\n * Gets the current compressed chunks\n * @returns Array of current compressed audio chunks\n */\n getCompressedChunks(): Blob[] {\n return [...this.compressedChunks]\n }\n\n /**\n * Sets the compressed chunks from a previous recorder\n * @param chunks Array of compressed chunks from a previous recorder\n */\n setCompressedChunks(chunks: Blob[]): void {\n if (chunks && chunks.length > 0) {\n this.logger?.debug(\n `Adding ${chunks.length} compressed chunks from previous device`\n )\n this.compressedChunks = [...chunks, ...this.compressedChunks]\n // Update size\n this.compressedSize = this.compressedChunks.reduce(\n (size, chunk) => size + chunk.size,\n 0\n )\n }\n }\n}\n"]}
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Platform-specific audio recording limitations and capabilities
3
+ */
4
+ import { Platform } from 'react-native';
5
+ export const PLATFORM_CAPABILITIES = {
6
+ ios: {
7
+ supportedEncodings: ['pcm_16bit', 'pcm_32bit'],
8
+ supportedBitDepths: [16, 32],
9
+ notes: [
10
+ '8-bit PCM is not natively supported by iOS AVAudioFormat',
11
+ 'Recording with 8-bit will fallback to 16-bit',
12
+ ],
13
+ },
14
+ android: {
15
+ supportedEncodings: ['pcm_8bit', 'pcm_16bit', 'pcm_32bit'],
16
+ supportedBitDepths: [8, 16, 32],
17
+ notes: ['All PCM formats are fully supported'],
18
+ },
19
+ web: {
20
+ supportedEncodings: ['pcm_16bit', 'pcm_32bit'],
21
+ supportedBitDepths: [16, 32],
22
+ notes: [
23
+ 'Web Audio API typically works with 32-bit float',
24
+ '8-bit is not commonly supported in browsers',
25
+ ],
26
+ },
27
+ };
28
+ /**
29
+ * Get the current platform's audio capabilities
30
+ */
31
+ export function getPlatformCapabilities() {
32
+ return PLATFORM_CAPABILITIES[Platform.OS] || PLATFORM_CAPABILITIES.web;
33
+ }
34
+ /**
35
+ * Check if a specific encoding is supported on the current platform
36
+ */
37
+ export function isEncodingSupported(encoding) {
38
+ const capabilities = getPlatformCapabilities();
39
+ return capabilities.supportedEncodings.includes(encoding);
40
+ }
41
+ /**
42
+ * Check if a specific bit depth is supported on the current platform
43
+ */
44
+ export function isBitDepthSupported(bitDepth) {
45
+ const capabilities = getPlatformCapabilities();
46
+ return capabilities.supportedBitDepths.includes(bitDepth);
47
+ }
48
+ /**
49
+ * Get a fallback encoding if the requested one is not supported
50
+ */
51
+ export function getFallbackEncoding(requestedEncoding) {
52
+ if (isEncodingSupported(requestedEncoding)) {
53
+ return requestedEncoding;
54
+ }
55
+ // Default fallback is 16-bit PCM (supported on all platforms)
56
+ return 'pcm_16bit';
57
+ }
58
+ /**
59
+ * Get a fallback bit depth if the requested one is not supported
60
+ */
61
+ export function getFallbackBitDepth(requestedBitDepth) {
62
+ if (isBitDepthSupported(requestedBitDepth)) {
63
+ return requestedBitDepth;
64
+ }
65
+ // Default fallback is 16-bit (supported on all platforms)
66
+ return 16;
67
+ }
68
+ /**
69
+ * Validate and adjust recording configuration based on platform limitations
70
+ */
71
+ export function validateRecordingConfig(config) {
72
+ const warnings = [];
73
+ const capabilities = getPlatformCapabilities();
74
+ let encoding = config.encoding || 'pcm_16bit';
75
+ // Check if encoding is supported
76
+ if (!isEncodingSupported(encoding)) {
77
+ const fallback = getFallbackEncoding(encoding);
78
+ warnings.push(`${encoding} is not supported on ${Platform.OS}. Using ${fallback} instead.`);
79
+ encoding = fallback;
80
+ }
81
+ // Add platform-specific notes if there were changes
82
+ if (warnings.length > 0) {
83
+ warnings.push(...capabilities.notes);
84
+ }
85
+ return {
86
+ encoding,
87
+ warnings,
88
+ };
89
+ }
90
+ //# sourceMappingURL=platformLimitations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platformLimitations.js","sourceRoot":"","sources":["../../../src/constants/platformLimitations.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAUvC,MAAM,CAAC,MAAM,qBAAqB,GAAyC;IACvE,GAAG,EAAE;QACD,kBAAkB,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC;QAC9C,kBAAkB,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAC5B,KAAK,EAAE;YACH,0DAA0D;YAC1D,8CAA8C;SACjD;KACJ;IACD,OAAO,EAAE;QACL,kBAAkB,EAAE,CAAC,UAAU,EAAE,WAAW,EAAE,WAAW,CAAC;QAC1D,kBAAkB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC;QAC/B,KAAK,EAAE,CAAC,qCAAqC,CAAC;KACjD;IACD,GAAG,EAAE;QACD,kBAAkB,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC;QAC9C,kBAAkB,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC;QAC5B,KAAK,EAAE;YACH,iDAAiD;YACjD,6CAA6C;SAChD;KACJ;CACJ,CAAA;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACnC,OAAO,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,qBAAqB,CAAC,GAAG,CAAA;AAC1E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAsB;IACtD,MAAM,YAAY,GAAG,uB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AQ,CAAC,IAAI,CAAC,GAAG,YAAY,CAAC,KAAK,CAAC,CAAA;IACxC,CAAC;IAED,OAAO;QACH,QAAQ;QACR,QAAQ;KACX,CAAA;AACL,CAAC","sourcesContent":["/**\n * Platform-specific audio recording limitations and capabilities\n */\n\nimport { Platform } from 'react-native'\n\nimport { EncodingType, BitDepth } from '../AudioStudio.types'\n\nexport interface PlatformCapabilities {\n supportedEncodings: EncodingType[]\n supportedBitDepths: BitDepth[]\n notes: string[]\n}\n\nexport const PLATFORM_CAPABILITIES: Record<string, PlatformCapabilities> = {\n ios: {\n supportedEncodings: ['pcm_16bit', 'pcm_32bit'],\n supportedBitDepths: [16, 32],\n notes: [\n '8-bit PCM is not natively supported by iOS AVAudioFormat',\n 'Recording with 8-bit will fallback to 16-bit',\n ],\n },\n android: {\n supportedEncodings: ['pcm_8bit', 'pcm_16bit', 'pcm_32bit'],\n supportedBitDepths: [8, 16, 32],\n notes: ['All PCM formats are fully supported'],\n },\n web: {\n supportedEncodings: ['pcm_16bit', 'pcm_32bit'],\n supportedBitDepths: [16, 32],\n notes: [\n 'Web Audio API typically works with 32-bit float',\n '8-bit is not commonly supported in browsers',\n ],\n },\n}\n\n/**\n * Get the current platform's audio capabilities\n */\nexport function getPlatformCapabilities(): PlatformCapabilities {\n return PLATFORM_CAPABILITIES[Platform.OS] || PLATFORM_CAPABILITIES.web\n}\n\n/**\n * Check if a specific encoding is supported on the current platform\n */\nexport function isEncodingSupported(encoding: EncodingType): boolean {\n const capabilities = getPlatformCapabilities()\n return capabilities.supportedEncodings.includes(encoding)\n}\n\n/**\n * Check if a specific bit depth is supported on the current platform\n */\nexport function isBitDepthSupported(bitDepth: BitDepth): boolean {\n const capabilities = getPlatformCapabilities()\n return capabilities.supportedBitDepths.includes(bitDepth)\n}\n\n/**\n * Get a fallback encoding if the requested one is not supported\n */\nexport function getFallbackEncoding(\n requestedEncoding: EncodingType\n): EncodingType {\n if (isEncodingSupported(requestedEncoding)) {\n return requestedEncoding\n }\n\n // Default fallback is 16-bit PCM (supported on all platforms)\n return 'pcm_16bit'\n}\n\n/**\n * Get a fallback bit depth if the requested one is not supported\n */\nexport function getFallbackBitDepth(requestedBitDepth: BitDepth): BitDepth {\n if (isBitDepthSupported(requestedBitDepth)) {\n return requestedBitDepth\n }\n\n // Default fallback is 16-bit (supported on all platforms)\n return 16\n}\n\n/**\n * Validate and adjust recording configuration based on platform limitations\n */\nexport function validateRecordingConfig(config: { encoding?: EncodingType }): {\n encoding: EncodingType\n warnings: string[]\n} {\n const warnings: string[] = []\n const capabilities = getPlatformCapabilities()\n\n let encoding = config.encoding || 'pcm_16bit'\n\n // Check if encoding is supported\n if (!isEncodingSupported(encoding)) {\n const fallback = getFallbackEncoding(encoding)\n warnings.push(\n `${encoding} is not supported on ${Platform.OS}. Using ${fallback} instead.`\n )\n encoding = fallback\n }\n\n // Add platform-specific notes if there were changes\n if (warnings.length > 0) {\n warnings.push(...capabilities.notes)\n }\n\n return {\n encoding,\n warnings,\n }\n}\n"]}
@@ -0,0 +1,17 @@
1
+ // packages/audio-studio/src/constants.ts
2
+ import { Platform } from 'react-native';
3
+ export const isWeb = Platform.OS === 'web';
4
+ export const DEBUG_NAMESPACE = 'audio-studio';
5
+ // Constants for identifying chunks in a WAV file
6
+ export const RIFF_HEADER = 0x52494646; // "RIFF"
7
+ export const WAVE_HEADER = 0x57415645; // "WAVE"
8
+ export const FMT_CHUNK_ID = 0x666d7420; // "fmt "
9
+ export const DATA_CHUNK_ID = 0x64617461; // "data"
10
+ export const INFO_CHUNK_ID = 0x494e464f; // "INFO"
11
+ // Default values
12
+ export const DEFAULT_SAMPLE_RATE = 16000;
13
+ export const DEFAULT_BIT_DEPTH = 32;
14
+ export const DEFAULT_INTERVAL_MS = 1000;
15
+ export const DEFAULT_ANALYSIS_INTERVAL_MS = 500;
16
+ export const DEFAULT_MAX_BUFFER_SIZE = 100;
17
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAIvC,MAAM,CAAC,MAAM,KAAK,GAAG,QAAQ,CAAC,EAAE,KAAK,KAAK,CAAA;AAC1C,MAAM,CAAC,MAAM,eAAe,GAAG,cAAc,CAAA;AAE7C,iDAAiD;AACjD,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA,CAAC,SAAS;AAC/C,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAA,CAAC,SAAS;AAC/C,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAA,CAAC,SAAS;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAA,CAAC,SAAS;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAA,CAAC,SAAS;AAEjD,iBAAiB;AACjB,MAAM,CAAC,MAAM,mBAAmB,GAAe,KAAK,CAAA;AACpD,MAAM,CAAC,MAAM,iBAAiB,GAAa,EAAE,CAAA;AAC7C,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAA;AACvC,MAAM,CAAC,MAAM,4BAA4B,GAAG,GAAG,CAAA;AAC/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,CAAA","sourcesContent":["// packages/audio-studio/src/constants.ts\nimport { Platform } from 'react-native'\n\nimport { BitDepth, SampleRate } from './AudioStudio.types'\n\nexport const isWeb = Platform.OS === 'web'\nexport const DEBUG_NAMESPACE = 'audio-studio'\n\n// Constants for identifying chunks in a WAV file\nexport const RIFF_HEADER = 0x52494646 // \"RIFF\"\nexport const WAVE_HEADER = 0x57415645 // \"WAVE\"\nexport const FMT_CHUNK_ID = 0x666d7420 // \"fmt \"\nexport const DATA_CHUNK_ID = 0x64617461 // \"data\"\nexport const INFO_CHUNK_ID = 0x494e464f // \"INFO\"\n\n// Default values\nexport const DEFAULT_SAMPLE_RATE: SampleRate = 16000\nexport const DEFAULT_BIT_DEPTH: BitDepth = 32\nexport const DEFAULT_INTERVAL_MS = 1000\nexport const DEFAULT_ANALYSIS_INTERVAL_MS = 500\nexport const DEFAULT_MAX_BUFFER_SIZE = 100\n"]}
@@ -0,0 +1,21 @@
1
+ // packages/audio-studio/src/events.ts
2
+ import { LegacyEventEmitter } from 'expo-modules-core';
3
+ import AudioStudioModule from './AudioStudioModule';
4
+ const emitter = new LegacyEventEmitter(AudioStudioModule);
5
+ export function addAudioEventListener(listener) {
6
+ return emitter.addListener('AudioData', listener);
7
+ }
8
+ export function addAudioAnalysisListener(listener) {
9
+ return emitter.addListener('AudioAnalysis', listener);
10
+ }
11
+ export function addRecordingInterruptionListener(listener) {
12
+ // Add debug logging
13
+ console.debug('Adding recording interruption listener');
14
+ const subscription = emitter.addListener('onRecordingInterrupted', // Make sure this matches the native event name
15
+ (event) => {
16
+ console.debug('Recording interruption event received:', event);
17
+ listener(event);
18
+ });
19
+ return subscription;
20
+ }
21
+ //# sourceMappingURL=events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"events.js","sourceRoot":"","sources":["../../src/events.ts"],"names":[],"mappings":"AAAA,sCAAsC;AAEtC,OAAO,EAAE,kBAAkB,EAA0B,MAAM,mBAAmB,CAAA;AAI9E,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AAEnD,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;AAwBzD,MAAM,UAAU,qBAAqB,CACjC,QAAqD;IAErD,OAAO,OAAO,CAAC,WAAW,CAAoB,WAAW,EAAE,QAAQ,CAAC,CAAA;AACxE,CAAC;AAKD,MAAM,UAAU,wBAAwB,CACpC,QAAsD;IAEtD,OAAO,OAAO,CAAC,WAAW,CAAqB,eAAe,EAAE,QAAQ,CAAC,CAAA;AAC7E,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC5C,QAAqD;IAErD,oBAAoB;IACpB,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAA;IAEvD,MAAM,YAAY,GAAG,OAAO,CAAC,WAAW,CACpC,wBAAwB,EAAE,+CAA+C;IACzE,CAAC,KAAK,EAAE,EAAE;QACN,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,KAAK,CAAC,CAAA;QAC9D,QAAQ,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC,CACJ,CAAA;IAED,OAAO,YAAY,CAAA;AACvB,CAAC","sourcesContent":["// packages/audio-studio/src/events.ts\n\nimport { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport { RecordingInterruptionEvent } from './AudioStudio.types'\nimport AudioStudioModule from './AudioStudioModule'\n\nconst emitter = new LegacyEventEmitter(AudioStudioModule)\n\n// Internal event payload from native module\nexport interface AudioEventPayload {\n encoded?: string\n /** Float32 samples in [-1, 1] — sent by native when streamFormat='float32'.\n * Android new arch delivers Float32Array; iOS delivers number[]. */\n pcmFloat32?: Float32Array | number[]\n buffer?: Float32Array\n fileUri: string\n lastEmittedSize: number\n position: number\n deltaSize: number\n totalSize: number\n mimeType: string\n streamUuid: string\n compression?: {\n data?: string | Blob // Base64 (native) or Float32Array (web) encoded compressed data chunk\n position: number\n eventDataSize: number\n totalSize: number\n }\n}\n\nexport function addAudioEventListener(\n listener: (event: AudioEventPayload) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioEventPayload>('AudioData', listener)\n}\n\n// Only aliasing the AudioAnalysis type for the event payload\nexport interface AudioAnalysisEvent extends AudioAnalysis {}\n\nexport function addAudioAnalysisListener(\n listener: (event: AudioAnalysisEvent) => Promise<void>\n): EventSubscription {\n return emitter.addListener<AudioAnalysisEvent>('AudioAnalysis', listener)\n}\n\nexport function addRecordingInterruptionListener(\n listener: (event: RecordingInterruptionEvent) => void\n): EventSubscription {\n // Add debug logging\n console.debug('Adding recording interruption listener')\n\n const subscription = emitter.addListener<RecordingInterruptionEvent>(\n 'onRecordingInterrupted', // Make sure this matches the native event name\n (event) => {\n console.debug('Recording interruption event received:', event)\n listener(event)\n }\n )\n\n return subscription\n}\n"]}
@@ -0,0 +1,176 @@
1
+ import { useCallback, useEffect, useState, useId } from 'react';
2
+ import { audioDeviceManager } from '../AudioDeviceManager';
3
+ /**
4
+ * React hook for managing audio input devices
5
+ */
6
+ export function useAudioDevices() {
7
+ const [devices, setDevices] = useState([]);
8
+ const [currentDevice, setCurrentDevice] = useState(null);
9
+ const [loading, setLoading] = useState(true);
10
+ const [error, setError] = useState(null);
11
+ // Generate unique instance ID for debugging
12
+ const instanceId = useId().replace(/:/g, '').slice(0, 5);
13
+ // Load devices on mount
14
+ useEffect(() => {
15
+ let isMounted = true;
16
+ const loadDevices = async () => {
17
+ try {
18
+ setLoading(true);
19
+ setError(null);
20
+ // Load available devices
21
+ const availableDevices = await audioDeviceManager.getAvailableDevices();
22
+ if (isMounted)
23
+ setDevices(availableDevices);
24
+ // Get current device
25
+ const device = await audioDeviceManager.getCurrentDevice();
26
+ if (isMounted)
27
+ setCurrentDevice(device);
28
+ }
29
+ catch (err) {
30
+ audioDeviceManager
31
+ .getLogger()
32
+ ?.error('Failed to load audio devices:', err);
33
+ if (isMounted)
34
+ setError(err instanceof Error
35
+ ? err
36
+ : new Error('Failed to load audio devices'));
37
+ }
38
+ finally {
39
+ if (isMounted)
40
+ setLoading(false);
41
+ }
42
+ };
43
+ loadDevices();
44
+ // Set up device change listener
45
+ const removeListener = audioDeviceManager.addDeviceChangeListener((updatedDevices) => {
46
+ audioDeviceManager
47
+ .getLogger()
48
+ ?.debug(`🎛️ useAudioDevices [${instanceId}] received device change. Count: ${updatedDevices.length}`);
49
+ if (isMounted) {
50
+ setDevices(updatedDevices);
51
+ // If our current device is no longer available, update it
52
+ if (currentDevice &&
53
+ !updatedDevices.some((d) => d.id === currentDevice.id)) {
54
+ audioDeviceManager
55
+ .getLogger()
56
+ ?.debug(`🎛️ useAudioDevices [${instanceId}] Current device ${currentDevice.id} no longer available, updating`);
57
+ audioDeviceManager
58
+ .getCurrentDevice()
59
+ .then((newDevice) => {
60
+ if (isMounted) {
61
+ setCurrentDevice(newDevice);
62
+ }
63
+ });
64
+ }
65
+ }
66
+ });
67
+ return () => {
68
+ isMounted = false;
69
+ removeListener();
70
+ };
71
+ }, []);
72
+ /**
73
+ * Select a specific audio input device
74
+ * @param deviceId The ID of the device to select
75
+ * @returns Promise resolving to a boolean indicating success
76
+ */
77
+ const selectDevice = useCallback(async (deviceId) => {
78
+ try {
79
+ setLoading(true);
80
+ setError(null);
81
+ const success = await audioDeviceManager.selectDevice(deviceId);
82
+ if (success) {
83
+ // Get the updated current device after selection
84
+ const device = await audioDeviceManager.getCurrentDevice();
85
+ setCurrentDevice(device);
86
+ }
87
+ return success;
88
+ }
89
+ catch (err) {
90
+ audioDeviceManager
91
+ .getLogger()
92
+ ?.error('Failed to select audio device:', err);
93
+ setError(err instanceof Error
94
+ ? err
95
+ : new Error('Failed to select audio device'));
96
+ return false;
97
+ }
98
+ finally {
99
+ setLoading(false);
100
+ }
101
+ }, []);
102
+ /**
103
+ * Reset to the default audio input device
104
+ * @returns Promise resolving to a boolean indicating success
105
+ */
106
+ const resetToDefaultDevice = useCallback(async () => {
107
+ try {
108
+ setLoading(true);
109
+ setError(null);
110
+ const success = await audioDeviceManager.resetToDefaultDevice();
111
+ if (success) {
112
+ // Get the updated current device after reset
113
+ const device = await audioDeviceManager.getCurrentDevice();
114
+ setCurrentDevice(device);
115
+ }
116
+ return success;
117
+ }
118
+ catch (err) {
119
+ audioDeviceManager
120
+ .getLogger()
121
+ ?.error('Failed to reset to default audio device:', err);
122
+ setError(err instanceof Error
123
+ ? err
124
+ : new Error('Failed to reset to default audio device'));
125
+ return false;
126
+ }
127
+ finally {
128
+ setLoading(false);
129
+ }
130
+ }, []);
131
+ /**
132
+ * Refresh the list of available devices
133
+ */
134
+ const refreshDevices = useCallback(async () => {
135
+ try {
136
+ setLoading(true);
137
+ setError(null);
138
+ const updatedDevices = await audioDeviceManager.refreshDevices();
139
+ setDevices(updatedDevices);
140
+ // Also refresh the current device
141
+ const device = await audioDeviceManager.getCurrentDevice();
142
+ setCurrentDevice(device);
143
+ return updatedDevices;
144
+ }
145
+ catch (err) {
146
+ audioDeviceManager
147
+ .getLogger()
148
+ ?.error('Failed to refresh audio devices:', err);
149
+ setError(err instanceof Error
150
+ ? err
151
+ : new Error('Failed to refresh audio devices'));
152
+ return [];
153
+ }
154
+ finally {
155
+ setLoading(false);
156
+ }
157
+ }, []);
158
+ /**
159
+ * Initialize device detection
160
+ * Useful for restarting device detection if it failed initially
161
+ */
162
+ const initializeDeviceDetection = useCallback(() => {
163
+ audioDeviceManager.initializeDeviceDetection();
164
+ }, []);
165
+ return {
166
+ devices,
167
+ currentDevice,
168
+ loading,
169
+ error,
170
+ selectDevice,
171
+ resetToDefaultDevice,
172
+ refreshDevices,
173
+ initializeDeviceDetection,
174
+ };
175
+ }
176
+ //# sourceMappingURL=useAudioDevices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAudioDevices.js","sourceRoot":"","sources":["../../../src/hooks/useAudioDevices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D;;GAEG;AACH,MAAM,UAAU,eAAe;IAC3B,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAgB,EAAE,CAAC,CAAA;IACzD,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAqB,IAAI,CAAC,CAAA;IAC5E,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAA;IAC5C,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAe,IAAI,CAAC,CAAA;IAEtD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C,IAAI,CAAC,CAAA;YAChB,QAAQ,CAAC,IAAI,CAAC,CAAA;YAEd,MAAM,cAAc,GAAG,MAAM,kBAAkB,CAAC,cAAc,EAAE,CAAA;YAChE,UAAU,CAAC,cAAc,CAAC,CAAA;YAE1B,kCAAkC;YAClC,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,gBAAgB,EAAE,CAAA;YAC1D,gBAAgB,CAAC,MAAM,CAAC,CAAA;YAExB,OAAO,cAAc,CAAA;QACzB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACX,kBAAkB;iBACb,SAAS,EAAE;gBACZ,EAAE,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAA;YACpD,QAAQ,CACJ,GAAG,YAAY,KAAK;gBAChB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,IAAI,KAAK,CAAC,iCAAiC,CAAC,CACrD,CAAA;YACD,OAAO,EAAE,CAAA;QACb,CAAC;gBAAS,CAAC;YACP,UAAU,CAAC,KAAK,CAAC,CAAA;QACrB,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN;;;OAGG;IACH,MAAM,yBAAyB,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/C,kBAAkB,CAAC,yBAAyB,EAAE,CAAA;IAClD,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACH,OAAO;QACP,aAAa;QACb,OAAO;QACP,KAAK;QACL,YAAY;QACZ,oBAAoB;QACpB,cAAc;QACd,yBAAyB;KAC5B,CAAA;AACL,CAAC","sourcesContent":["import { useCallback, useEffect, useState, useId } from 'react'\n\nimport { audioDeviceManager } from '../AudioDeviceManager'\nimport { AudioDevice } from '../AudioStudio.types'\n\n/**\n * React hook for managing audio input devices\n */\nexport function useAudioDevices() {\n const [devices, setDevices] = useState<AudioDevice[]>([])\n const [currentDevice, setCurrentDevice] = useState<AudioDevice | null>(null)\n const [loading, setLoading] = useState(true)\n const [error, setError] = useState<Error | null>(null)\n\n // Generate unique instance ID for debugging\n const instanceId = useId().replace(/:/g, '').slice(0, 5)\n\n // Load devices on mount\n useEffect(() => {\n let isMounted = true\n\n const loadDevices = async () => {\n try {\n setLoading(true)\n setError(null)\n\n // Load available devices\n const availableDevices =\n await audioDeviceManager.getAvailableDevices()\n if (isMounted) setDevices(availableDevices)\n\n // Get current device\n const device = await audioDeviceManager.getCurrentDevice()\n if (isMounted) setCurrentDevice(device)\n } catch (err) {\n audioDeviceManager\n .getLogger()\n ?.error('Failed to load audio devices:', err)\n if (isMounted)\n setError(\n err instanceof Error\n ? err\n : new Error('Failed to load audio devices')\n )\n } finally {\n if (isMounted) setLoading(false)\n }\n }\n\n loadDevices()\n\n // Set up device change listener\n const removeListener = audioDeviceManager.addDeviceChangeListener(\n (updatedDevices: AudioDevice[]) => {\n audioDeviceManager\n .getLogger()\n ?.debug(\n `🎛️ useAudioDevices [${instanceId}] received device change. Count: ${updatedDevices.length}`\n )\n\n if (isMounted) {\n setDevices(updatedDevices)\n\n // If our current device is no longer available, update it\n if (\n currentDevice &&\n !updatedDevices.some(\n (d: AudioDevice) => d.id === currentDevice.id\n )\n ) {\n audioDeviceManager\n .getLogger()\n ?.debug(\n `🎛️ useAudioDevices [${instanceId}] Current device ${currentDevice.id} no longer available, updating`\n )\n audioDeviceManager\n .getCurrentDevice()\n .then((newDevice: AudioDevice | null) => {\n if (isMounted) {\n setCurrentDevice(newDevice)\n }\n })\n }\n }\n }\n )\n\n return () => {\n isMounted = false\n removeListener()\n }\n }, [])\n\n /**\n * Select a specific audio input device\n * @param deviceId The ID of the device to select\n * @returns Promise resolving to a boolean indicating success\n */\n const selectDevice = useCallback(\n async (deviceId: string): Promise<boolean> => {\n try {\n setLoading(true)\n setError(null)\n\n const success = await audioDeviceManager.selectDevice(deviceId)\n\n if (success) {\n // Get the updated current device after selection\n const device = await audioDeviceManager.getCurrentDevice()\n setCurrentDevice(device)\n }\n\n return success\n } catch (err) {\n audioDeviceManager\n .getLogger()\n ?.error('Failed to select audio device:', err)\n setError(\n err instanceof Error\n ? err\n : new Error('Failed to select audio device')\n )\n return false\n } finally {\n setLoading(false)\n }\n },\n []\n )\n\n /**\n * Reset to the default audio input device\n * @returns Promise resolving to a boolean indicating success\n */\n const resetToDefaultDevice = useCallback(async (): Promise<boolean> => {\n try {\n setLoading(true)\n setError(null)\n\n const success = await audioDeviceManager.resetToDefaultDevice()\n\n if (success) {\n // Get the updated current device after reset\n const device = await audioDeviceManager.getCurrentDevice()\n setCurrentDevice(device)\n }\n\n return success\n } catch (err) {\n audioDeviceManager\n .getLogger()\n ?.error('Failed to reset to default audio device:', err)\n setError(\n err instanceof Error\n ? err\n : new Error('Failed to reset to default audio device')\n )\n return false\n } finally {\n setLoading(false)\n }\n }, [])\n\n /**\n * Refresh the list of available devices\n */\n const refreshDevices = useCallback(async (): Promise<AudioDevice[]> => {\n try {\n setLoading(true)\n setError(null)\n\n const updatedDevices = await audioDeviceManager.refreshDevices()\n setDevices(updatedDevices)\n\n // Also refresh the current device\n const device = await audioDeviceManager.getCurrentDevice()\n setCurrentDevice(device)\n\n return updatedDevices\n } catch (err) {\n audioDeviceManager\n .getLogger()\n ?.error('Failed to refresh audio devices:', err)\n setError(\n err instanceof Error\n ? err\n : new Error('Failed to refresh audio devices')\n )\n return []\n } finally {\n setLoading(false)\n }\n }, [])\n\n /**\n * Initialize device detection\n * Useful for restarting device detection if it failed initially\n */\n const initializeDeviceDetection = useCallback(() => {\n audioDeviceManager.initializeDeviceDetection()\n }, [])\n\n return {\n devices,\n currentDevice,\n loading,\n error,\n selectDevice,\n resetToDefaultDevice,\n refreshDevices,\n initializeDeviceDetection,\n }\n}\n"]}
@@ -0,0 +1,23 @@
1
+ // src/index.ts
2
+ import { extractRawWavAnalysis, extractAudioAnalysis, } from './AudioAnalysis/extractAudioAnalysis';
3
+ import { extractAudioData } from './AudioAnalysis/extractAudioData';
4
+ import { extractMelSpectrogram, MAX_DURATION_MS, } from './AudioAnalysis/extractMelSpectrogram';
5
+ import { extractPreview } from './AudioAnalysis/extractPreview';
6
+ import { initMelStreamingWasm, computeMelFrameWasm, } from './AudioAnalysis/melSpectrogramWasm';
7
+ import { AudioRecorderProvider, useSharedAudioRecorder, } from './AudioRecorder.provider';
8
+ import AudioStudioModule from './AudioStudioModule';
9
+ import { trimAudio } from './trimAudio';
10
+ import { useAudioRecorder } from './useAudioRecorder';
11
+ export * from './utils/convertPCMToFloat32';
12
+ export * from './utils/getWavFileInfo';
13
+ export * from './utils/writeWavHeader';
14
+ // Export platform capabilities
15
+ export { getPlatformCapabilities, isEncodingSupported, isBitDepthSupported, getFallbackEncoding, getFallbackBitDepth, validateRecordingConfig, } from './constants/platformLimitations';
16
+ // Export AudioDeviceManager
17
+ export { AudioDeviceManager, audioDeviceManager } from './AudioDeviceManager';
18
+ // Export useAudioDevices hook
19
+ export { useAudioDevices } from './hooks/useAudioDevices';
20
+ export { AudioRecorderProvider, AudioStudioModule, extractRawWavAnalysis, extractAudioAnalysis, extractPreview, trimAudio, extractAudioData, extractMelSpectrogram, initMelStreamingWasm, computeMelFrameWasm, MAX_DURATION_MS, useAudioRecorder, useSharedAudioRecorder, };
21
+ /** @deprecated Use AudioStudioModule instead */
22
+ export const ExpoAudioStreamModule = AudioStudioModule;
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,eAAe;AAEf,OAAO,EACH,qBAAqB,EACrB,oBAAoB,GACvB,MAAM,sCAAsC,CAAA;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EACH,qBAAqB,EACrB,eAAe,GAClB,MAAM,uCAAuC,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAA;AAC/D,OAAO,EACH,oBAAoB,EACpB,mBAAmB,GACtB,MAAM,oCAAoC,CAAA;AAC3C,OAAO,EACH,qBAAqB,EACrB,sBAAsB,GACzB,MAAM,0BAA0B,CAAA;AACjC,OAAO,iBAAiB,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAErD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,wBAAwB,CAAA;AACtC,cAAc,wBAAwB,CAAA;AAEtC,+BAA+B;AAC/B,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GAE1B,MAAM,iCAAiC,CAAA;AAExC,4BAA4B;AAC5B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE7E,8BAA8B;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EACH,qBAAqB,EACrB,iBAAiB,EACjB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,sBAAsB,GACzB,CAAA;AAMD,gDAAgD;AAChD,MAAM,CAAC,MAAM,qBAAqB,GAAG,iBAAiB,CAAA","sourcesContent":["// src/index.ts\n\nimport {\n extractRawWavAnalysis,\n extractAudioAnalysis,\n} from './AudioAnalysis/extractAudioAnalysis'\nimport { extractAudioData } from './AudioAnalysis/extractAudioData'\nimport {\n extractMelSpectrogram,\n MAX_DURATION_MS,\n} from './AudioAnalysis/extractMelSpectrogram'\nimport { extractPreview } from './AudioAnalysis/extractPreview'\nimport {\n initMelStreamingWasm,\n computeMelFrameWasm,\n} from './AudioAnalysis/melSpectrogramWasm'\nimport {\n AudioRecorderProvider,\n useSharedAudioRecorder,\n} from './AudioRecorder.provider'\nimport AudioStudioModule from './AudioStudioModule'\nimport { trimAudio } from './trimAudio'\nimport { useAudioRecorder } from './useAudioRecorder'\n\nexport * from './utils/convertPCMToFloat32'\nexport * from './utils/getWavFileInfo'\nexport * from './utils/writeWavHeader'\n\n// Export platform capabilities\nexport {\n getPlatformCapabilities,\n isEncodingSupported,\n isBitDepthSupported,\n getFallbackEncoding,\n getFallbackBitDepth,\n validateRecordingConfig,\n type PlatformCapabilities,\n} from './constants/platformLimitations'\n\n// Export AudioDeviceManager\nexport { AudioDeviceManager, audioDeviceManager } from './AudioDeviceManager'\n\n// Export useAudioDevices hook\nexport { useAudioDevices } from './hooks/useAudioDevices'\n\nexport {\n AudioRecorderProvider,\n AudioStudioModule,\n extractRawWavAnalysis,\n extractAudioAnalysis,\n extractPreview,\n trimAudio,\n extractAudioData,\n extractMelSpectrogram,\n initMelStreamingWasm,\n computeMelFrameWasm,\n MAX_DURATION_MS,\n useAudioRecorder,\n useSharedAudioRecorder,\n}\n\n// Export all types\nexport type * from './AudioAnalysis/AudioAnalysis.types'\nexport type * from './AudioStudio.types'\n\n/** @deprecated Use AudioStudioModule instead */\nexport const ExpoAudioStreamModule = AudioStudioModule\n"]}
@@ -0,0 +1,69 @@
1
+ import { LegacyEventEmitter } from 'expo-modules-core';
2
+ import AudioStudioModule from './AudioStudioModule';
3
+ import { cleanNativeOptions } from './utils/cleanNativeOptions';
4
+ // Create a single emitter instance
5
+ const emitter = new LegacyEventEmitter(AudioStudioModule);
6
+ /**
7
+ * Trims an audio file based on the provided options.
8
+ *
9
+ * @experimental This API is experimental and not fully optimized for production use.
10
+ * Performance may vary based on file size and device capabilities.
11
+ * Future versions may include breaking changes.
12
+ *
13
+ * @param options Configuration options for the trimming operation
14
+ * @param progressCallback Optional callback to receive progress updates
15
+ * @returns Promise resolving to the trimmed audio file information, including processing time
16
+ */
17
+ export async function trimAudio(options, progressCallback) {
18
+ // Validation
19
+ if (!options.fileUri) {
20
+ throw new Error('fileUri is required');
21
+ }
22
+ const mode = options.mode ?? 'single';
23
+ if (mode === 'single') {
24
+ if (options.startTimeMs === undefined &&
25
+ options.endTimeMs === undefined) {
26
+ throw new Error('At least one of startTimeMs or endTimeMs must be provided in single mode');
27
+ }
28
+ }
29
+ else if (mode === 'keep' || mode === 'remove') {
30
+ if (!options.ranges || options.ranges.length === 0) {
31
+ throw new Error('ranges must be provided and non-empty for keep or remove modes');
32
+ }
33
+ }
34
+ else {
35
+ throw new Error(`Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`);
36
+ }
37
+ // Set up progress event listener if callback is provided
38
+ let subscription;
39
+ if (progressCallback) {
40
+ subscription = emitter.addListener('TrimProgress', (event) => {
41
+ progressCallback(event);
42
+ });
43
+ }
44
+ try {
45
+ // Clean non-serializable/undefined values to avoid Android Kotlin bridge crash
46
+ const result = await AudioStudioModule.trimAudio(cleanNativeOptions(options));
47
+ return result;
48
+ }
49
+ finally {
50
+ if (subscription) {
51
+ subscription.remove();
52
+ }
53
+ }
54
+ }
55
+ /**
56
+ * Simplified version of trimAudio that returns only the URI of the trimmed file.
57
+ *
58
+ * @experimental This API is experimental and not fully optimized for production use.
59
+ * Performance may vary based on file size and device capabilities.
60
+ * Future versions may include breaking changes.
61
+ *
62
+ * @param options Configuration options for the trimming operation
63
+ * @returns Promise resolving to the URI of the trimmed audio file
64
+ */
65
+ export async function trimAudioSimple(options) {
66
+ const result = await trimAudio(options);
67
+ return result.uri;
68
+ }
69
+ //# sourceMappingURL=trimAudio.js.map