@siteed/expo-audio-studio 2.7.0 → 2.8.1

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 (241) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/app.plugin.cjs +15 -2
  3. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js +4 -0
  4. package/build/cjs/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  5. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js +205 -0
  6. package/build/cjs/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  7. package/build/cjs/AudioAnalysis/extractAudioData.js +12 -0
  8. package/build/cjs/AudioAnalysis/extractAudioData.js.map +1 -0
  9. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js +89 -0
  10. package/build/cjs/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
  11. package/build/cjs/AudioAnalysis/extractPreview.js +29 -0
  12. package/build/cjs/AudioAnalysis/extractPreview.js.map +1 -0
  13. package/build/cjs/AudioAnalysis/extractWaveform.js +18 -0
  14. package/build/cjs/AudioAnalysis/extractWaveform.js.map +1 -0
  15. package/build/cjs/AudioDeviceManager.js +500 -0
  16. package/build/cjs/AudioDeviceManager.js.map +1 -0
  17. package/build/cjs/AudioRecorder.provider.js +68 -0
  18. package/build/cjs/AudioRecorder.provider.js.map +1 -0
  19. package/build/cjs/ExpoAudioStream.native.js +8 -0
  20. package/build/cjs/ExpoAudioStream.native.js.map +1 -0
  21. package/build/cjs/ExpoAudioStream.types.js +11 -0
  22. package/build/cjs/ExpoAudioStream.types.js.map +1 -0
  23. package/build/cjs/ExpoAudioStream.web.js +705 -0
  24. package/build/cjs/ExpoAudioStream.web.js.map +1 -0
  25. package/build/cjs/ExpoAudioStreamModule.js +718 -0
  26. package/build/cjs/ExpoAudioStreamModule.js.map +1 -0
  27. package/build/cjs/WebRecorder.web.js +756 -0
  28. package/build/cjs/WebRecorder.web.js.map +1 -0
  29. package/build/cjs/constants.js +17 -0
  30. package/build/cjs/constants.js.map +1 -0
  31. package/build/cjs/events.js +30 -0
  32. package/build/cjs/events.js.map +1 -0
  33. package/build/cjs/hooks/useAudioDevices.js +155 -0
  34. package/build/cjs/hooks/useAudioDevices.js.map +1 -0
  35. package/build/cjs/index.js +50 -0
  36. package/build/cjs/index.js.map +1 -0
  37. package/build/cjs/trimAudio.js +75 -0
  38. package/build/cjs/trimAudio.js.map +1 -0
  39. package/build/cjs/useAudioRecorder.js +453 -0
  40. package/build/cjs/useAudioRecorder.js.map +1 -0
  41. package/build/cjs/utils/BlobFix.js +502 -0
  42. package/build/cjs/utils/BlobFix.js.map +1 -0
  43. package/build/cjs/utils/audioProcessing.js +137 -0
  44. package/build/cjs/utils/audioProcessing.js.map +1 -0
  45. package/build/cjs/utils/concatenateBuffers.js +25 -0
  46. package/build/cjs/utils/concatenateBuffers.js.map +1 -0
  47. package/build/cjs/utils/convertPCMToFloat32.js +124 -0
  48. package/build/cjs/utils/convertPCMToFloat32.js.map +1 -0
  49. package/build/cjs/utils/crc32.js +52 -0
  50. package/build/cjs/utils/crc32.js.map +1 -0
  51. package/build/cjs/utils/encodingToBitDepth.js +17 -0
  52. package/build/cjs/utils/encodingToBitDepth.js.map +1 -0
  53. package/build/cjs/utils/getWavFileInfo.js +96 -0
  54. package/build/cjs/utils/getWavFileInfo.js.map +1 -0
  55. package/build/cjs/utils/writeWavHeader.js +88 -0
  56. package/build/cjs/utils/writeWavHeader.js.map +1 -0
  57. package/build/cjs/workers/InlineFeaturesExtractor.web.js +853 -0
  58. package/build/cjs/workers/InlineFeaturesExtractor.web.js.map +1 -0
  59. package/build/cjs/workers/inlineAudioWebWorker.web.js +184 -0
  60. package/build/cjs/workers/inlineAudioWebWorker.web.js.map +1 -0
  61. package/build/esm/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  62. package/build/esm/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  63. package/build/esm/AudioAnalysis/extractAudioData.js.map +1 -0
  64. package/build/esm/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
  65. package/build/esm/AudioAnalysis/extractPreview.js.map +1 -0
  66. package/build/esm/AudioAnalysis/extractWaveform.js.map +1 -0
  67. package/build/esm/AudioDeviceManager.js.map +1 -0
  68. package/build/esm/AudioRecorder.provider.js.map +1 -0
  69. package/build/esm/ExpoAudioStream.native.js.map +1 -0
  70. package/build/esm/ExpoAudioStream.types.js.map +1 -0
  71. package/build/esm/ExpoAudioStream.web.js.map +1 -0
  72. package/build/esm/ExpoAudioStreamModule.js.map +1 -0
  73. package/build/esm/WebRecorder.web.js.map +1 -0
  74. package/build/esm/constants.js.map +1 -0
  75. package/build/esm/events.js.map +1 -0
  76. package/build/esm/hooks/useAudioDevices.js.map +1 -0
  77. package/build/esm/index.js.map +1 -0
  78. package/build/esm/trimAudio.js.map +1 -0
  79. package/build/esm/useAudioRecorder.js.map +1 -0
  80. package/build/esm/utils/BlobFix.js.map +1 -0
  81. package/build/esm/utils/audioProcessing.js.map +1 -0
  82. package/build/esm/utils/concatenateBuffers.js.map +1 -0
  83. package/build/esm/utils/convertPCMToFloat32.js.map +1 -0
  84. package/build/esm/utils/crc32.js.map +1 -0
  85. package/build/esm/utils/encodingToBitDepth.js.map +1 -0
  86. package/build/esm/utils/getWavFileInfo.js.map +1 -0
  87. package/build/esm/utils/writeWavHeader.js.map +1 -0
  88. package/build/esm/workers/InlineFeaturesExtractor.web.js.map +1 -0
  89. package/build/esm/workers/inlineAudioWebWorker.web.js.map +1 -0
  90. package/build/types/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
  91. package/build/types/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
  92. package/build/types/AudioAnalysis/extractAudioData.d.ts.map +1 -0
  93. package/build/types/AudioAnalysis/extractMelSpectrogram.d.ts.map +1 -0
  94. package/build/types/AudioAnalysis/extractPreview.d.ts.map +1 -0
  95. package/build/types/AudioAnalysis/extractWaveform.d.ts.map +1 -0
  96. package/build/types/AudioDeviceManager.d.ts.map +1 -0
  97. package/build/types/AudioRecorder.provider.d.ts.map +1 -0
  98. package/build/types/ExpoAudioStream.native.d.ts.map +1 -0
  99. package/build/types/ExpoAudioStream.types.d.ts.map +1 -0
  100. package/build/types/ExpoAudioStream.web.d.ts.map +1 -0
  101. package/build/types/ExpoAudioStreamModule.d.ts.map +1 -0
  102. package/build/types/WebRecorder.web.d.ts.map +1 -0
  103. package/build/types/constants.d.ts.map +1 -0
  104. package/build/types/events.d.ts.map +1 -0
  105. package/build/types/hooks/useAudioDevices.d.ts.map +1 -0
  106. package/build/types/index.d.ts.map +1 -0
  107. package/build/types/trimAudio.d.ts.map +1 -0
  108. package/build/types/useAudioRecorder.d.ts.map +1 -0
  109. package/build/types/utils/BlobFix.d.ts.map +1 -0
  110. package/build/types/utils/audioProcessing.d.ts.map +1 -0
  111. package/build/types/utils/concatenateBuffers.d.ts.map +1 -0
  112. package/build/types/utils/convertPCMToFloat32.d.ts.map +1 -0
  113. package/build/types/utils/crc32.d.ts.map +1 -0
  114. package/build/types/utils/encodingToBitDepth.d.ts.map +1 -0
  115. package/build/types/utils/getWavFileInfo.d.ts.map +1 -0
  116. package/build/types/utils/writeWavHeader.d.ts.map +1 -0
  117. package/build/types/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
  118. package/build/types/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
  119. package/ios/AudioNotificationManager.swift +42 -19
  120. package/ios/AudioProcessingHelpers.swift +5 -5
  121. package/ios/AudioProcessor.swift +44 -218
  122. package/ios/AudioStreamManager.swift +121 -61
  123. package/ios/DataPoint.swift +5 -5
  124. package/ios/ExpoAudioStreamModule.swift +2 -1
  125. package/package.json +25 -7
  126. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  127. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  128. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  129. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  130. package/build/AudioAnalysis/extractAudioData.d.ts.map +0 -1
  131. package/build/AudioAnalysis/extractAudioData.js.map +0 -1
  132. package/build/AudioAnalysis/extractMelSpectrogram.d.ts.map +0 -1
  133. package/build/AudioAnalysis/extractMelSpectrogram.js.map +0 -1
  134. package/build/AudioAnalysis/extractPreview.d.ts.map +0 -1
  135. package/build/AudioAnalysis/extractPreview.js.map +0 -1
  136. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  137. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  138. package/build/AudioDeviceManager.d.ts.map +0 -1
  139. package/build/AudioDeviceManager.js.map +0 -1
  140. package/build/AudioRecorder.provider.d.ts.map +0 -1
  141. package/build/AudioRecorder.provider.js.map +0 -1
  142. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  143. package/build/ExpoAudioStream.native.js.map +0 -1
  144. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  145. package/build/ExpoAudioStream.types.js.map +0 -1
  146. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  147. package/build/ExpoAudioStream.web.js.map +0 -1
  148. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  149. package/build/ExpoAudioStreamModule.js.map +0 -1
  150. package/build/WebRecorder.web.d.ts.map +0 -1
  151. package/build/WebRecorder.web.js.map +0 -1
  152. package/build/constants.d.ts.map +0 -1
  153. package/build/constants.js.map +0 -1
  154. package/build/events.d.ts.map +0 -1
  155. package/build/events.js.map +0 -1
  156. package/build/hooks/useAudioDevices.d.ts.map +0 -1
  157. package/build/hooks/useAudioDevices.js.map +0 -1
  158. package/build/index.d.ts.map +0 -1
  159. package/build/index.js.map +0 -1
  160. package/build/trimAudio.d.ts.map +0 -1
  161. package/build/trimAudio.js.map +0 -1
  162. package/build/useAudioRecorder.d.ts.map +0 -1
  163. package/build/useAudioRecorder.js.map +0 -1
  164. package/build/utils/BlobFix.d.ts.map +0 -1
  165. package/build/utils/BlobFix.js.map +0 -1
  166. package/build/utils/audioProcessing.d.ts.map +0 -1
  167. package/build/utils/audioProcessing.js.map +0 -1
  168. package/build/utils/concatenateBuffers.d.ts.map +0 -1
  169. package/build/utils/concatenateBuffers.js.map +0 -1
  170. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  171. package/build/utils/convertPCMToFloat32.js.map +0 -1
  172. package/build/utils/crc32.d.ts.map +0 -1
  173. package/build/utils/crc32.js.map +0 -1
  174. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  175. package/build/utils/encodingToBitDepth.js.map +0 -1
  176. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  177. package/build/utils/getWavFileInfo.js.map +0 -1
  178. package/build/utils/writeWavHeader.d.ts.map +0 -1
  179. package/build/utils/writeWavHeader.js.map +0 -1
  180. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  181. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  182. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  183. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  184. /package/build/{AudioAnalysis → esm/AudioAnalysis}/AudioAnalysis.types.js +0 -0
  185. /package/build/{AudioAnalysis → esm/AudioAnalysis}/extractAudioAnalysis.js +0 -0
  186. /package/build/{AudioAnalysis → esm/AudioAnalysis}/extractAudioData.js +0 -0
  187. /package/build/{AudioAnalysis → esm/AudioAnalysis}/extractMelSpectrogram.js +0 -0
  188. /package/build/{AudioAnalysis → esm/AudioAnalysis}/extractPreview.js +0 -0
  189. /package/build/{AudioAnalysis → esm/AudioAnalysis}/extractWaveform.js +0 -0
  190. /package/build/{AudioDeviceManager.js → esm/AudioDeviceManager.js} +0 -0
  191. /package/build/{AudioRecorder.provider.js → esm/AudioRecorder.provider.js} +0 -0
  192. /package/build/{ExpoAudioStream.native.js → esm/ExpoAudioStream.native.js} +0 -0
  193. /package/build/{ExpoAudioStream.types.js → esm/ExpoAudioStream.types.js} +0 -0
  194. /package/build/{ExpoAudioStream.web.js → esm/ExpoAudioStream.web.js} +0 -0
  195. /package/build/{ExpoAudioStreamModule.js → esm/ExpoAudioStreamModule.js} +0 -0
  196. /package/build/{WebRecorder.web.js → esm/WebRecorder.web.js} +0 -0
  197. /package/build/{constants.js → esm/constants.js} +0 -0
  198. /package/build/{events.js → esm/events.js} +0 -0
  199. /package/build/{hooks → esm/hooks}/useAudioDevices.js +0 -0
  200. /package/build/{index.js → esm/index.js} +0 -0
  201. /package/build/{trimAudio.js → esm/trimAudio.js} +0 -0
  202. /package/build/{useAudioRecorder.js → esm/useAudioRecorder.js} +0 -0
  203. /package/build/{utils → esm/utils}/BlobFix.js +0 -0
  204. /package/build/{utils → esm/utils}/audioProcessing.js +0 -0
  205. /package/build/{utils → esm/utils}/concatenateBuffers.js +0 -0
  206. /package/build/{utils → esm/utils}/convertPCMToFloat32.js +0 -0
  207. /package/build/{utils → esm/utils}/crc32.js +0 -0
  208. /package/build/{utils → esm/utils}/encodingToBitDepth.js +0 -0
  209. /package/build/{utils → esm/utils}/getWavFileInfo.js +0 -0
  210. /package/build/{utils → esm/utils}/writeWavHeader.js +0 -0
  211. /package/build/{workers → esm/workers}/InlineFeaturesExtractor.web.js +0 -0
  212. /package/build/{workers → esm/workers}/inlineAudioWebWorker.web.js +0 -0
  213. /package/build/{AudioAnalysis → types/AudioAnalysis}/AudioAnalysis.types.d.ts +0 -0
  214. /package/build/{AudioAnalysis → types/AudioAnalysis}/extractAudioAnalysis.d.ts +0 -0
  215. /package/build/{AudioAnalysis → types/AudioAnalysis}/extractAudioData.d.ts +0 -0
  216. /package/build/{AudioAnalysis → types/AudioAnalysis}/extractMelSpectrogram.d.ts +0 -0
  217. /package/build/{AudioAnalysis → types/AudioAnalysis}/extractPreview.d.ts +0 -0
  218. /package/build/{AudioAnalysis → types/AudioAnalysis}/extractWaveform.d.ts +0 -0
  219. /package/build/{AudioDeviceManager.d.ts → types/AudioDeviceManager.d.ts} +0 -0
  220. /package/build/{AudioRecorder.provider.d.ts → types/AudioRecorder.provider.d.ts} +0 -0
  221. /package/build/{ExpoAudioStream.native.d.ts → types/ExpoAudioStream.native.d.ts} +0 -0
  222. /package/build/{ExpoAudioStream.types.d.ts → types/ExpoAudioStream.types.d.ts} +0 -0
  223. /package/build/{ExpoAudioStream.web.d.ts → types/ExpoAudioStream.web.d.ts} +0 -0
  224. /package/build/{ExpoAudioStreamModule.d.ts → types/ExpoAudioStreamModule.d.ts} +0 -0
  225. /package/build/{WebRecorder.web.d.ts → types/WebRecorder.web.d.ts} +0 -0
  226. /package/build/{constants.d.ts → types/constants.d.ts} +0 -0
  227. /package/build/{events.d.ts → types/events.d.ts} +0 -0
  228. /package/build/{hooks → types/hooks}/useAudioDevices.d.ts +0 -0
  229. /package/build/{index.d.ts → types/index.d.ts} +0 -0
  230. /package/build/{trimAudio.d.ts → types/trimAudio.d.ts} +0 -0
  231. /package/build/{useAudioRecorder.d.ts → types/useAudioRecorder.d.ts} +0 -0
  232. /package/build/{utils → types/utils}/BlobFix.d.ts +0 -0
  233. /package/build/{utils → types/utils}/audioProcessing.d.ts +0 -0
  234. /package/build/{utils → types/utils}/concatenateBuffers.d.ts +0 -0
  235. /package/build/{utils → types/utils}/convertPCMToFloat32.d.ts +0 -0
  236. /package/build/{utils → types/utils}/crc32.d.ts +0 -0
  237. /package/build/{utils → types/utils}/encodingToBitDepth.d.ts +0 -0
  238. /package/build/{utils → types/utils}/getWavFileInfo.d.ts +0 -0
  239. /package/build/{utils → types/utils}/writeWavHeader.d.ts +0 -0
  240. /package/build/{workers → types/workers}/InlineFeaturesExtractor.web.d.ts +0 -0
  241. /package/build/{workers → types/workers}/inlineAudioWebWorker.web.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -8,6 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [Unreleased]
