@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,899 @@
1
+ // packages/audio-studio/src/AudioStudio.types.ts
2
+ import {
3
+ AudioAnalysis,
4
+ AudioFeaturesOptions,
5
+ DecodingConfig,
6
+ } from './AudioAnalysis/AudioAnalysis.types'
7
+ import { AudioAnalysisEvent } from './events'
8
+
9
+ export interface CompressionInfo {
10
+ /** Size of the compressed audio data in bytes */
11
+ size: number
12
+ /** MIME type of the compressed audio (e.g., 'audio/aac', 'audio/opus') */
13
+ mimeType: string
14
+ /** Bitrate of the compressed audio in bits per second */
15
+ bitrate: number
16
+ /** Format of the compression (e.g., 'aac', 'opus') */
17
+ format: string
18
+ /** URI to the compressed audio file if available */
19
+ compressedFileUri?: string
20
+ }
21
+
22
+ export interface AudioStreamStatus {
23
+ /** Indicates whether audio recording is currently active */
24
+ isRecording: boolean
25
+ /** Indicates whether recording is in a paused state */
26
+ isPaused: boolean
27
+ /** Duration of the current recording in milliseconds */
28
+ durationMs: number
29
+ /** Size of the recorded audio data in bytes */
30
+ size: number
31
+ /** Interval in milliseconds at which recording data is emitted */
32
+ interval: number
33
+ /** Interval in milliseconds at which analysis data is emitted */
34
+ intervalAnalysis: number
35
+ /** MIME type of the recorded audio (e.g., 'audio/wav') */
36
+ mimeType: string
37
+ /** Information about audio compression if enabled */
38
+ compression?: CompressionInfo
39
+ }
40
+
41
+ interface AudioDataEventBase {
42
+ /** Current position in the audio stream in bytes */
43
+ position: number
44
+ /** URI to the file being recorded */
45
+ fileUri: string
46
+ /** Size of the current data chunk in bytes */
47
+ eventDataSize: number
48
+ /** Total size of the recording so far in bytes */
49
+ totalSize: number
50
+ /** Information about compression if enabled, including the compressed data chunk */
51
+ compression?: CompressionInfo & {
52
+ /** Base64 (native) or Blob (web) encoded compressed data chunk */
53
+ data?: string | Blob
54
+ }
55
+ }
56
+
57
+ export interface AudioDataEventRaw extends AudioDataEventBase {
58
+ /** Audio data as base64 string (native), Float32Array (web), or Int16Array (web) */
59
+ data: string | Float32Array | Int16Array
60
+ streamFormat?: undefined | 'raw'
61
+ }
62
+
63
+ export interface AudioDataEventFloat32 extends AudioDataEventBase {
64
+ /** Audio data as Float32Array with samples in [-1, 1] range */
65
+ data: Float32Array
66
+ streamFormat: 'float32'
67
+ }
68
+
69
+ export type AudioDataEvent = AudioDataEventRaw | AudioDataEventFloat32
70
+
71
+ /**
72
+ * Audio encoding types supported by the library.
73
+ *
74
+ * Platform support:
75
+ * - `pcm_8bit`: Android only (iOS/Web will fallback to 16-bit)
76
+ * - `pcm_16bit`: All platforms
77
+ * - `pcm_32bit`: All platforms
78
+ *
79
+ * @see {@link https://github.com/deeeed/audiolab/blob/main/packages/audio-studio/docs/PLATFORM_LIMITATIONS.md | Platform Limitations}
80
+ */
81
+ export type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit'
82
+
83
+ /**
84
+ * Supported audio sample rates in Hz.
85
+ * All platforms support these standard rates.
86
+ */
87
+ export type SampleRate = 16000 | 44100 | 48000
88
+
89
+ /**
90
+ * Audio bit depth (bits per sample).
91
+ *
92
+ * Platform support:
93
+ * - `8`: Android only (iOS/Web will fallback to 16)
94
+ * - `16`: All platforms (recommended for compatibility)
95
+ * - `32`: All platforms
96
+ *
97
+ * @see {@link https://github.com/deeeed/audiolab/blob/main/packages/audio-studio/docs/PLATFORM_LIMITATIONS.md | Platform Limitations}
98
+ */
99
+ export type BitDepth = 8 | 16 | 32
100
+
101
+ /**
102
+ * PCM format string representation.
103
+ * @deprecated Use `EncodingType` directly
104
+ */
105
+ export type PCMFormat = `pcm_${BitDepth}bit`
106
+
107
+ export type ConsoleLike = {
108
+ /** Logs a message with optional arguments */
109
+ log: (message: string, ...args: unknown[]) => void
110
+ /** Logs a debug message with optional arguments */
111
+ debug: (message: string, ...args: unknown[]) => void
112
+ /** Logs an info message with optional arguments */
113
+ info: (message: string, ...args: unknown[]) => void
114
+ /** Logs a warning message with optional arguments */
115
+ warn: (message: string, ...args: unknown[]) => void
116
+ /** Logs an error message with optional arguments */
117
+ error: (message: string, ...args: unknown[]) => void
118
+ }
119
+
120
+ export interface Chunk {
121
+ /** Transcribed text content */
122
+ text: string
123
+ /** Start and end timestamp in seconds [start, end] where end can be null if ongoing */
124
+ timestamp: [number, number | null]
125
+ }
126
+
127
+ export interface TranscriberData {
128
+ /** Unique identifier for the transcription */
129
+ id: string
130
+ /** Indicates if the transcriber is currently processing */
131
+ isBusy: boolean
132
+ /** Complete transcribed text */
133
+ text: string
134
+ /** Start time of the transcription in milliseconds */
135
+ startTime: number
136
+ /** End time of the transcription in milliseconds */
137
+ endTime: number
138
+ /** Array of transcribed text chunks with timestamps */
139
+ chunks: Chunk[]
140
+ }
141
+
142
+ export interface AudioRecording {
143
+ /** URI to the recorded audio file */
144
+ fileUri: string
145
+ /** Filename of the recorded audio */
146
+ filename: string
147
+ /** Duration of the recording in milliseconds */
148
+ durationMs: number
149
+ /** Size of the recording in bytes */
150
+ size: number
151
+ /** MIME type of the recorded audio */
152
+ mimeType: string
153
+ /** Number of audio channels (1 for mono, 2 for stereo) */
154
+ channels: number
155
+ /** Bit depth of the audio (8, 16, or 32 bits) */
156
+ bitDepth: BitDepth
157
+ /** Sample rate of the audio in Hz */
158
+ sampleRate: SampleRate
159
+ /** Timestamp when the recording was created */
160
+ createdAt?: number
161
+ /** Array of transcription data if available */
162
+ transcripts?: TranscriberData[]
163
+ /** Analysis data for the recording if processing was enabled */
164
+ analysisData?: AudioAnalysis
165
+ /** Information about compression if enabled, including the URI to the compressed file */
166
+ compression?: CompressionInfo & {
167
+ /** URI to the compressed audio file */
168
+ compressedFileUri: string
169
+ }
170
+ }
171
+
172
+ export interface StartRecordingResult {
173
+ /** URI to the file being recorded */
174
+ fileUri: string
175
+ /** MIME type of the recording */
176
+ mimeType: string
177
+ /** Number of audio channels (1 for mono, 2 for stereo) */
178
+ channels?: number
179
+ /** Bit depth of the audio (8, 16, or 32 bits) */
180
+ bitDepth?: BitDepth
181
+ /** Sample rate of the audio in Hz */
182
+ sampleRate?: SampleRate
183
+ /** Information about compression if enabled, including the URI to the compressed file */
184
+ compression?: CompressionInfo & {
185
+ /** URI to the compressed audio file */
186
+ compressedFileUri: string
187
+ }
188
+ }
189
+
190
+ export interface AudioSessionConfig {
191
+ /**
192
+ * Audio session category that defines the audio behavior
193
+ * - 'Ambient': Audio continues with silent switch, mixes with other audio
194
+ * - 'SoloAmbient': Audio continues with silent switch, interrupts other audio
195
+ * - 'Playback': Audio continues in background, interrupts other audio
196
+ * - 'Record': Optimized for recording, interrupts other audio
197
+ * - 'PlayAndRecord': Allows simultaneous playback and recording
198
+ * - 'MultiRoute': Routes audio to multiple outputs simultaneously
199
+ */
200
+ category?:
201
+ | 'Ambient'
202
+ | 'SoloAmbient'
203
+ | 'Playback'
204
+ | 'Record'
205
+ | 'PlayAndRecord'
206
+ | 'MultiRoute'
207
+ /**
208
+ * Audio session mode that defines the behavior for specific use cases
209
+ * - 'Default': Standard audio behavior
210
+ * - 'VoiceChat': Optimized for voice chat applications
211
+ * - 'VideoChat': Optimized for video chat applications
212
+ * - 'GameChat': Optimized for in-game chat
213
+ * - 'VideoRecording': Optimized for video recording
214
+ * - 'Measurement': Optimized for audio measurement
215
+ * - 'MoviePlayback': Optimized for movie playback
216
+ * - 'SpokenAudio': Optimized for spoken audio content
217
+ */
218
+ mode?:
219
+ | 'Default'
220
+ | 'VoiceChat'
221
+ | 'VideoChat'
222
+ | 'GameChat'
223
+ | 'VideoRecording'
224
+ | 'Measurement'
225
+ | 'MoviePlayback'
226
+ | 'SpokenAudio'
227
+ /**
228
+ * Options that modify the behavior of the audio session category
229
+ * - 'MixWithOthers': Allows mixing with other active audio sessions
230
+ * - 'DuckOthers': Reduces the volume of other audio sessions
231
+ * - 'InterruptSpokenAudioAndMixWithOthers': Interrupts spoken audio and mixes with others
232
+ * - 'AllowBluetooth': Allows audio routing to Bluetooth devices
233
+ * - 'AllowBluetoothA2DP': Allows audio routing to Bluetooth A2DP devices
234
+ * - 'AllowAirPlay': Allows audio routing to AirPlay devices
235
+ * - 'DefaultToSpeaker': Routes audio to the speaker by default
236
+ */
237
+ categoryOptions?: (
238
+ | 'MixWithOthers'
239
+ | 'DuckOthers'
240
+ | 'InterruptSpokenAudioAndMixWithOthers'
241
+ | 'AllowBluetooth'
242
+ | 'AllowBluetoothA2DP'
243
+ | 'AllowAirPlay'
244
+ | 'DefaultToSpeaker'
245
+ )[]
246
+ }
247
+
248
+ export interface IOSConfig {
249
+ /** Configuration for the iOS audio session */
250
+ audioSession?: AudioSessionConfig
251
+ }
252
+
253
+ /** Android platform specific configuration options */
254
+ export interface AndroidConfig {
255
+ /**
256
+ * Audio focus strategy for handling interruptions and background behavior
257
+ *
258
+ * - `'background'`: Continue recording when app loses focus (voice recorders, transcription apps)
259
+ * - `'interactive'`: Pause when losing focus, resume when gaining (music apps, games)
260
+ * - `'communication'`: Maintain priority for real-time communication (video calls, voice chat)
261
+ * - `'none'`: No automatic audio focus management (custom handling)
262
+ *
263
+ * @default 'background' when keepAwake=true, 'interactive' otherwise
264
+ */
265
+ audioFocusStrategy?: 'background' | 'interactive' | 'communication' | 'none'
266
+ }
267
+
268
+ /** Web platform specific configuration options */
269
+ export interface WebConfig {
270
+ // Reserved for future web-specific options
271
+ }
272
+
273
+ // Add new type for interruption reasons
274
+ export type RecordingInterruptionReason =
275
+ /** Audio focus was lost to another app */
276
+ | 'audioFocusLoss'
277
+ /** Audio focus was regained */
278
+ | 'audioFocusGain'
279
+ /** Recording was interrupted by a phone call */
280
+ | 'phoneCall'
281
+ /** Phone call that interrupted recording has ended */
282
+ | 'phoneCallEnded'
283
+ /** Recording was stopped by the system or another app */
284
+ | 'recordingStopped'
285
+ /** Recording device was disconnected */
286
+ | 'deviceDisconnected'
287
+ /** Recording switched to default device after disconnection */
288
+ | 'deviceFallback'
289
+ /** A new audio device was connected */
290
+ | 'deviceConnected'
291
+ /** Device switching failed */
292
+ | 'deviceSwitchFailed'
293
+
294
+ // Add new interface for interruption events
295
+ export interface RecordingInterruptionEvent {
296
+ /** The reason for the recording interruption */
297
+ reason: RecordingInterruptionReason
298
+ /** Indicates whether the recording is paused due to the interruption */
299
+ isPaused: boolean
300
+ }
301
+
302
+ export interface AudioDeviceCapabilities {
303
+ /** Supported sample rates for the device */
304
+ sampleRates: number[]
305
+ /** Supported channel counts for the device */
306
+ channelCounts: number[]
307
+ /** Supported bit depths for the device */
308
+ bitDepths: number[]
309
+ /** Whether the device supports echo cancellation */
310
+ hasEchoCancellation?: boolean
311
+ /** Whether the device supports noise suppression */
312
+ hasNoiseSuppression?: boolean
313
+ /** Whether the device supports automatic gain control */
314
+ hasAutomaticGainControl?: boolean
315
+ }
316
+
317
+ export interface AudioDevice {
318
+ /** Unique identifier for the device */
319
+ id: string
320
+ /** Human-readable name of the device */
321
+ name: string
322
+ /** Device type (builtin_mic, bluetooth, etc.) */
323
+ type: string
324
+ /** Whether this is the system default device */
325
+ isDefault: boolean
326
+ /** Audio capabilities for the device */
327
+ capabilities: AudioDeviceCapabilities
328
+ /** Whether the device is currently available */
329
+ isAvailable: boolean
330
+ }
331
+
332
+ /** Defines how recording should behave when a device becomes unavailable */
333
+ export const DeviceDisconnectionBehavior = {
334
+ /** Pause recording when device disconnects */
335
+ PAUSE: 'pause',
336
+ /** Switch to default device and continue recording */
337
+ FALLBACK: 'fallback',
338
+ } as const
339
+
340
+ /** Type for DeviceDisconnectionBehavior values */
341
+ export type DeviceDisconnectionBehaviorType =
342
+ (typeof DeviceDisconnectionBehavior)[keyof typeof DeviceDisconnectionBehavior]
343
+
344
+ /**
345
+ * Configuration for audio output files during recording
346
+ */
347
+ export interface OutputConfig {
348
+ /**
349
+ * Configuration for the primary (uncompressed) output file
350
+ */
351
+ primary?: {
352
+ /** Whether to create the primary output file (default: true) */
353
+ enabled?: boolean
354
+ /** Format for the primary output (currently only 'wav' is supported) */
355
+ format?: 'wav'
356
+ }
357
+
358
+ /**
359
+ * Configuration for the compressed output file
360
+ */
361
+ compressed?: {
362
+ /** Whether to create a compressed output file (default: false) */
363
+ enabled?: boolean
364
+ /**
365
+ * Format for compression
366
+ * - 'aac': Advanced Audio Coding - supported on all platforms
367
+ * - 'opus': Opus encoding - supported on Android and Web; on iOS will automatically fall back to AAC
368
+ */
369
+ format?: 'aac' | 'opus'
370
+ /** Bitrate for compression in bits per second (default: 128000) */
371
+ bitrate?: number
372
+ /**
373
+ * Prefer raw stream over container format (Android only)
374
+ * - true: Use raw AAC stream (.aac files) like in v2.10.6
375
+ * - false/undefined: Use M4A container (.m4a files) for better seeking support
376
+ * Note: iOS always produces M4A containers and ignores this flag
377
+ */
378
+ preferRawStream?: boolean
379
+ }
380
+
381
+ // Future enhancement: Post-processing pipeline
382
+ // postProcessing?: {
383
+ // normalize?: boolean
384
+ // trimSilence?: boolean
385
+ // noiseReduction?: boolean
386
+ // customProcessors?: AudioProcessor[]
387
+ // }
388
+ }
389
+
390
+ export interface RecordingConfig {
391
+ /** Sample rate for recording in Hz (16000, 44100, or 48000) */
392
+ sampleRate?: SampleRate
393
+
394
+ /** Number of audio channels (1 for mono, 2 for stereo) */
395
+ channels?: 1 | 2
396
+
397
+ /**
398
+ * Encoding type for the recording.
399
+ *
400
+ * Platform limitations:
401
+ * - `pcm_8bit`: Android only (iOS/Web will fallback to `pcm_16bit` with warning)
402
+ * - `pcm_16bit`: All platforms (recommended for cross-platform compatibility)
403
+ * - `pcm_32bit`: All platforms
404
+ *
405
+ * The library will automatically validate and adjust the encoding based on
406
+ * platform capabilities. A warning will be logged if fallback is required.
407
+ *
408
+ * @default 'pcm_16bit'
409
+ * @see {@link EncodingType}
410
+ * @see {@link https://github.com/deeeed/audiolab/blob/main/packages/audio-studio/docs/PLATFORM_LIMITATIONS.md | Platform Limitations}
411
+ */
412
+ encoding?: EncodingType
413
+
414
+ /** Interval in milliseconds at which to emit recording data (minimum: 10ms) */
415
+ interval?: number
416
+
417
+ /** Interval in milliseconds at which to emit analysis data (minimum: 10ms) */
418
+ intervalAnalysis?: number
419
+
420
+ /** Keep the device awake while recording (default is false) */
421
+ keepAwake?: boolean
422
+
423
+ /** Show a notification during recording (default is false) */
424
+ showNotification?: boolean
425
+
426
+ /** Show waveform in the notification (Android only, when showNotification is true) */
427
+ showWaveformInNotification?: boolean
428
+
429
+ /** Configuration for the notification */
430
+ notification?: NotificationConfig
431
+
432
+ /** Enable audio processing (default is false) */
433
+ enableProcessing?: boolean
434
+
435
+ /** iOS-specific configuration */
436
+ ios?: IOSConfig
437
+
438
+ /** Android-specific configuration */
439
+ android?: AndroidConfig
440
+
441
+ /** Web-specific configuration options */
442
+ web?: WebConfig
443
+
444
+ /** Duration of each segment in milliseconds for analysis (default: 100) */
445
+ segmentDurationMs?: number
446
+
447
+ /** Feature options to extract during audio processing */
448
+ features?: AudioFeaturesOptions
449
+
450
+ /** Callback function to handle audio stream data */
451
+ onAudioStream?: (_: AudioDataEvent) => Promise<void>
452
+
453
+ /** Callback function to handle audio features extraction results */
454
+ onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>
455
+
456
+ /**
457
+ * Configuration for audio output files
458
+ *
459
+ * Examples:
460
+ * - Primary only (default): `{ primary: { enabled: true } }`
461
+ * - Compressed only: `{ primary: { enabled: false }, compressed: { enabled: true, format: 'aac' } }`
462
+ * - Both outputs: `{ compressed: { enabled: true } }`
463
+ * - Streaming only: `{ primary: { enabled: false } }`
464
+ */
465
+ output?: OutputConfig
466
+
467
+ /** Whether to automatically resume recording after an interruption (default is false) */
468
+ autoResumeAfterInterruption?: boolean
469
+
470
+ /** Optional callback to handle recording interruptions */
471
+ onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void
472
+
473
+ /** Optional directory path where output files will be saved */
474
+ outputDirectory?: string // If not provided, uses default app directory
475
+ /** Optional filename for the recording (uses UUID if not provided) */
476
+ filename?: string // If not provided, uses UUID
477
+
478
+ /** ID of the device to use for recording (if not specified, uses default) */
479
+ deviceId?: string
480
+
481
+ /** How to handle device disconnection during recording */
482
+ deviceDisconnectionBehavior?: DeviceDisconnectionBehaviorType
483
+
484
+ /**
485
+ * Buffer duration in seconds. Controls the size of audio buffers
486
+ * used during recording. Smaller values reduce latency but increase
487
+ * CPU usage. Larger values improve efficiency but increase latency.
488
+ *
489
+ * Platform Notes:
490
+ * - iOS/macOS: Minimum effective 0.1s, uses accumulation below
491
+ * - Android: Respects all sizes within hardware limits
492
+ * - Web: Fully configurable
493
+ *
494
+ * Default: undefined (uses platform default ~23ms at 44.1kHz)
495
+ * Recommended: 0.01 - 0.5 seconds
496
+ * Optimal iOS: >= 0.1 seconds
497
+ */
498
+ bufferDurationSeconds?: number
499
+
500
+ /**
501
+ * Format for the audio stream data delivered to `onAudioStream`.
502
+ *
503
+ * - `'raw'` (default): base64-encoded PCM bytes on native, Float32Array on web
504
+ * - `'float32'`: Float32Array with samples in [-1, 1] on all platforms.
505
+ * Eliminates base64 encode/decode overhead on the native bridge.
506
+ * Android (new arch): delivered as Float32Array via JSI.
507
+ * iOS: delivered as regular Array<number>, normalized to Float32Array in JS.
508
+ *
509
+ * @default 'raw'
510
+ */
511
+ streamFormat?: 'float32' | 'raw'
512
+ }
513
+
514
+ export interface NotificationConfig {
515
+ /** Title of the notification */
516
+ title?: string
517
+
518
+ /** Main text content of the notification */
519
+ text?: string
520
+
521
+ /** Icon to be displayed in the notification (resource name or URI) */
522
+ icon?: string
523
+
524
+ /** Android-specific notification configuration */
525
+ android?: {
526
+ /** Unique identifier for the notification channel */
527
+ channelId?: string
528
+
529
+ /** User-visible name of the notification channel */
530
+ channelName?: string
531
+
532
+ /** User-visible description of the notification channel */
533
+ channelDescription?: string
534
+
535
+ /** Unique identifier for this notification */
536
+ notificationId?: number
537
+
538
+ /** List of actions that can be performed from the notification */
539
+ actions?: NotificationAction[]
540
+
541
+ /** Configuration for the waveform visualization in the notification */
542
+ waveform?: WaveformConfig
543
+
544
+ /** Color of the notification LED (if device supports it) */
545
+ lightColor?: string
546
+
547
+ /** Priority of the notification (affects how it's displayed) */
548
+ priority?: 'min' | 'low' | 'default' | 'high' | 'max'
549
+
550
+ /** Accent color for the notification (used for the app icon and buttons) */
551
+ accentColor?: string
552
+
553
+ /** Whether to show pause/resume actions in the notification (default: true) */
554
+ showPauseResumeActions?: boolean
555
+ }
556
+
557
+ /** iOS-specific notification configuration */
558
+ ios?: {
559
+ /** Identifier for the notification category (used for grouping similar notifications) */
560
+ categoryIdentifier?: string
561
+ }
562
+ }
563
+
564
+ export interface NotificationAction {
565
+ /** Display title for the action */
566
+ title: string
567
+
568
+ /** Unique identifier for the action */
569
+ identifier: string
570
+
571
+ /** Icon to be displayed for the action (Android only) */
572
+ icon?: string
573
+ }
574
+
575
+ export interface WaveformConfig {
576
+ /** The color of the waveform (e.g., "#FFFFFF" for white) */
577
+ color?: string // The color of the waveform (e.g., "#FFFFFF" for white)
578
+ /** Opacity of the waveform (0.0 - 1.0) */
579
+ opacity?: number // Opacity of the waveform (0.0 - 1.0)
580
+ /** Width of the waveform line (default: 1.5) */
581
+ strokeWidth?: number // Width of the waveform line (default: 1.5)
582
+ /** Drawing style: "stroke" for outline, "fill" for solid */
583
+ style?: 'stroke' | 'fill' // Drawing style: "stroke" for outline, "fill" for solid
584
+ /** Whether to mirror the waveform (symmetrical display) */
585
+ mirror?: boolean // Whether to mirror the waveform (symmetrical display)
586
+ /** Height of the waveform view in dp (default: 64) */
587
+ height?: number // Height of the waveform view in dp (default: 64)
588
+ }
589
+
590
+ export interface ExtractAudioDataOptions {
591
+ /** URI of the audio file to extract data from */
592
+ fileUri: string
593
+ /** Start time in milliseconds (for time-based range) */
594
+ startTimeMs?: number
595
+ /** End time in milliseconds (for time-based range) */
596
+ endTimeMs?: number
597
+ /** Start position in bytes (for byte-based range) */
598
+ position?: number
599
+ /** Length in bytes to extract (for byte-based range) */
600
+ length?: number
601
+ /** Include normalized audio data in [-1, 1] range */
602
+ includeNormalizedData?: boolean
603
+ /** Include base64 encoded string representation of the audio data */
604
+ includeBase64Data?: boolean
605
+ /** Include WAV header in the PCM data (makes it a valid WAV file) */
606
+ includeWavHeader?: boolean
607
+ /** Logger for debugging - can pass console directly. */
608
+ logger?: ConsoleLike
609
+ /** Compute the checksum of the PCM data */
610
+ computeChecksum?: boolean
611
+ /** Target config for the normalized audio (Android and Web) */
612
+ decodingOptions?: DecodingConfig
613
+ }
614
+
615
+ export interface ExtractedAudioData {
616
+ /** Raw PCM audio data */
617
+ pcmData: Uint8Array
618
+ /** Normalized audio data in [-1, 1] range (when includeNormalizedData is true) */
619
+ normalizedData?: Float32Array
620
+ /** Base64 encoded string representation of the audio data (when includeBase64Data is true) */
621
+ base64Data?: string
622
+ /** Sample rate in Hz (e.g., 44100, 48000) */
623
+ sampleRate: number
624
+ /** Number of audio channels (1 for mono, 2 for stereo) */
625
+ channels: number
626
+ /** Bits per sample (8, 16, or 32) */
627
+ bitDepth: BitDepth
628
+ /** Duration of the audio in milliseconds */
629
+ durationMs: number
630
+ /** PCM format identifier (e.g., "pcm_16bit") */
631
+ format: PCMFormat
632
+ /** Total number of audio samples per channel */
633
+ samples: number
634
+ /** Whether the pcmData includes a WAV header */
635
+ hasWavHeader?: boolean
636
+ /** CRC32 Checksum of PCM data */
637
+ checksum?: number
638
+ }
639
+
640
+ export interface UseAudioRecorderState {
641
+ /**
642
+ * Prepares recording with the specified configuration without starting it.
643
+ *
644
+ * This method eliminates the latency between calling startRecording and the actual recording beginning.
645
+ * It pre-initializes all audio resources, requests permissions, and sets up audio sessions in advance,
646
+ * allowing for true zero-latency recording start when startRecording is called later.
647
+ *
648
+ * Technical benefits:
649
+ * - Eliminates audio pipeline initialization delay (50-300ms depending on platform)
650
+ * - Pre-allocates audio buffers to avoid memory allocation during recording start
651
+ * - Initializes audio hardware in advance (particularly important on iOS)
652
+ * - Requests and verifies permissions before the critical recording moment
653
+ *
654
+ * Use this method when:
655
+ * - You need zero-latency recording start (e.g., voice commands, musical applications)
656
+ * - You're building time-sensitive applications where missing initial audio would be problematic
657
+ * - You want to prepare resources during app initialization, screen loading, or preceding user interaction
658
+ * - You need to ensure recording starts reliably and instantly on all platforms
659
+ *
660
+ * @param config - The recording configuration, identical to what you would pass to startRecording
661
+ * @returns A promise that resolves when preparation is complete
662
+ *
663
+ * @example
664
+ * // Prepare during component mounting
665
+ * useEffect(() => {
666
+ * prepareRecording({
667
+ * sampleRate: 44100,
668
+ * channels: 1,
669
+ * encoding: 'pcm_16bit',
670
+ * });
671
+ * }, []);
672
+ *
673
+ * // Later when user taps record button, it starts with zero latency
674
+ * const handleRecordPress = () => startRecording({
675
+ * sampleRate: 44100,
676
+ * channels: 1,
677
+ * encoding: 'pcm_16bit',
678
+ * });
679
+ */
680
+ prepareRecording: (_: RecordingConfig) => Promise<void>
681
+ /** Starts recording with the specified configuration */
682
+ startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>
683
+ /** Stops the current recording and returns the recording data */
684
+ stopRecording: () => Promise<AudioRecording | null>
685
+ /** Pauses the current recording */
686
+ pauseRecording: () => Promise<void>
687
+ /** Resumes a paused recording */
688
+ resumeRecording: () => Promise<void>
689
+ /** Indicates whether recording is currently active */
690
+ isRecording: boolean
691
+ /** Indicates whether recording is in a paused state */
692
+ isPaused: boolean
693
+ /** Duration of the current recording in milliseconds */
694
+ durationMs: number // Duration of the recording
695
+ /** Size of the recorded audio in bytes */
696
+ size: number // Size in bytes of the recorded audio
697
+ /** Information about compression if enabled */
698
+ compression?: CompressionInfo
699
+ /** Analysis data for the recording if processing was enabled */
700
+ analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag
701
+ /** Optional callback to handle recording interruptions */
702
+ onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void
703
+ }
704
+
705
+ /**
706
+ * Represents an event emitted during the trimming process to report progress.
707
+ */
708
+ export interface TrimProgressEvent {
709
+ /**
710
+ * The percentage of the trimming process that has been completed, ranging from 0 to 100.
711
+ */
712
+ progress: number
713
+
714
+ /**
715
+ * The number of bytes that have been processed so far. This is optional and may not be provided in all implementations.
716
+ */
717
+ bytesProcessed?: number
718
+
719
+ /**
720
+ * The total number of bytes to process. This is optional and may not be provided in all implementations.
721
+ */
722
+ totalBytes?: number
723
+ }
724
+
725
+ /**
726
+ * Defines a time range in milliseconds for trimming operations.
727
+ */
728
+ export interface TimeRange {
729
+ /**
730
+ * The start time of the range in milliseconds.
731
+ */
732
+ startTimeMs: number
733
+
734
+ /**
735
+ * The end time of the range in milliseconds.
736
+ */
737
+ endTimeMs: number
738
+ }
739
+
740
+ /**
741
+ * Options for configuring the audio trimming operation.
742
+ */
743
+ export interface TrimAudioOptions {
744
+ /**
745
+ * The URI of the audio file to trim.
746
+ */
747
+ fileUri: string
748
+
749
+ /**
750
+ * The mode of trimming to apply.
751
+ * - `'single'`: Trims the audio to a single range defined by `startTimeMs` and `endTimeMs`.
752
+ * - `'keep'`: Keeps the specified `ranges` and removes all other portions of the audio.
753
+ * - `'remove'`: Removes the specified `ranges` and keeps the remaining portions of the audio.
754
+ * @default 'single'
755
+ */
756
+ mode?: 'single' | 'keep' | 'remove'
757
+
758
+ /**
759
+ * An array of time ranges to keep or remove, depending on the `mode`.
760
+ * - Required for `'keep'` and `'remove'` modes.
761
+ * - Ignored when `mode` is `'single'`.
762
+ */
763
+ ranges?: TimeRange[]
764
+
765
+ /**
766
+ * The start time in milliseconds for the `'single'` mode.
767
+ * - If not provided, trimming starts from the beginning of the audio (0 ms).
768
+ */
769
+ startTimeMs?: number
770
+
771
+ /**
772
+ * The end time in milliseconds for the `'single'` mode.
773
+ * - If not provided, trimming extends to the end of the audio.
774
+ */
775
+ endTimeMs?: number
776
+
777
+ /**
778
+ * The name of the output file. If not provided, a default name will be generated.
779
+ */
780
+ outputFileName?: string
781
+
782
+ /**
783
+ * Configuration for the output audio format.
784
+ */
785
+ outputFormat?: {
786
+ /**
787
+ * The format of the output audio file.
788
+ * - `'wav'`: Waveform Audio File Format (uncompressed).
789
+ * - `'aac'`: Advanced Audio Coding (compressed). Not supported on web platforms.
790
+ * - `'opus'`: Opus Interactive Audio Codec (compressed).
791
+ */
792
+ format: 'wav' | 'aac' | 'opus'
793
+
794
+ /**
795
+ * The sample rate of the output audio in Hertz (Hz).
796
+ * - If not provided, the input audio's sample rate is used.
797
+ */
798
+ sampleRate?: number
799
+
800
+ /**
801
+ * The number of channels in the output audio (e.g., 1 for mono, 2 for stereo).
802
+ * - If not provided, the input audio's channel count is used.
803
+ */
804
+ channels?: number
805
+
806
+ /**
807
+ * The bit depth of the output audio, applicable to PCM formats like `'wav'`.
808
+ * - If not provided, the input audio's bit depth is used.
809
+ */
810
+ bitDepth?: number
811
+
812
+ /**
813
+ * The bitrate of the output audio in bits per second, applicable to compressed formats like `'aac'`.
814
+ * - If not provided, a default bitrate is used based on the format.
815
+ */
816
+ bitrate?: number
817
+ }
818
+
819
+ /**
820
+ * Options for decoding the input audio file.
821
+ * - See `DecodingConfig` for details.
822
+ */
823
+ decodingOptions?: DecodingConfig
824
+ }
825
+
826
+ /**
827
+ * Result of the audio trimming operation.
828
+ */
829
+ export interface TrimAudioResult {
830
+ /**
831
+ * The URI of the trimmed audio file.
832
+ */
833
+ uri: string
834
+
835
+ /**
836
+ * The filename of the trimmed audio file.
837
+ */
838
+ filename: string
839
+
840
+ /**
841
+ * The duration of the trimmed audio in milliseconds.
842
+ */
843
+ durationMs: number
844
+
845
+ /**
846
+ * The size of the trimmed audio file in bytes.
847
+ */
848
+ size: number
849
+
850
+ /**
851
+ * The sample rate of the trimmed audio in Hertz (Hz).
852
+ */
853
+ sampleRate: number
854
+
855
+ /**
856
+ * The number of channels in the trimmed audio (e.g., 1 for mono, 2 for stereo).
857
+ */
858
+ channels: number
859
+
860
+ /**
861
+ * The bit depth of the trimmed audio, applicable to PCM formats like `'wav'`.
862
+ */
863
+ bitDepth: number
864
+
865
+ /**
866
+ * The MIME type of the trimmed audio file (e.g., `'audio/wav'`, `'audio/mpeg'`).
867
+ */
868
+ mimeType: string
869
+
870
+ /**
871
+ * Information about compression if the output format is compressed.
872
+ */
873
+ compression?: {
874
+ /**
875
+ * The format of the compression (e.g., `'aac'`, `'mp3'`, `'opus'`).
876
+ */
877
+ format: string
878
+
879
+ /**
880
+ * The bitrate of the compressed audio in bits per second.
881
+ */
882
+ bitrate: number
883
+
884
+ /**
885
+ * The size of the compressed audio file in bytes.
886
+ */
887
+ size: number
888
+ }
889
+
890
+ /**
891
+ * Information about the processing time.
892
+ */
893
+ processingInfo?: {
894
+ /**
895
+ * The time it took to process the audio in milliseconds.
896
+ */
897
+ durationMs: number
898
+ }
899
+ }