@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,226 @@
1
+ // packages/audio-studio/src/AudioAnalysis/AudioAnalysis.types.ts
2
+
3
+ import { BitDepth, ConsoleLike } from '../AudioStudio.types'
4
+
5
+ /**
6
+ * Represents the configuration for decoding audio data.
7
+ */
8
+ export interface DecodingConfig {
9
+ /** Target sample rate for decoded audio (Android and Web) */
10
+ targetSampleRate?: number
11
+ /** Target number of channels (Android and Web) */
12
+ targetChannels?: number
13
+ /** Target bit depth (Android and Web) */
14
+ targetBitDepth?: BitDepth
15
+ /** Whether to normalize audio levels (Android and Web) */
16
+ normalizeAudio?: boolean
17
+ }
18
+
19
+ /**
20
+ * Represents speech-related features extracted from audio.
21
+ */
22
+ export interface SpeechFeatures {
23
+ isActive: boolean // Whether speech is detected in this segment
24
+ speakerId?: number // Optional speaker identification
25
+ // Could add more speech-related features here like:
26
+ // confidence: number
27
+ // language?: string
28
+ // sentiment?: number
29
+ // etc.
30
+ }
31
+
32
+ /**
33
+ * Represents various audio features extracted from an audio signal.
34
+ */
35
+ export interface AudioFeatures {
36
+ energy?: number // The infinite integral of the squared signal, representing the overall energy of the audio.
37
+ mfcc?: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.
38
+ rms?: number // Root mean square value, indicating the amplitude of the audio signal.
39
+ minAmplitude?: number // Minimum amplitude value in the audio signal.
40
+ maxAmplitude?: number // Maximum amplitude value in the audio signal.
41
+ zcr?: number // Zero-crossing rate, indicating the rate at which the signal changes sign.
42
+ spectralCentroid?: number // The center of mass of the spectrum, indicating the brightness of the sound.
43
+ spectralFlatness?: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.
44
+ spectralRolloff?: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.
45
+ spectralBandwidth?: number // The width of the spectrum, indicating the range of frequencies present.
46
+ chromagram?: number[] // Chromagram, representing the 12 different pitch classes of the audio.
47
+ tempo?: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).
48
+ hnr?: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.
49
+ melSpectrogram?: number[] // Mel-scaled spectrogram representation of the audio.
50
+ spectralContrast?: number[] // Spectral contrast features representing the difference between peaks and valleys.
51
+ tonnetz?: number[] // Tonal network features representing harmonic relationships.
52
+ pitch?: number // Pitch of the audio signal, measured in Hertz (Hz).
53
+ crc32?: number // crc32 checksum of the audio signal, used to verify the integrity of the audio.
54
+ }
55
+
56
+ /**
57
+ * Options to specify which audio features to extract.
58
+ * Note: Advanced features (spectral features, chromagram, pitch, etc.) are experimental,
59
+ * especially during live recording, due to high processing requirements.
60
+ */
61
+ export interface AudioFeaturesOptions {
62
+ // Basic features - well optimized
63
+ energy?: boolean
64
+ rms?: boolean
65
+ zcr?: boolean
66
+
67
+ // Advanced features - experimental, may impact performance in live recording
68
+ mfcc?: boolean
69
+ spectralCentroid?: boolean
70
+ spectralFlatness?: boolean
71
+ spectralRolloff?: boolean
72
+ spectralBandwidth?: boolean
73
+ chromagram?: boolean
74
+ tempo?: boolean
75
+ hnr?: boolean
76
+ melSpectrogram?: boolean
77
+ spectralContrast?: boolean
78
+ tonnetz?: boolean
79
+ pitch?: boolean
80
+
81
+ // Utility
82
+ crc32?: boolean
83
+ }
84
+
85
+ /**
86
+ * Represents a single data point in the audio analysis.
87
+ */
88
+ export interface DataPoint {
89
+ id: number
90
+ amplitude: number // Peak amplitude for the segment
91
+ rms: number // Root mean square value
92
+ dB: number // dBFS (decibels relative to full scale) computed from RMS value
93
+ silent: boolean // Always computed
94
+ features?: AudioFeatures
95
+ speech?: SpeechFeatures
96
+ startTime?: number
97
+ endTime?: number
98
+ // start / end position in bytes
99
+ startPosition?: number
100
+ endPosition?: number
101
+ // number of audio samples for this point (samples size depends on bit depth)
102
+ samples?: number
103
+ }
104
+
105
+ /**
106
+ * Represents the complete data from the audio analysis.
107
+ */
108
+ export interface AudioAnalysis {
109
+ segmentDurationMs: number // Duration of each segment in milliseconds
110
+ durationMs: number // Duration of the audio in milliseconds
111
+ /**
112
+ * Bit depth used for audio analysis processing.
113
+ *
114
+ * **Important**: This represents the internal processing bit depth, which may differ
115
+ * from the recording bit depth. Audio is typically converted to 32-bit float for
116
+ * analysis to ensure precision in calculations, regardless of the original recording format.
117
+ *
118
+ * Platform behavior:
119
+ * - iOS: Always 32 (float processing)
120
+ * - Android: Always 32 (float processing)
121
+ * - Web: Always 32 (Web Audio API standard)
122
+ *
123
+ * The actual recorded file will maintain the requested bit depth (8, 16, or 32).
124
+ */
125
+ bitDepth: number
126
+ samples: number // Size of the audio in bytes
127
+ numberOfChannels: number // Number of audio channels
128
+ sampleRate: number // Sample rate of the audio
129
+ dataPoints: DataPoint[] // Array of data points from the analysis.
130
+ amplitudeRange: {
131
+ min: number
132
+ max: number
133
+ }
134
+ rmsRange: {
135
+ min: number
136
+ max: number
137
+ }
138
+ extractionTimeMs: number // Time taken to extract/process the analysis in milliseconds
139
+ // TODO: speaker changes into a broader speech analysis section
140
+ speechAnalysis?: {
141
+ speakerChanges: {
142
+ timestamp: number
143
+ speakerId: number
144
+ }[]
145
+ // Could add more speech analysis data here like:
146
+ // dominantSpeaker?: number
147
+ // totalSpeechDuration?: number
148
+ // speakerStats?: { [speakerId: number]: { duration: number, segments: number } }
149
+ }
150
+ }
151
+
152
+ /**
153
+ * Options for specifying a time range within an audio file.
154
+ */
155
+ export interface AudioRangeOptions {
156
+ /** Start time in milliseconds */
157
+ startTimeMs?: number
158
+ /** End time in milliseconds */
159
+ endTimeMs?: number
160
+ }
161
+
162
+ /**
163
+ * Options for generating a quick preview of audio waveform.
164
+ * This is optimized for UI rendering with a specified number of points.
165
+ */
166
+ export interface PreviewOptions extends AudioRangeOptions {
167
+ /** URI of the audio file to analyze */
168
+ fileUri: string
169
+ /**
170
+ * Total number of points to generate for the preview.
171
+ * @default 100
172
+ */
173
+ numberOfPoints?: number
174
+ /**
175
+ * Optional logger for debugging.
176
+ */
177
+ logger?: ConsoleLike
178
+ /**
179
+ * Optional configuration for decoding the audio file.
180
+ * Defaults to:
181
+ * - targetSampleRate: undefined (keep original)
182
+ * - targetChannels: undefined (keep original)
183
+ * - targetBitDepth: 16
184
+ * - normalizeAudio: false
185
+ */
186
+ decodingOptions?: DecodingConfig
187
+ }
188
+
189
+ /**
190
+ * Options for mel-spectrogram extraction
191
+ *
192
+ * @experimental This feature is experimental and currently only available on Android.
193
+ * The API may change in future versions.
194
+ */
195
+ export interface ExtractMelSpectrogramOptions {
196
+ fileUri?: string // Path to audio file
197
+ arrayBuffer?: ArrayBuffer // Raw audio buffer
198
+ windowSizeMs: number // Window size in ms (e.g., 25)
199
+ hopLengthMs: number // Hop length in ms (e.g., 10)
200
+ nMels: number // Number of mel filters (e.g., 60)
201
+ fMin?: number // Min frequency (default: 0)
202
+ fMax?: number // Max frequency (default: sampleRate / 2)
203
+ windowType?: 'hann' | 'hamming' // Window function (default: 'hann')
204
+ normalize?: boolean // Mean normalization (default: false)
205
+ logScale?: boolean // Log scaling of mel energies (default: true)
206
+ decodingOptions?: DecodingConfig // Audio decoding settings
207
+ /** Optional start time in ms. If neither startTimeMs nor endTimeMs is set, defaults to 0. */
208
+ startTimeMs?: number
209
+ /** Optional end time in ms. Clamped so that the range does not exceed MAX_DURATION_MS (30 s). */
210
+ endTimeMs?: number
211
+ logger?: ConsoleLike
212
+ }
213
+
214
+ /**
215
+ * Return type for mel spectrogram extraction
216
+ *
217
+ * @experimental This feature is experimental and currently only available on Android.
218
+ * The API may change in future versions.
219
+ */
220
+ export interface MelSpectrogram {
221
+ spectrogram: number[][] // 2D array [time][mel]
222
+ sampleRate: number // Audio sample rate
223
+ nMels: number // Number of mel filters
224
+ timeSteps: number // Number of time frames
225
+ durationMs: number // Audio duration in ms
226
+ }
@@ -0,0 +1,37 @@
1
+ /** Type declarations for audio features functions in the mel-spectrogram WASM module */
2
+
3
+ import type { MelSpectrogramWasmModule } from './mel-spectrogram-wasm'
4
+
5
+ export interface AudioFeaturesWasmModule extends MelSpectrogramWasmModule {
6
+ _audio_features_compute(
7
+ samples: number,
8
+ numSamples: number,
9
+ sampleRate: number,
10
+ fftLength: number,
11
+ nMfcc: number,
12
+ nMelFilters: number,
13
+ computeMfcc: number,
14
+ computeChroma: number
15
+ ): number
16
+
17
+ _audio_features_free(resultPtr: number): void
18
+
19
+ _audio_features_init(
20
+ sampleRate: number,
21
+ fftLength: number,
22
+ nMfcc: number,
23
+ nMelFilters: number,
24
+ computeMfcc: number,
25
+ computeChroma: number
26
+ ): void
27
+
28
+ _audio_features_compute_frame(
29
+ samples: number,
30
+ numSamples: number,
31
+ resultPtr: number
32
+ ): number
33
+
34
+ _audio_features_free_arrays(resultPtr: number): void
35
+
36
+ _audio_features_get_n_mfcc(): number
37
+ }
@@ -0,0 +1,200 @@
1
+ import type { AudioFeaturesWasmModule } from './audio-features-wasm'
2
+
3
+ export interface AudioFeaturesWasmResult {
4
+ spectralCentroid: number
5
+ spectralFlatness: number
6
+ spectralRolloff: number
7
+ spectralBandwidth: number
8
+ mfcc: number[]
9
+ chromagram: number[]
10
+ }
11
+
12
+ let modulePromise: Promise<AudioFeaturesWasmModule> | null = null
13
+
14
+ function getModule(): Promise<AudioFeaturesWasmModule> {
15
+ if (!modulePromise) {
16
+ modulePromise = (async () => {
17
+ // Same WASM module as mel spectrogram (now includes audio features)
18
+ // @ts-expect-error -- prebuilt Emscripten JS glue has no .d.ts
19
+ const mod = await import('../../prebuilt/wasm/mel-spectrogram.js')
20
+ const factory = mod.default ?? mod
21
+ return factory() as Promise<AudioFeaturesWasmModule>
22
+ })().catch((err) => {
23
+ modulePromise = null
24
+ throw err
25
+ })
26
+ }
27
+ return modulePromise
28
+ }
29
+
30
+ // --- Struct layout for CAudioFeaturesResult (wasm32) ---
31
+ // Offset 0: float spectralCentroid (4 bytes)
32
+ // Offset 4: float spectralFlatness (4 bytes)
33
+ // Offset 8: float spectralRolloff (4 bytes)
34
+ // Offset 12: float spectralBandwidth (4 bytes)
35
+ // Offset 16: float* mfcc (4 bytes pointer)
36
+ // Offset 20: int mfccCount (4 bytes)
37
+ // Offset 24: float* chromagram (4 bytes pointer)
38
+ // Offset 28: int chromagramCount (4 bytes)
39
+ const STRUCT_SIZE = 32
40
+
41
+ function readResult(
42
+ Module: AudioFeaturesWasmModule,
43
+ ptr: number
44
+ ): AudioFeaturesWasmResult {
45
+ const spectralCentroid = Module.getValue(ptr, 'float')
46
+ const spectralFlatness = Module.getValue(ptr + 4, 'float')
47
+ const spectralRolloff = Module.getValue(ptr + 8, 'float')
48
+ const spectralBandwidth = Module.getValue(ptr + 12, 'float')
49
+
50
+ const mfccPtr = Module.getValue(ptr + 16, 'i32')
51
+ const mfccCount = Module.getValue(ptr + 20, 'i32')
52
+ const chromaPtr = Module.getValue(ptr + 24, 'i32')
53
+ const chromaCount = Module.getValue(ptr + 28, 'i32')
54
+
55
+ const mfcc: number[] = []
56
+ if (mfccPtr && mfccCount > 0) {
57
+ const offset = mfccPtr >> 2
58
+ for (let i = 0; i < mfccCount; i++) {
59
+ mfcc.push(Module.HEAPF32[offset + i])
60
+ }
61
+ }
62
+
63
+ const chromagram: number[] = []
64
+ if (chromaPtr && chromaCount > 0) {
65
+ const offset = chromaPtr >> 2
66
+ for (let i = 0; i < chromaCount; i++) {
67
+ chromagram.push(Module.HEAPF32[offset + i])
68
+ }
69
+ }
70
+
71
+ return {
72
+ spectralCentroid,
73
+ spectralFlatness,
74
+ spectralRolloff,
75
+ spectralBandwidth,
76
+ mfcc,
77
+ chromagram,
78
+ }
79
+ }
80
+
81
+ // --- Streaming (per-frame) API ---
82
+
83
+ let streamingModule: AudioFeaturesWasmModule | null = null
84
+ let streamingFramePtr = 0
85
+ let streamingFrameCapacity = 0
86
+ let streamingResultPtr = 0
87
+
88
+ /**
89
+ * Initialise the WASM streaming audio features processor.
90
+ * Call once before computeAudioFeaturesFrameWasm().
91
+ */
92
+ export async function initAudioFeaturesWasm(
93
+ sampleRate: number,
94
+ fftLength = 1024,
95
+ nMfcc = 13,
96
+ nMelFilters = 26,
97
+ computeMfcc = true,
98
+ computeChroma = true
99
+ ): Promise<void> {
100
+ const Module = await getModule()
101
+ streamingModule = Module
102
+
103
+ Module._audio_features_init(
104
+ sampleRate,
105
+ fftLength,
106
+ nMfcc,
107
+ nMelFilters,
108
+ computeMfcc ? 1 : 0,
109
+ computeChroma ? 1 : 0
110
+ )
111
+
112
+ // Pre-allocate result struct on WASM heap
113
+ if (streamingResultPtr) Module._free(streamingResultPtr)
114
+ streamingResultPtr = Module._malloc(STRUCT_SIZE)
115
+ // Zero-initialize to prevent freeing garbage pointers on first use
116
+ Module.HEAPU8.fill(0, streamingResultPtr, streamingResultPtr + STRUCT_SIZE)
117
+
118
+ // Frame input buffer allocated on demand
119
+ streamingFrameCapacity = 0
120
+ streamingFramePtr = 0
121
+ }
122
+
123
+ /**
124
+ * Compute audio features for a single frame via WASM C++.
125
+ * Returns null if not initialised or on error.
126
+ */
127
+ export function computeAudioFeaturesFrameWasm(
128
+ samples: Float32Array
129
+ ): AudioFeaturesWasmResult | null {
130
+ if (!streamingModule || !streamingResultPtr) return null
131
+ const Module = streamingModule
132
+
133
+ // (Re-)allocate frame input buffer if needed
134
+ if (samples.length > streamingFrameCapacity) {
135
+ if (streamingFramePtr) Module._free(streamingFramePtr)
136
+ streamingFramePtr = Module._malloc(samples.length * 4)
137
+ streamingFrameCapacity = samples.length
138
+ }
139
+
140
+ // Copy samples to WASM heap
141
+ Module.HEAPF32.set(samples, streamingFramePtr >> 2)
142
+
143
+ const ok = Module._audio_features_compute_frame(
144
+ streamingFramePtr,
145
+ samples.length,
146
+ streamingResultPtr
147
+ )
148
+ if (!ok) return null
149
+
150
+ const result = readResult(Module, streamingResultPtr)
151
+
152
+ // Free internal arrays (mfcc, chromagram) allocated by C
153
+ Module._audio_features_free_arrays(streamingResultPtr)
154
+
155
+ return result
156
+ }
157
+
158
+ // --- Batch API ---
159
+
160
+ /**
161
+ * Compute audio features for a buffer of samples via WASM C++.
162
+ * Lazy-loads the WASM module on first call.
163
+ */
164
+ export async function computeAudioFeaturesWasm(
165
+ audioData: Float32Array,
166
+ sampleRate: number,
167
+ fftLength = 1024,
168
+ nMfcc = 13,
169
+ nMelFilters = 26,
170
+ computeMfcc = true,
171
+ computeChroma = true
172
+ ): Promise<AudioFeaturesWasmResult> {
173
+ const Module = await getModule()
174
+
175
+ const numSamples = audioData.length
176
+ const inputPtr = Module._malloc(numSamples * 4)
177
+ Module.HEAPF32.set(audioData, inputPtr >> 2)
178
+
179
+ const resultPtr = Module._audio_features_compute(
180
+ inputPtr,
181
+ numSamples,
182
+ sampleRate,
183
+ fftLength,
184
+ nMfcc,
185
+ nMelFilters,
186
+ computeMfcc ? 1 : 0,
187
+ computeChroma ? 1 : 0
188
+ )
189
+
190
+ Module._free(inputPtr)
191
+
192
+ if (resultPtr === 0) {
193
+ throw new Error('audio_features_compute returned null')
194
+ }
195
+
196
+ const result = readResult(Module, resultPtr)
197
+ Module._audio_features_free(resultPtr)
198
+
199
+ return result
200
+ }