9
9
 
10
10
 
11
+ ## [2.8.1] - 2025-05-06
12
+ ### Changed
13
+ - feat(expo-audio-studio): implement dual module format (ESM/CommonJS) to resolve module resolution issues (#235) ([58c5a94](https://github.com/deeeed/expo-audio-stream/commit/58c5a94ecf2fdcefa554b2f8664743730001e6d8))
14
+ - chore(expo-audio-studio): release @siteed/expo-audio-studio@2.8.0 ([a879e93](https://github.com/deeeed/expo-audio-stream/commit/a879e93bb7b5d27ab5ee764c903e890550c8dda5))
15
+ ## [2.8.0] - 2025-05-04
16
+ ### Changed
17
+ - feat(playground): Version 1.0.1 with Audio Enhancements, App Updates, and Navigation Refactor (#229) ([868fca0](https://github.com/deeeed/expo-audio-stream/commit/868fca026119aea116a22670c2b6fe364b6df06c))
18
+ - chore: enhance publish script to include git push after documentation updates ([1b0b0db](https://github.com/deeeed/expo-audio-stream/commit/1b0b0db6cf40a6397e6d7438cb7543c93e67b143))
19
+ - chore(expo-audio-studio): release @siteed/expo-audio-studio@2.7.0 ([fe19a2f](https://github.com/deeeed/expo-audio-stream/commit/fe19a2fa1af6033cfa025691f25a0e9bcd64b37c))
11
20
  ## [2.7.0] - 2025-05-04
12
21
  ### Changed
13
22
  - fix: Enhance iOS Background Audio Recording and Audio Format Conversion (#228) ([c17169b](https://github.com/deeeed/expo-audio-stream/commit/c17169bf9275706abf287712acc30df2f1814ed7))
@@ -217,7 +226,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
217
226
  - Feature: Audio features extraction during recording.
218
227
  - Feature: Consistent WAV PCM recording format across all platforms.
219
228
 
220
- [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.7.0...HEAD
229
+ [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.8.1...HEAD
230
+ [2.8.1]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.8.0...@siteed/expo-audio-studio@2.8.1
231
+ [2.8.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.7.0...@siteed/expo-audio-studio@2.8.0
221
232
  [2.7.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.6.3...@siteed/expo-audio-studio@2.7.0
222
233
  [2.6.3]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.6.2...@siteed/expo-audio-studio@2.6.3
223
234
  [2.6.2]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.6.1...@siteed/expo-audio-studio@2.6.2
package/app.plugin.cjs CHANGED
@@ -1,2 +1,15 @@
1
- // Simply export the plugin - this is a CommonJS file (.cjs)
2
- module.exports = require('./plugin/build/index.cjs')
1
+ // This is a CommonJS file (.cjs) which loads the plugin configuration
2
+ try {
3
+ // Export the plugin from its CommonJS build
4
+ module.exports = require('./plugin/build/index.cjs')
5
+ } catch (error) {
6
+ console.error(
7
+ '[@siteed/expo-audio-studio] Plugin loading error:',
8
+ error.message
9
+ )
10
+ // Fallback plugin that does nothing but logs error
11
+ module.exports = (config) => {
12
+ console.warn('[@siteed/expo-audio-studio] Using fallback plugin due to loading error. Run `yarn build` in the package directory.')
13
+ return config
14
+ }
15
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ // packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ //# sourceMappingURL=AudioAnalysis.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":";AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\nimport { BitDepth, ConsoleLike } from '../ExpoAudioStream.types'\n\n/**\n * Represents the configuration for decoding audio data.\n */\nexport interface DecodingConfig {\n /** Target sample rate for decoded audio (Android and Web) */\n targetSampleRate?: number\n /** Target number of channels (Android and Web) */\n targetChannels?: number\n /** Target bit depth (Android and Web) */\n targetBitDepth?: BitDepth\n /** Whether to normalize audio levels (Android and Web) */\n normalizeAudio?: boolean\n}\n\n/**\n * Represents speech-related features extracted from audio.\n */\nexport interface SpeechFeatures {\n isActive: boolean // Whether speech is detected in this segment\n speakerId?: number // Optional speaker identification\n // Could add more speech-related features here like:\n // confidence: number\n // language?: string\n // sentiment?: number\n // etc.\n}\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy?: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc?: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms?: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude?: number // Minimum amplitude value in the audio signal.\n maxAmplitude?: number // Maximum amplitude value in the audio signal.\n zcr?: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid?: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness?: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff?: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth?: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram?: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo?: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr?: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n melSpectrogram?: number[] // Mel-scaled spectrogram representation of the audio.\n spectralContrast?: number[] // Spectral contrast features representing the difference between peaks and valleys.\n tonnetz?: number[] // Tonal network features representing harmonic relationships.\n pitch?: number // Pitch of the audio signal, measured in Hertz (Hz).\n crc32?: number // crc32 checksum of the audio signal, used to verify the integrity of the audio.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n melSpectrogram?: boolean\n spectralContrast?: boolean\n tonnetz?: boolean\n pitch?: boolean\n crc32?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number // Peak amplitude for the segment\n rms: number // Root mean square value\n dB: number // dBFS (decibels relative to full scale) computed from RMS value\n silent: boolean // Always computed\n features?: AudioFeatures\n speech?: SpeechFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n}\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n segmentDurationMs: number // Duration of each segment in milliseconds\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeRange: {\n min: number\n max: number\n }\n rmsRange: {\n min: number\n max: number\n }\n // TODO: speaker changes into a broader speech analysis section\n speechAnalysis?: {\n speakerChanges: {\n timestamp: number\n speakerId: number\n }[]\n // Could add more speech analysis data here like:\n // dominantSpeaker?: number\n // totalSpeechDuration?: number\n // speakerStats?: { [speakerId: number]: { duration: number, segments: number } }\n }\n}\n\n/**\n * Options for specifying a time range within an audio file.\n */\nexport interface AudioRangeOptions {\n /** Start time in milliseconds */\n startTimeMs?: number\n /** End time in milliseconds */\n endTimeMs?: number\n}\n\n/**\n * Options for generating a quick preview of audio waveform.\n * This is optimized for UI rendering with a specified number of points.\n */\nexport interface PreviewOptions extends AudioRangeOptions {\n /** URI of the audio file to analyze */\n fileUri: string\n /**\n * Total number of points to generate for the preview.\n * @default 100\n */\n numberOfPoints?: number\n /**\n * Optional logger for debugging.\n */\n logger?: ConsoleLike\n /**\n * Optional configuration for decoding the audio file.\n * Defaults to:\n * - targetSampleRate: undefined (keep original)\n * - targetChannels: undefined (keep original)\n * - targetBitDepth: 16\n * - normalizeAudio: false\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Options for mel-spectrogram extraction\n *\n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface ExtractMelSpectrogramOptions {\n fileUri?: string // Path to audio file\n arrayBuffer?: ArrayBuffer // Raw audio buffer\n windowSizeMs: number // Window size in ms (e.g., 25)\n hopLengthMs: number // Hop length in ms (e.g., 10)\n nMels: number // Number of mel filters (e.g., 60)\n fMin?: number // Min frequency (default: 0)\n fMax?: number // Max frequency (default: sampleRate / 2)\n windowType?: 'hann' | 'hamming' // Window function (default: 'hann')\n normalize?: boolean // Mean normalization (default: false)\n logScale?: boolean // Log scaling of mel energies (default: true)\n decodingOptions?: DecodingConfig // Audio decoding settings\n startTimeMs?: number // Optional start time\n endTimeMs?: number // Optional end time\n logger?: ConsoleLike\n}\n\n/**\n * Return type for mel spectrogram extraction\n *\n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface MelSpectrogram {\n spectrogram: number[][] // 2D array [time][mel]\n sampleRate: number // Audio sample rate\n nMels: number // Number of mel filters\n timeSteps: number // Number of time frames\n durationMs: number // Audio duration in ms\n}\n"]}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractRawWavAnalysis = exports.extractAudioAnalysis = void 0;
7
+ const ExpoAudioStreamModule_1 = __importDefault(require("../ExpoAudioStreamModule"));
8
+ const constants_1 = require("../constants");
9
+ const audioProcessing_1 = require("../utils/audioProcessing");
10
+ const convertPCMToFloat32_1 = require("../utils/convertPCMToFloat32");
11
+ const crc32_1 = __importDefault(require("../utils/crc32"));
12
+ const getWavFileInfo_1 = require("../utils/getWavFileInfo");
13
+ const InlineFeaturesExtractor_web_1 = require("../workers/InlineFeaturesExtractor.web");
14
+ function calculateCRC32ForDataPoint(data) {
15
+ // Convert float array to byte array for CRC32
16
+ const byteArray = new Uint8Array(data.length * 4);
17
+ const dataView = new DataView(byteArray.buffer);
18
+ for (let i = 0; i < data.length; i++) {
19
+ dataView.setFloat32(i * 4, data[i], true);
20
+ }
21
+ return crc32_1.default.buf(byteArray);
22
+ }
23
+ /**
24
+ * Extracts detailed audio analysis from the specified audio file or buffer.
25
+ * Supports either time-based or byte-based ranges for flexibility in analysis.
26
+ *
27
+ * @param props - The options for extraction, including file URI, ranges, and decoding settings.
28
+ * @returns A promise that resolves to the audio analysis data.
29
+ * @throws {Error} If both time and byte ranges are provided or if required parameters are missing.
30
+ */
31
+ async function extractAudioAnalysis(props) {
32
+ const { fileUri, arrayBuffer, decodingOptions, logger, segmentDurationMs = 100, features, } = props;
33
+ if (constants_1.isWeb) {
34
+ try {
35
+ // Create AudioContext here
36
+ const audioContext = new (window.AudioContext ||
37
+ window.webkitAudioContext)({
38
+ sampleRate: decodingOptions?.targetSampleRate ?? 16000,
39
+ });
40
+ try {
41
+ const processedBuffer = await (0, audioProcessing_1.processAudioBuffer)({
42
+ arrayBuffer,
43
+ fileUri,
44
+ targetSampleRate: decodingOptions?.targetSampleRate ?? 16000,
45
+ targetChannels: decodingOptions?.targetChannels ?? 1,
46
+ normalizeAudio: decodingOptions?.normalizeAudio ?? false,
47
+ startTimeMs: 'startTimeMs' in props ? props.startTimeMs : undefined,
48
+ endTimeMs: 'endTimeMs' in props ? props.endTimeMs : undefined,
49
+ position: 'position' in props ? props.position : undefined,
50
+ length: 'length' in props ? props.length : undefined,
51
+ audioContext, // Pass the context we created
52
+ logger,
53
+ });
54
+ const channelData = processedBuffer.buffer.getChannelData(0);
55
+ // Create and initialize the worker
56
+ const blob = new Blob([InlineFeaturesExtractor_web_1.InlineFeaturesExtractor], {
57
+ type: 'application/javascript',
58
+ });
59
+ const workerUrl = URL.createObjectURL(blob);
60
+ const worker = new Worker(workerUrl);
61
+ return new Promise((resolve, reject) => {
62
+ worker.onmessage = (event) => {
63
+ if (event.data.error) {
64
+ reject(new Error(event.data.error));
65
+ return;
66
+ }
67
+ const result = event.data.result;
68
+ // Calculate CRC32 after worker completes if requested
69
+ if (features?.crc32) {
70
+ const samplesPerSegment = Math.floor((processedBuffer.sampleRate *
71
+ segmentDurationMs) /
72
+ 1000);
73
+ result.dataPoints = result.dataPoints.map((point, index) => {
74
+ const startSample = index * samplesPerSegment;
75
+ const segmentData = channelData.slice(startSample, startSample + samplesPerSegment);
76
+ return {
77
+ ...point,
78
+ features: {
79
+ ...point.features,
80
+ crc32: calculateCRC32ForDataPoint(segmentData),
81
+ },
82
+ };
83
+ });
84
+ }
85
+ URL.revokeObjectURL(workerUrl);
86
+ worker.terminate();
87
+ resolve(result);
88
+ };
89
+ worker.onerror = (error) => {
90
+ URL.revokeObjectURL(workerUrl);
91
+ worker.terminate();
92
+ reject(error);
93
+ };
94
+ worker.postMessage({
95
+ channelData,
96
+ sampleRate: processedBuffer.sampleRate,
97
+ segmentDurationMs,
98
+ bitDepth: decodingOptions?.targetBitDepth ?? 32,
99
+ numberOfChannels: processedBuffer.channels,
100
+ fullAudioDurationMs: processedBuffer.durationMs,
101
+ // enableLogging: !!logger,
102
+ features,
103
+ });
104
+ });
105
+ }
106
+ finally {
107
+ await audioContext.close();
108
+ }
109
+ }
110
+ catch (error) {
111
+ logger?.error('Failed to process audio:', error);
112
+ throw error;
113
+ }
114
+ }
115
+ else {
116
+ return await ExpoAudioStreamModule_1.default.extractAudioAnalysis(props);
117
+ }
118
+ }
119
+ exports.extractAudioAnalysis = extractAudioAnalysis;
120
+ /**
121
+ * Analyzes WAV files without decoding, preserving original PCM values.
122
+ * Use this function when you need to ensure the analysis matches other software by avoiding any transformations.
123
+ *
124
+ * @param props - The options for WAV analysis, including file URI and range.
125
+ * @returns A promise that resolves to the audio analysis data.
126
+ */
127
+ const extractRawWavAnalysis = async ({ fileUri, segmentDurationMs = 100, // Default to 100ms
128
+ arrayBuffer, bitDepth, durationMs, sampleRate, numberOfChannels, features, logger, position = 0, length, }) => {
129
+ if (constants_1.isWeb) {
130
+ if (!arrayBuffer && !fileUri) {
131
+ throw new Error('Either arrayBuffer or fileUri must be provided');
132
+ }
133
+ if (!arrayBuffer) {
134
+ logger?.log(`fetching fileUri`, fileUri);
135
+ const response = await fetch(fileUri);
136
+ if (!response.ok) {
137
+ throw new Error(`Failed to fetch fileUri: ${response.statusText}`);
138
+ }
139
+ arrayBuffer = await response.arrayBuffer();
140
+ logger?.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer);
141
+ }
142
+ // Create a new copy of the ArrayBuffer to avoid detachment issues
143
+ const bufferCopy = arrayBuffer.slice(0);
144
+ logger?.log(`extractAudioAnalysis bitDepth=${bitDepth} len=${bufferCopy.byteLength}`, bufferCopy.slice(0, 100));
145
+ let actualBitDepth = bitDepth;
146
+ if (!actualBitDepth) {
147
+ logger?.log(`extractAudioAnalysis bitDepth not provided -- getting wav file info`);
148
+ const fileInfo = await (0, getWavFileInfo_1.getWavFileInfo)(bufferCopy);
149
+ actualBitDepth = fileInfo.bitDepth;
150
+ }
151
+ logger?.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`);
152
+ const { pcmValues: channelData, min, max, } = await (0, convertPCMToFloat32_1.convertPCMToFloat32)({
153
+ buffer: arrayBuffer,
154
+ bitDepth: actualBitDepth,
155
+ });
156
+ logger?.log(`extractAudioAnalysis convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`);
157
+ // Apply position and length constraints to channelData if specified
158
+ const startIndex = position;
159
+ const endIndex = length ? startIndex + length : channelData.length;
160
+ const constrainedChannelData = channelData.slice(startIndex, endIndex);
161
+ return new Promise((resolve, reject) => {
162
+ const blob = new Blob([InlineFeaturesExtractor_web_1.InlineFeaturesExtractor], {
163
+ type: 'application/javascript',
164
+ });
165
+ const url = URL.createObjectURL(blob);
166
+ const worker = new Worker(url);
167
+ worker.onmessage = (event) => {
168
+ resolve(event.data.result);
169
+ };
170
+ worker.onerror = (error) => {
171
+ reject(error);
172
+ };
173
+ worker.postMessage({
174
+ command: 'process',
175
+ channelData: constrainedChannelData,
176
+ sampleRate,
177
+ segmentDurationMs,
178
+ logger,
179
+ bitDepth,
180
+ fullAudioDurationMs: durationMs,
181
+ numberOfChannels,
182
+ });
183
+ });
184
+ }
185
+ else {
186
+ if (!fileUri) {
187
+ throw new Error('fileUri is required');
188
+ }
189
+ logger?.log(`extractAudioAnalysis`, {
190
+ fileUri,
191
+ segmentDurationMs,
192
+ });
193
+ const res = await ExpoAudioStreamModule_1.default.extractAudioAnalysis({
194
+ fileUri,
195
+ segmentDurationMs,
196
+ features,
197
+ position,
198
+ length,
199
+ });
200
+ logger?.log(`extractAudioAnalysis`, res);
201
+ return res;
202
+ }
203
+ };
204
+ exports.extractRawWavAnalysis = extractRawWavAnalysis;
205
+ //# sourceMappingURL=extractAudioAnalysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractAudioAnalysis.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":";;;;;;AAQA,qFAA4D;AAC5D,4CAAoC;AAOpC,8DAA6D;AAC7D,sEAAkE;AAClE,2DAAkC;AAClC,4DAAqE;AACrE,wFAAgF;AAEhF,SAAS,0BAA0B,CAAC,IAAkB;IAClD,8CAA8C;IAC9C,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACjD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;IAE/C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACnC,QAAQ,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAA;IAC7C,CAAC;IAED,OAAO,eAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;AAC/B,CAAC;AAwD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C;QACD,MAAM,EAAE,GAAG,CAAC,sBAAsB,EAAE;YAChC,OAAO;YACP,iBAAiB;SACpB,CAAC,CAAA;QACF,MAAM,GAAG,GAAG,MAAM,+BAAqB,CAAC,oBAAoB,CAAC;YACzD,OAAO;YACP,iBAAiB;YACjB,QAAQ;YACR,QAAQ;YACR,MAAM;SACT,CAAC,CAAA;QACF,MAAM,EAAE,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;QACxC,OAAO,GAAG,CAAA;IACd,CAAC;AACL,CAAC,CAAA;AA9GY,QAAA,qBAAqB,yBA8GjC","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts\n/**\n * This module provides functions for extracting and analyzing audio data.\n * - `extractAudioAnalysis`: For detailed analysis with customizable ranges and decoding options.\n * - `extractWavAudioAnalysis`: For analyzing WAV files without decoding, preserving original PCM values.\n * - `extractPreview`: For generating quick previews of audio waveforms, optimized for UI rendering.\n */\nimport { ConsoleLike } from '../ExpoAudioStream.types'\nimport ExpoAudioStreamModule from '../ExpoAudioStreamModule'\nimport { isWeb } from '../constants'\nimport {\n AudioAnalysis,\n AudioFeaturesOptions,\n DataPoint,\n DecodingConfig,\n} from './AudioAnalysis.types'\nimport { processAudioBuffer } from '../utils/audioProcessing'\nimport { convertPCMToFloat32 } from '../utils/convertPCMToFloat32'\nimport crc32 from '../utils/crc32'\nimport { getWavFileInfo, WavFileInfo } from '../utils/getWavFileInfo'\nimport { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web'\n\nfunction calculateCRC32ForDataPoint(data: Float32Array): number {\n // Convert float array to byte array for CRC32\n const byteArray = new Uint8Array(data.length * 4)\n const dataView = new DataView(byteArray.buffer)\n\n for (let i = 0; i < data.length; i++) {\n dataView.setFloat32(i * 4, data[i], true)\n }\n\n return crc32.buf(byteArray)\n}\n\nexport interface ExtractWavAudioAnalysisProps {\n fileUri?: string // should provide either fileUri or arrayBuffer\n wavMetadata?: WavFileInfo\n arrayBuffer?: ArrayBuffer\n bitDepth?: number\n durationMs?: number\n sampleRate?: number\n numberOfChannels?: number\n position?: number // Optional number of bytes to skip. Default is 0\n length?: number // Optional number of bytes to read.\n segmentDurationMs?: number // Optional number of points per second. Use to reduce the number of points and compute the number of datapoints to return.\n features?: AudioFeaturesOptions\n featuresExtratorUrl?: string\n logger?: ConsoleLike\n decodingOptions?: DecodingConfig\n}\n\n// Define base options interface with common properties\ninterface BaseExtractOptions {\n fileUri?: string\n arrayBuffer?: ArrayBuffer\n /**\n * Duration of each analysis segment in milliseconds. Defaults to 100ms if not specified.\n */\n segmentDurationMs?: number\n features?: AudioFeaturesOptions\n decodingOptions?: DecodingConfig\n logger?: ConsoleLike\n}\n\n// Time-based range options\ninterface TimeRangeOptions extends BaseExtractOptions {\n startTimeMs?: number\n endTimeMs?: number\n position?: never\n length?: never\n}\n\n// Byte-based range options\ninterface ByteRangeOptions extends BaseExtractOptions {\n position?: number\n length?: number\n startTimeMs?: never\n endTimeMs?: never\n}\n\n/**\n * Options for extracting audio analysis.\n * - For time-based analysis, provide `startTimeMs` and `endTimeMs`.\n * - For byte-based analysis, provide `position` and `length`.\n * - Do not mix time and byte ranges.\n */\nexport type ExtractAudioAnalysisProps = TimeRangeOptions | ByteRangeOptions\n\n/**\n * Extracts detailed audio analysis from the specified audio file or buffer.\n * Supports either time-based or byte-based ranges for flexibility in analysis.\n *\n * @param props - The options for extraction, including file URI, ranges, and decoding settings.\n * @returns A promise that resolves to the audio analysis data.\n * @throws {Error} If both time and byte ranges are provided or if required parameters are missing.\n */\nexport async function extractAudioAnalysis(\n props: ExtractAudioAnalysisProps\n): Promise<AudioAnalysis> {\n const {\n fileUri,\n arrayBuffer,\n decodingOptions,\n logger,\n segmentDurationMs = 100,\n features,\n } = props\n\n if (isWeb) {\n try {\n // Create AudioContext here\n const audioContext = new (window.AudioContext ||\n (window as any).webkitAudioContext)({\n sampleRate: decodingOptions?.targetSampleRate ?? 16000,\n })\n\n try {\n const processedBuffer = await processAudioBuffer({\n arrayBuffer,\n fileUri,\n targetSampleRate:\n decodingOptions?.targetSampleRate ?? 16000,\n targetChannels: decodingOptions?.targetChannels ?? 1,\n normalizeAudio: decodingOptions?.normalizeAudio ?? false,\n startTimeMs:\n 'startTimeMs' in props ? props.startTimeMs : undefined,\n endTimeMs:\n 'endTimeMs' in props ? props.endTimeMs : undefined,\n position: 'position' in props ? props.position : undefined,\n length: 'length' in props ? props.length : undefined,\n audioContext, // Pass the context we created\n logger,\n })\n\n const channelData = processedBuffer.buffer.getChannelData(0)\n\n // Create and initialize the worker\n const blob = new Blob([InlineFeaturesExtractor], {\n type: 'application/javascript',\n })\n const workerUrl = URL.createObjectURL(blob)\n const worker = new Worker(workerUrl)\n\n return new Promise((resolve, reject) => {\n worker.onmessage = (event) => {\n if (event.data.error) {\n reject(new Error(event.data.error))\n return\n }\n\n const result: AudioAnalysis = event.data.result\n // Calculate CRC32 after worker completes if requested\n if (features?.crc32) {\n const samplesPerSegment = Math.floor(\n (processedBuffer.sampleRate *\n segmentDurationMs) /\n 1000\n )\n\n result.dataPoints = result.dataPoints.map(\n (point: DataPoint, index: number) => {\n const startSample =\n index * samplesPerSegment\n const segmentData = channelData.slice(\n startSample,\n startSample + samplesPerSegment\n )\n\n return {\n ...point,\n features: {\n ...point.features,\n crc32: calculateCRC32ForDataPoint(\n segmentData\n ),\n },\n }\n }\n )\n }\n\n URL.revokeObjectURL(workerUrl)\n worker.terminate()\n resolve(result)\n }\n\n worker.onerror = (error) => {\n URL.revokeObjectURL(workerUrl)\n worker.terminate()\n reject(error)\n }\n\n worker.postMessage({\n channelData,\n sampleRate: processedBuffer.sampleRate,\n segmentDurationMs,\n bitDepth: decodingOptions?.targetBitDepth ?? 32,\n numberOfChannels: processedBuffer.channels,\n fullAudioDurationMs: processedBuffer.durationMs,\n // enableLogging: !!logger,\n features,\n })\n })\n } finally {\n await audioContext.close()\n }\n } catch (error) {\n logger?.error('Failed to process audio:', error)\n throw error\n }\n } else {\n return await ExpoAudioStreamModule.extractAudioAnalysis(props)\n }\n}\n\n/**\n * Analyzes WAV files without decoding, preserving original PCM values.\n * Use this function when you need to ensure the analysis matches other software by avoiding any transformations.\n *\n * @param props - The options for WAV analysis, including file URI and range.\n * @returns A promise that resolves to the audio analysis data.\n */\nexport const extractRawWavAnalysis = async ({\n fileUri,\n segmentDurationMs = 100, // Default to 100ms\n arrayBuffer,\n bitDepth,\n durationMs,\n sampleRate,\n numberOfChannels,\n features,\n logger,\n position = 0,\n length,\n}: ExtractWavAudioAnalysisProps): Promise<AudioAnalysis> => {\n if (isWeb) {\n if (!arrayBuffer && !fileUri) {\n throw new Error('Either arrayBuffer or fileUri must be provided')\n }\n\n if (!arrayBuffer) {\n logger?.log(`fetching fileUri`, fileUri)\n const response = await fetch(fileUri!)\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch fileUri: ${response.statusText}`\n )\n }\n\n arrayBuffer = await response.arrayBuffer()\n logger?.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)\n }\n\n // Create a new copy of the ArrayBuffer to avoid detachment issues\n const bufferCopy = arrayBuffer.slice(0)\n logger?.log(\n `extractAudioAnalysis bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,\n bufferCopy.slice(0, 100)\n )\n\n let actualBitDepth = bitDepth\n if (!actualBitDepth) {\n logger?.log(\n `extractAudioAnalysis bitDepth not provided -- getting wav file info`\n )\n const fileInfo = await getWavFileInfo(bufferCopy)\n actualBitDepth = fileInfo.bitDepth\n }\n logger?.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`)\n\n const {\n pcmValues: channelData,\n min,\n max,\n } = await convertPCMToFloat32({\n buffer: arrayBuffer,\n bitDepth: actualBitDepth,\n })\n logger?.log(\n `extractAudioAnalysis convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`\n )\n\n // Apply position and length constraints to channelData if specified\n const startIndex = position\n const endIndex = length ? startIndex + length : channelData.length\n const constrainedChannelData = channelData.slice(startIndex, endIndex)\n\n return new Promise((resolve, reject) => {\n const blob = new Blob([InlineFeaturesExtractor], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n const worker = new Worker(url)\n\n worker.onmessage = (event) => {\n resolve(event.data.result)\n }\n\n worker.onerror = (error) => {\n reject(error)\n }\n\n worker.postMessage({\n command: 'process',\n channelData: constrainedChannelData,\n sampleRate,\n segmentDurationMs,\n logger,\n bitDepth,\n fullAudioDurationMs: durationMs,\n numberOfChannels,\n })\n })\n } else {\n if (!fileUri) {\n throw new Error('fileUri is required')\n }\n logger?.log(`extractAudioAnalysis`, {\n fileUri,\n segmentDurationMs,\n })\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n segmentDurationMs,\n features,\n position,\n length,\n })\n logger?.log(`extractAudioAnalysis`, res)\n return res\n }\n}\n"]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractAudioData = void 0;
7
+ const ExpoAudioStreamModule_1 = __importDefault(require("../ExpoAudioStreamModule"));
8
+ const extractAudioData = async (props) => {
9
+ return await ExpoAudioStreamModule_1.default.extractAudioData(props);
10
+ };
11
+ exports.extractAudioData = extractAudioData;
12
+ //# sourceMappingURL=extractAudioData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractAudioData.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/extractAudioData.ts"],"names":[],"mappings":";;;;;;AACA,qFAA4D;AAErD,MAAM,gBAAgB,GAAG,KAAK,EAAE,KAA8B,EAAE,EAAE;IACrE,OAAO,MAAM,+BAAqB,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;AAC9D,CAAC,CAAA;AAFY,QAAA,gBAAgB,oBAE5B","sourcesContent":["import { ExtractAudioDataOptions } from '../ExpoAudioStream.types'\nimport ExpoAudioStreamModule from '../ExpoAudioStreamModule'\n\nexport const extractAudioData = async (props: ExtractAudioDataOptions) => {\n return await ExpoAudioStreamModule.extractAudioData(props)\n}\n"]}
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ /**
3
+ * @experimental This feature is experimental and currently only available on Android.
4
+ * The API may change in future versions. The web implementation is a placeholder.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.extractMelSpectrogram = void 0;
8
+ const __1 = require("..");
9
+ const constants_1 = require("../constants");
10
+ const audioProcessing_1 = require("../utils/audioProcessing");
11
+ /**
12
+ * Extracts a mel spectrogram from audio data
13
+ *
14
+ * @experimental This feature is experimental and currently only available on Android.
15
+ * The iOS implementation will throw an "UNSUPPORTED_PLATFORM" error.
16
+ * The web implementation is a placeholder that returns dummy data.
17
+ */
18
+ async function extractMelSpectrogram(options) {
19
+ const { fileUri, arrayBuffer, windowSizeMs, hopLengthMs, nMels, fMin = 0, fMax, windowType = 'hann', normalize = false, logScale = true, decodingOptions, startTimeMs, endTimeMs, logger, } = options;
20
+ if (constants_1.isWeb) {
21
+ // Create audio context
22
+ const audioContext = new (window.AudioContext ||
23
+ window.webkitAudioContext)();
24
+ try {
25
+ // Process audio data using the existing utility
26
+ const processedAudio = await (0, audioProcessing_1.processAudioBuffer)({
27
+ arrayBuffer,
28
+ fileUri,
29
+ targetSampleRate: decodingOptions?.targetSampleRate || 16000,
30
+ targetChannels: decodingOptions?.targetChannels || 1,
31
+ normalizeAudio: decodingOptions?.normalizeAudio ?? false,
32
+ startTimeMs,
33
+ endTimeMs,
34
+ audioContext,
35
+ logger: options.logger,
36
+ });
37
+ // Calculate window and hop size in samples
38
+ const sampleRate = processedAudio.sampleRate;
39
+ const windowSize = Math.floor((windowSizeMs * sampleRate) / 1000);
40
+ const hopLength = Math.floor((hopLengthMs * sampleRate) / 1000);
41
+ const maxFreq = fMax || sampleRate / 2;
42
+ // Extract the mel spectrogram from the processed audio
43
+ const spectrogram = computeMelSpectrogram(processedAudio.channelData, sampleRate, nMels, windowSize, hopLength, fMin, maxFreq, windowType, normalize, logScale);
44
+ const timeSteps = spectrogram.length;
45
+ return {
46
+ spectrogram,
47
+ sampleRate,
48
+ nMels,
49
+ timeSteps,
50
+ durationMs: processedAudio.durationMs,
51
+ };
52
+ }
53
+ catch (error) {
54
+ logger?.error('Error extracting mel spectrogram:', error);
55
+ throw error;
56
+ }
57
+ finally {
58
+ // Close the audio context
59
+ await audioContext.close();
60
+ }
61
+ }
62
+ return __1.ExpoAudioStreamModule.extractMelSpectrogram(options);
63
+ }
64
+ exports.extractMelSpectrogram = extractMelSpectrogram;
65
+ /**
66
+ * Computes a mel spectrogram from audio data
67
+ *
68
+ * @experimental This is a placeholder implementation that returns dummy data.
69
+ * The actual implementation will be added in a future version.
70
+ */
71
+ function computeMelSpectrogram(audioData, sampleRate, nMels, windowSize, hopLength, fMin, fMax, windowType, normalize, logScale) {
72
+ // Placeholder for the actual implementation
73
+ // This would include:
74
+ // 1. Windowing the audio data using the specified window type
75
+ // 2. Computing the STFT (Short-Time Fourier Transform)
76
+ // 3. Converting to power spectrogram
77
+ // 4. Applying mel filterbanks
78
+ // 5. Taking the logarithm if logScale is true
79
+ // 6. Normalizing if normalize is true
80
+ // For now, return a dummy implementation
81
+ const numFrames = Math.floor((audioData.length - windowSize) / hopLength) + 1;
82
+ const spectrogram = [];
83
+ // Create dummy mel spectrogram data
84
+ for (let i = 0; i < numFrames; i++) {
85
+ spectrogram.push(Array(nMels).fill(0));
86
+ }
87
+ return spectrogram;
88
+ }
89
+ //# sourceMappingURL=extractMelSpectrogram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractMelSpectrogram.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/extractMelSpectrogram.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,0BAA0C;AAC1C,4CAAoC;AAKpC,8DAGiC;AAEjC;;;;;;GAMG;AACI,KAAK,UAAU,qBAAqB,CACvC,OAAqC;IAErC,M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currently only available on Android.\n * The API may change in future versions. The web implementation is a placeholder.\n */\n\nimport { ExpoAudioStreamModule } from '..'\nimport { isWeb } from '../constants'\nimport {\n ExtractMelSpectrogramOptions,\n MelSpectrogram,\n} from './AudioAnalysis.types'\nimport {\n processAudioBuffer,\n ProcessedAudioData,\n} from '../utils/audioProcessing'\n\n/**\n * Extracts a mel spectrogram from audio data\n *\n * @experimental This feature is experimental and currently only available on Android.\n * The iOS implementation will throw an \"UNSUPPORTED_PLATFORM\" error.\n * The web implementation is a placeholder that returns dummy data.\n */\nexport async function extractMelSpectrogram(\n options: ExtractMelSpectrogramOptions\n): Promise<MelSpectrogram> {\n const {\n fileUri,\n arrayBuffer,\n windowSizeMs,\n hopLengthMs,\n nMels,\n fMin = 0,\n fMax,\n windowType = 'hann',\n normalize = false,\n logScale = true,\n decodingOptions,\n startTimeMs,\n endTimeMs,\n logger,\n } = options\n\n if (isWeb) {\n // Create audio context\n const audioContext = new (window.AudioContext ||\n (window as any).webkitAudioContext)()\n\n try {\n // Process audio data using the existing utility\n const processedAudio: ProcessedAudioData = await processAudioBuffer(\n {\n arrayBuffer,\n fileUri,\n targetSampleRate:\n decodingOptions?.targetSampleRate || 16000,\n targetChannels: decodingOptions?.targetChannels || 1,\n normalizeAudio: decodingOptions?.normalizeAudio ?? false,\n startTimeMs,\n endTimeMs,\n audioContext,\n logger: options.logger,\n }\n )\n\n // Calculate window and hop size in samples\n const sampleRate = processedAudio.sampleRate\n const windowSize = Math.floor((windowSizeMs * sampleRate) / 1000)\n const hopLength = Math.floor((hopLengthMs * sampleRate) / 1000)\n const maxFreq = fMax || sampleRate / 2\n\n // Extract the mel spectrogram from the processed audio\n const spectrogram = computeMelSpectrogram(\n processedAudio.channelData,\n sampleRate,\n nMels,\n windowSize,\n hopLength,\n fMin,\n maxFreq,\n windowType,\n normalize,\n logScale\n )\n\n const timeSteps = spectrogram.length\n\n return {\n spectrogram,\n sampleRate,\n nMels,\n timeSteps,\n durationMs: processedAudio.durationMs,\n }\n } catch (error) {\n logger?.error('Error extracting mel spectrogram:', error)\n throw error\n } finally {\n // Close the audio context\n await audioContext.close()\n }\n }\n return ExpoAudioStreamModule.extractMelSpectrogram(options)\n}\n\n/**\n * Computes a mel spectrogram from audio data\n *\n * @experimental This is a placeholder implementation that returns dummy data.\n * The actual implementation will be added in a future version.\n */\nfunction computeMelSpectrogram(\n audioData: Float32Array,\n sampleRate: number,\n nMels: number,\n windowSize: number,\n hopLength: number,\n fMin: number,\n fMax: number,\n windowType: 'hann' | 'hamming',\n normalize: boolean,\n logScale: boolean\n): number[][] {\n // Placeholder for the actual implementation\n // This would include:\n // 1. Windowing the audio data using the specified window type\n // 2. Computing the STFT (Short-Time Fourier Transform)\n // 3. Converting to power spectrogram\n // 4. Applying mel filterbanks\n // 5. Taking the logarithm if logScale is true\n // 6. Normalizing if normalize is true\n\n // For now, return a dummy implementation\n const numFrames =\n Math.floor((audioData.length - windowSize) / hopLength) + 1\n const spectrogram: number[][] = []\n\n // Create dummy mel spectrogram data\n for (let i = 0; i < numFrames; i++) {\n spectrogram.push(Array(nMels).fill(0))\n }\n\n return spectrogram\n}\n"]}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.extractPreview = void 0;
4
+ const extractAudioAnalysis_1 = require("./extractAudioAnalysis");
5
+ /**
6
+ * Generates a simplified preview of the audio waveform for quick visualization.
7
+ * Ideal for UI rendering with a specified number of points.
8
+ *
9
+ * @param options - The options for the preview, including file URI and time range.
10
+ * @returns A promise that resolves to the audio preview data.
11
+ */
12
+ async function extractPreview({ fileUri, numberOfPoints = 100, startTimeMs = 0, endTimeMs = 30000, // First 30 seconds
13
+ decodingOptions, logger, }) {
14
+ const durationMs = endTimeMs - startTimeMs;
15
+ const segmentDurationMs = Math.floor(durationMs / numberOfPoints);
16
+ // Call extractAudioAnalysis with calculated parameters
17
+ const analysis = await (0, extractAudioAnalysis_1.extractAudioAnalysis)({
18
+ fileUri,
19
+ startTimeMs,
20
+ endTimeMs,
21
+ logger,
22
+ segmentDurationMs,
23
+ decodingOptions,
24
+ });
25
+ // Transform the result into AudioPreview format
26
+ return analysis;
27
+ }
28
+ exports.extractPreview = extractPreview;
29
+ //# sourceMappingURL=extractPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractPreview.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/extractPreview.ts"],"names":[],"mappings":";;;AACA,iEAA6D;AAE7D;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAAC,EACjC,OAAO,EACP,cAAc,GAAG,GAAG,EACpB,WAAW,GAAG,CAAC,EACf,SAAS,GAAG,KAAK,EAAE,mBAAmB;AACtC,eAAe,EACf,MAAM,GACO;IACb,MAAM,UAAU,GAAG,SAAS,GAAG,WAAW,CAAA;IAC1C,MAAM,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,cAAc,CAAC,CAAA;IAEjE,uDAAuD;IACvD,MAAM,QAAQ,GAAG,MAAM,IAAA,2CAAoB,EAAC;QACxC,OAAO;QACP,WAAW;QACX,SAAS;QACT,MAAM;QACN,iBAAiB;QACjB,eAAe;KAClB,CAAC,CAAA;IAEF,gDAAgD;IAChD,OAAO,QAAQ,CAAA;AACnB,CAAC;AAvBD,wCAuBC","sourcesContent":["import { PreviewOptions, AudioAnalysis } from './AudioAnalysis.types'\nimport { extractAudioAnalysis } from './extractAudioAnalysis'\n\n/**\n * Generates a simplified preview of the audio waveform for quick visualization.\n * Ideal for UI rendering with a specified number of points.\n *\n * @param options - The options for the preview, including file URI and time range.\n * @returns A promise that resolves to the audio preview data.\n */\nexport async function extractPreview({\n fileUri,\n numberOfPoints = 100,\n startTimeMs = 0,\n endTimeMs = 30000, // First 30 seconds\n decodingOptions,\n logger,\n}: PreviewOptions): Promise<AudioAnalysis> {\n const durationMs = endTimeMs - startTimeMs\n const segmentDurationMs = Math.floor(durationMs / numberOfPoints)\n\n // Call extractAudioAnalysis with calculated parameters\n const analysis = await extractAudioAnalysis({\n fileUri,\n startTimeMs,\n endTimeMs,\n logger,\n segmentDurationMs,\n decodingOptions,\n })\n\n // Transform the result into AudioPreview format\n return analysis\n}\n"]}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.extractWaveform = void 0;
7
+ const ExpoAudioStreamModule_1 = __importDefault(require("../ExpoAudioStreamModule"));
8
+ const extractWaveform = async ({ fileUri, numberOfSamples, offset = 0, length, }) => {
9
+ const res = await ExpoAudioStreamModule_1.default.extractAudioAnalysis({
10
+ fileUri,
11
+ numberOfSamples,
12
+ offset,
13
+ length,
14
+ });
15
+ return res;
16
+ };
17
+ exports.extractWaveform = extractWaveform;
18
+ //# sourceMappingURL=extractWaveform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractWaveform.js","sourceRoot":"","sources":["../../../src/AudioAnalysis/extractWaveform.ts"],"names":[],"mappings":";;;;;;AAAA,qFAA4D;AAQrD,MAAM,eAAe,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,eAAe,EACf,MAAM,GAAG,CAAC,EACV,MAAM,GACa,EAAoB,EAAE;IACzC,MAAM,GAAG,GAAG,MAAM,+BAAqB,CAAC,oBAAoB,CAAC;QACzD,OAAO;QACP,eAAe;QACf,MAAM;QACN,MAAM;KACT,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACd,CAAC,CAAA;AAbY,QAAA,eAAe,mBAa3B","sourcesContent":["import ExpoAudioStreamModule from '../ExpoAudioStreamModule'\n\nexport interface ExtractWaveformProps {\n fileUri: string\n numberOfSamples: number\n offset?: number\n length?: number\n}\nexport const extractWaveform = async ({\n fileUri,\n numberOfSamples,\n offset = 0,\n length,\n}: ExtractWaveformProps): Promise<unknown> => {\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n numberOfSamples,\n offset,\n length,\n })\n return res\n}\n"]}