@siteed/expo-audio-stream 2.1.0 → 2.2.1-beta.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 (189) hide show
  1. package/README.md +23 -260
  2. package/build/index.d.ts +11 -15
  3. package/build/index.js +54 -14
  4. package/build/src/index.d.ts +11 -0
  5. package/build/src/index.js +54 -0
  6. package/package.json +49 -110
  7. package/src/index.ts +18 -32
  8. package/CHANGELOG.md +0 -206
  9. package/android/build.gradle +0 -105
  10. package/android/src/main/AndroidManifest.xml +0 -27
  11. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +0 -166
  12. package/android/src/main/java/net/siteed/audiostream/AudioDataEncoder.kt +0 -9
  13. package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +0 -131
  14. package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +0 -103
  15. package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +0 -435
  16. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +0 -2235
  17. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +0 -1437
  18. package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +0 -152
  19. package/android/src/main/java/net/siteed/audiostream/AudioTrimmer.kt +0 -1099
  20. package/android/src/main/java/net/siteed/audiostream/Constants.kt +0 -21
  21. package/android/src/main/java/net/siteed/audiostream/EventSender.kt +0 -7
  22. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +0 -739
  23. package/android/src/main/java/net/siteed/audiostream/FFT.kt +0 -99
  24. package/android/src/main/java/net/siteed/audiostream/Features.kt +0 -98
  25. package/android/src/main/java/net/siteed/audiostream/NotificationConfig.kt +0 -70
  26. package/android/src/main/java/net/siteed/audiostream/PermissionUtils.kt +0 -59
  27. package/android/src/main/java/net/siteed/audiostream/RecordingActionReceiver.kt +0 -59
  28. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +0 -205
  29. package/android/src/main/java/net/siteed/audiostream/WaveformConfig.kt +0 -19
  30. package/android/src/main/java/net/siteed/audiostream/WaveformRenderer.kt +0 -159
  31. package/android/src/main/res/drawable/ic_default_action_icon.xml +0 -16
  32. package/android/src/main/res/drawable/ic_microphone.xml +0 -13
  33. package/android/src/main/res/drawable/ic_pause.xml +0 -10
  34. package/android/src/main/res/drawable/ic_play.xml +0 -10
  35. package/android/src/main/res/drawable/ic_stop.xml +0 -10
  36. package/android/src/main/res/layout/notification_recording.xml +0 -37
  37. package/android/src/main/test/java/net/siteed/audiostream/AudioProcessorTest.kt +0 -56
  38. package/app.plugin.js +0 -1
  39. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -179
  40. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  41. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  42. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  43. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -68
  44. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  45. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -203
  46. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  47. package/build/AudioAnalysis/extractAudioData.d.ts +0 -3
  48. package/build/AudioAnalysis/extractAudioData.d.ts.map +0 -1
  49. package/build/AudioAnalysis/extractAudioData.js +0 -5
  50. package/build/AudioAnalysis/extractAudioData.js.map +0 -1
  51. package/build/AudioAnalysis/extractMelSpectrogram.d.ts +0 -14
  52. package/build/AudioAnalysis/extractMelSpectrogram.d.ts.map +0 -1
  53. package/build/AudioAnalysis/extractMelSpectrogram.js +0 -85
  54. package/build/AudioAnalysis/extractMelSpectrogram.js.map +0 -1
  55. package/build/AudioAnalysis/extractPreview.d.ts +0 -11
  56. package/build/AudioAnalysis/extractPreview.d.ts.map +0 -1
  57. package/build/AudioAnalysis/extractPreview.js +0 -25
  58. package/build/AudioAnalysis/extractPreview.js.map +0 -1
  59. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  60. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  61. package/build/AudioAnalysis/extractWaveform.js +0 -11
  62. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  63. package/build/AudioRecorder.provider.d.ts +0 -11
  64. package/build/AudioRecorder.provider.d.ts.map +0 -1
  65. package/build/AudioRecorder.provider.js +0 -37
  66. package/build/AudioRecorder.provider.js.map +0 -1
  67. package/build/ExpoAudioStream.native.d.ts +0 -3
  68. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  69. package/build/ExpoAudioStream.native.js +0 -6
  70. package/build/ExpoAudioStream.native.js.map +0 -1
  71. package/build/ExpoAudioStream.types.d.ts +0 -532
  72. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  73. package/build/ExpoAudioStream.types.js +0 -2
  74. package/build/ExpoAudioStream.types.js.map +0 -1
  75. package/build/ExpoAudioStream.web.d.ts +0 -59
  76. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  77. package/build/ExpoAudioStream.web.js +0 -285
  78. package/build/ExpoAudioStream.web.js.map +0 -1
  79. package/build/ExpoAudioStreamModule.d.ts +0 -3
  80. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  81. package/build/ExpoAudioStreamModule.js +0 -693
  82. package/build/ExpoAudioStreamModule.js.map +0 -1
  83. package/build/WebRecorder.web.d.ts +0 -119
  84. package/build/WebRecorder.web.d.ts.map +0 -1
  85. package/build/WebRecorder.web.js +0 -436
  86. package/build/WebRecorder.web.js.map +0 -1
  87. package/build/constants.d.ts +0 -11
  88. package/build/constants.d.ts.map +0 -1
  89. package/build/constants.js +0 -14
  90. package/build/constants.js.map +0 -1
  91. package/build/events.d.ts +0 -26
  92. package/build/events.d.ts.map +0 -1
  93. package/build/events.js +0 -21
  94. package/build/events.js.map +0 -1
  95. package/build/index.d.ts.map +0 -1
  96. package/build/index.js.map +0 -1
  97. package/build/trimAudio.d.ts +0 -25
  98. package/build/trimAudio.d.ts.map +0 -1
  99. package/build/trimAudio.js +0 -67
  100. package/build/trimAudio.js.map +0 -1
  101. package/build/useAudioRecorder.d.ts +0 -21
  102. package/build/useAudioRecorder.d.ts.map +0 -1
  103. package/build/useAudioRecorder.js +0 -427
  104. package/build/useAudioRecorder.js.map +0 -1
  105. package/build/utils/BlobFix.d.ts +0 -9
  106. package/build/utils/BlobFix.d.ts.map +0 -1
  107. package/build/utils/BlobFix.js +0 -498
  108. package/build/utils/BlobFix.js.map +0 -1
  109. package/build/utils/audioProcessing.d.ts +0 -24
  110. package/build/utils/audioProcessing.d.ts.map +0 -1
  111. package/build/utils/audioProcessing.js +0 -133
  112. package/build/utils/audioProcessing.js.map +0 -1
  113. package/build/utils/concatenateBuffers.d.ts +0 -8
  114. package/build/utils/concatenateBuffers.d.ts.map +0 -1
  115. package/build/utils/concatenateBuffers.js +0 -21
  116. package/build/utils/concatenateBuffers.js.map +0 -1
  117. package/build/utils/convertPCMToFloat32.d.ts +0 -13
  118. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  119. package/build/utils/convertPCMToFloat32.js +0 -120
  120. package/build/utils/convertPCMToFloat32.js.map +0 -1
  121. package/build/utils/encodingToBitDepth.d.ts +0 -5
  122. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  123. package/build/utils/encodingToBitDepth.js +0 -13
  124. package/build/utils/encodingToBitDepth.js.map +0 -1
  125. package/build/utils/getWavFileInfo.d.ts +0 -26
  126. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  127. package/build/utils/getWavFileInfo.js +0 -92
  128. package/build/utils/getWavFileInfo.js.map +0 -1
  129. package/build/utils/writeWavHeader.d.ts +0 -49
  130. package/build/utils/writeWavHeader.d.ts.map +0 -1
  131. package/build/utils/writeWavHeader.js +0 -91
  132. package/build/utils/writeWavHeader.js.map +0 -1
  133. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  134. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  135. package/build/workers/InlineFeaturesExtractor.web.js +0 -828
  136. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  137. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  138. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  139. package/build/workers/inlineAudioWebWorker.web.js +0 -157
  140. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  141. package/expo-module.config.json +0 -9
  142. package/ios/AudioAnalysisData.swift +0 -74
  143. package/ios/AudioNotificationManager.swift +0 -135
  144. package/ios/AudioProcessingHelpers.swift +0 -743
  145. package/ios/AudioProcessor.swift +0 -1313
  146. package/ios/AudioStreamError.swift +0 -7
  147. package/ios/AudioStreamManager.swift +0 -1708
  148. package/ios/AudioStreamManagerDelegate.swift +0 -16
  149. package/ios/DataPoint.swift +0 -54
  150. package/ios/DecodingConfig.swift +0 -47
  151. package/ios/ExpoAudioStream.podspec +0 -27
  152. package/ios/ExpoAudioStreamModule.swift +0 -805
  153. package/ios/FFT.swift +0 -62
  154. package/ios/Features.swift +0 -95
  155. package/ios/Logger.swift +0 -7
  156. package/ios/NotificationExtension.swift +0 -15
  157. package/ios/RecordingResult.swift +0 -22
  158. package/ios/RecordingSettings.swift +0 -265
  159. package/ios/WaveformExtractor.swift +0 -105
  160. package/plugin/build/index.d.ts +0 -21
  161. package/plugin/build/index.js +0 -191
  162. package/plugin/src/index.ts +0 -278
  163. package/plugin/tsconfig.json +0 -10
  164. package/plugin/tsconfig.tsbuildinfo +0 -1
  165. package/src/AudioAnalysis/AudioAnalysis.types.ts +0 -202
  166. package/src/AudioAnalysis/extractAudioAnalysis.ts +0 -333
  167. package/src/AudioAnalysis/extractAudioData.ts +0 -6
  168. package/src/AudioAnalysis/extractMelSpectrogram.ts +0 -144
  169. package/src/AudioAnalysis/extractPreview.ts +0 -34
  170. package/src/AudioAnalysis/extractWaveform.ts +0 -22
  171. package/src/AudioRecorder.provider.tsx +0 -54
  172. package/src/ExpoAudioStream.native.ts +0 -6
  173. package/src/ExpoAudioStream.types.ts +0 -641
  174. package/src/ExpoAudioStream.web.ts +0 -359
  175. package/src/ExpoAudioStreamModule.ts +0 -967
  176. package/src/WebRecorder.web.ts +0 -580
  177. package/src/constants.ts +0 -18
  178. package/src/events.ts +0 -60
  179. package/src/trimAudio.ts +0 -90
  180. package/src/useAudioRecorder.tsx +0 -620
  181. package/src/utils/BlobFix.ts +0 -559
  182. package/src/utils/audioProcessing.ts +0 -205
  183. package/src/utils/concatenateBuffers.ts +0 -24
  184. package/src/utils/convertPCMToFloat32.ts +0 -170
  185. package/src/utils/encodingToBitDepth.ts +0 -18
  186. package/src/utils/getWavFileInfo.ts +0 -132
  187. package/src/utils/writeWavHeader.ts +0 -114
  188. package/src/workers/InlineFeaturesExtractor.web.tsx +0 -827
  189. package/src/workers/inlineAudioWebWorker.web.tsx +0 -156
@@ -1,25 +0,0 @@
1
- import { TrimAudioOptions, TrimAudioResult, TrimProgressEvent } from './ExpoAudioStream.types';
2
- /**
3
- * Trims an audio file based on the provided options.
4
- *
5
- * @experimental This API is experimental and not fully optimized for production use.
6
- * Performance may vary based on file size and device capabilities.
7
- * Future versions may include breaking changes.
8
- *
9
- * @param options Configuration options for the trimming operation
10
- * @param progressCallback Optional callback to receive progress updates
11
- * @returns Promise resolving to the trimmed audio file information, including processing time
12
- */
13
- export declare function trimAudio(options: TrimAudioOptions, progressCallback?: (event: TrimProgressEvent) => void): Promise<TrimAudioResult>;
14
- /**
15
- * Simplified version of trimAudio that returns only the URI of the trimmed file.
16
- *
17
- * @experimental This API is experimental and not fully optimized for production use.
18
- * Performance may vary based on file size and device capabilities.
19
- * Future versions may include breaking changes.
20
- *
21
- * @param options Configuration options for the trimming operation
22
- * @returns Promise resolving to the URI of the trimmed audio file
23
- */
24
- export declare function trimAudioSimple(options: TrimAudioOptions): Promise<string>;
25
- //# sourceMappingURL=trimAudio.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trimAudio.d.ts","sourceRoot":"","sources":["../src/trimAudio.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACpB,MAAM,yBAAyB,CAAA;AAMhC;;;;;;;;;;GAUG;AACH,wBAAsB,SAAS,CAC3B,OAAO,EAAE,gBAAgB,EACzB,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,GACtD,OAAO,CAAC,eAAe,CAAC,CA8C1B;AAED;;;;;;;;;GASG;AACH,wBAAsB,eAAe,CACjC,OAAO,EAAE,gBAAgB,GAC1B,OAAO,CAAC,MAAM,CAAC,CAGjB"}
@@ -1,67 +0,0 @@
1
- import { LegacyEventEmitter } from 'expo-modules-core';
2
- import ExpoAudioStreamModule from './ExpoAudioStreamModule';
3
- // Create a single emitter instance
4
- const emitter = new LegacyEventEmitter(ExpoAudioStreamModule);
5
- /**
6
- * Trims an audio file based on the provided options.
7
- *
8
- * @experimental This API is experimental and not fully optimized for production use.
9
- * Performance may vary based on file size and device capabilities.
10
- * Future versions may include breaking changes.
11
- *
12
- * @param options Configuration options for the trimming operation
13
- * @param progressCallback Optional callback to receive progress updates
14
- * @returns Promise resolving to the trimmed audio file information, including processing time
15
- */
16
- export async function trimAudio(options, progressCallback) {
17
- // Validation
18
- if (!options.fileUri) {
19
- throw new Error('fileUri is required');
20
- }
21
- const mode = options.mode ?? 'single';
22
- if (mode === 'single') {
23
- if (options.startTimeMs === undefined &&
24
- options.endTimeMs === undefined) {
25
- throw new Error('At least one of startTimeMs or endTimeMs must be provided in single mode');
26
- }
27
- }
28
- else if (mode === 'keep' || mode === 'remove') {
29
- if (!options.ranges || options.ranges.length === 0) {
30
- throw new Error('ranges must be provided and non-empty for keep or remove modes');
31
- }
32
- }
33
- else {
34
- throw new Error(`Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`);
35
- }
36
- // Set up progress event listener if callback is provided
37
- let subscription;
38
- if (progressCallback) {
39
- subscription = emitter.addListener('TrimProgress', (event) => {
40
- progressCallback(event);
41
- });
42
- }
43
- try {
44
- const result = await ExpoAudioStreamModule.trimAudio(options);
45
- return result;
46
- }
47
- finally {
48
- if (subscription) {
49
- subscription.remove();
50
- }
51
- }
52
- }
53
- /**
54
- * Simplified version of trimAudio that returns only the URI of the trimmed file.
55
- *
56
- * @experimental This API is experimental and not fully optimized for production use.
57
- * Performance may vary based on file size and device capabilities.
58
- * Future versions may include breaking changes.
59
- *
60
- * @param options Configuration options for the trimming operation
61
- * @returns Promise resolving to the URI of the trimmed audio file
62
- */
63
- export async function trimAudioSimple(options) {
64
- const result = await trimAudio(options);
65
- return result.uri;
66
- }
67
- //# sourceMappingURL=trimAudio.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trimAudio.js","sourceRoot":"","sources":["../src/trimAudio.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,mBAAmB,CAAA;AAO9E,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAE3D,mCAAmC;AACnC,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,qBAAqB,CAAC,CAAA;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC3B,OAAyB,EACzB,gBAAqD;IAErD,aAAa;IACb,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAC1C,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,QAAQ,CAAA;IACrC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QACpB,IACI,OAAO,CAAC,WAAW,KAAK,SAAS;YACjC,OAAO,CAAC,SAAS,KAAK,SAAS,EACjC,CAAC;YACC,MAAM,IAAI,KAAK,CACX,0EAA0E,CAC7E,CAAA;QACL,CAAC;IACL,CAAC;SAAM,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9C,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACjD,MAAM,IAAI,KAAK,CACX,gEAAgE,CACnE,CAAA;QACL,CAAC;IACL,CAAC;SAAM,CAAC;QACJ,MAAM,IAAI,KAAK,CACX,iBAAiB,IAAI,yCAAyC,CACjE,CAAA;IACL,CAAC;IAED,yDAAyD;IACzD,IAAI,YAA2C,CAAA;IAC/C,IAAI,gBAAgB,EAAE,CAAC;QACnB,YAAY,GAAG,OAAO,CAAC,WAAW,CAC9B,cAAc,EACd,CAAC,KAAwB,EAAE,EAAE;YACzB,gBAAgB,CAAC,KAAK,CAAC,CAAA;QAC3B,CAAC,CACJ,CAAA;IACL,CAAC;IAED,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,qBAAqB,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QAC7D,OAAO,MAAM,CAAA;IACjB,CAAC;YAAS,CAAC;QACP,IAAI,YAAY,EAAE,CAAC;YACf,YAAY,CAAC,MAAM,EAAE,CAAA;QACzB,CAAC;IACL,CAAC;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACjC,OAAyB;IAEzB,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,MAAM,CAAC,GAAG,CAAA;AACrB,CAAC","sourcesContent":["import { LegacyEventEmitter, type EventSubscription } from 'expo-modules-core'\n\nimport {\n TrimAudioOptions,\n TrimAudioResult,\n TrimProgressEvent,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\n\n// Create a single emitter instance\nconst emitter = new LegacyEventEmitter(ExpoAudioStreamModule)\n\n/**\n * Trims an audio file based on the provided options.\n *\n * @experimental This API is experimental and not fully optimized for production use.\n * Performance may vary based on file size and device capabilities.\n * Future versions may include breaking changes.\n *\n * @param options Configuration options for the trimming operation\n * @param progressCallback Optional callback to receive progress updates\n * @returns Promise resolving to the trimmed audio file information, including processing time\n */\nexport async function trimAudio(\n options: TrimAudioOptions,\n progressCallback?: (event: TrimProgressEvent) => void\n): Promise<TrimAudioResult> {\n // Validation\n if (!options.fileUri) {\n throw new Error('fileUri is required')\n }\n const mode = options.mode ?? 'single'\n if (mode === 'single') {\n if (\n options.startTimeMs === undefined &&\n options.endTimeMs === undefined\n ) {\n throw new Error(\n 'At least one of startTimeMs or endTimeMs must be provided in single mode'\n )\n }\n } else if (mode === 'keep' || mode === 'remove') {\n if (!options.ranges || options.ranges.length === 0) {\n throw new Error(\n 'ranges must be provided and non-empty for keep or remove modes'\n )\n }\n } else {\n throw new Error(\n `Invalid mode: ${mode}. Must be 'single', 'keep', or 'remove'`\n )\n }\n\n // Set up progress event listener if callback is provided\n let subscription: EventSubscription | undefined\n if (progressCallback) {\n subscription = emitter.addListener(\n 'TrimProgress',\n (event: TrimProgressEvent) => {\n progressCallback(event)\n }\n )\n }\n\n try {\n const result = await ExpoAudioStreamModule.trimAudio(options)\n return result\n } finally {\n if (subscription) {\n subscription.remove()\n }\n }\n}\n\n/**\n * Simplified version of trimAudio that returns only the URI of the trimmed file.\n *\n * @experimental This API is experimental and not fully optimized for production use.\n * Performance may vary based on file size and device capabilities.\n * Future versions may include breaking changes.\n *\n * @param options Configuration options for the trimming operation\n * @returns Promise resolving to the URI of the trimmed audio file\n */\nexport async function trimAudioSimple(\n options: TrimAudioOptions\n): Promise<string> {\n const result = await trimAudio(options)\n return result.uri\n}\n"]}
@@ -1,21 +0,0 @@
1
- import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
2
- import { AudioRecording, CompressionInfo, ConsoleLike, RecordingConfig, StartRecordingResult } from './ExpoAudioStream.types';
3
- export interface UseAudioRecorderProps {
4
- logger?: ConsoleLike;
5
- audioWorkletUrl?: string;
6
- featuresExtratorUrl?: string;
7
- }
8
- export interface UseAudioRecorderState {
9
- startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
10
- stopRecording: () => Promise<AudioRecording>;
11
- pauseRecording: () => Promise<void>;
12
- resumeRecording: () => Promise<void>;
13
- isRecording: boolean;
14
- isPaused: boolean;
15
- durationMs: number;
16
- size: number;
17
- compression?: CompressionInfo;
18
- analysisData?: AudioAnalysis;
19
- }
20
- export declare function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl, }?: UseAudioRecorderProps): UseAudioRecorderState;
21
- //# sourceMappingURL=useAudioRecorder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAudioRecorder.d.ts","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAEH,cAAc,EAEd,eAAe,EACf,WAAW,EACX,eAAe,EACf,oBAAoB,EACvB,MAAM,yBAAyB,CAAA;AAShC,MAAM,WAAW,qBAAqB;IAClC,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,mBAAmB,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrE,aAAa,EAAE,MAAM,OAAO,CAAC,cAAc,CAAC,CAAA;IAC5C,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,eAAe,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IACpC,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,CAAC,EAAE,eAAe,CAAA;IAC7B,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B;AAkHD,wBAAgB,gBAAgB,CAAC,EAC7B,MAAM,EACN,eAAe,EACf,mBAAmB,GACtB,GAAE,qBAA0B,GAAG,qBAAqB,CA8cpD"}
@@ -1,427 +0,0 @@
1
- // src/useAudioRecorder.ts
2
- import { Platform } from 'expo-modules-core';
3
- import { useCallback, useEffect, useReducer, useRef } from 'react';
4
- import ExpoAudioStreamModule from './ExpoAudioStreamModule';
5
- import { addAudioAnalysisListener, addAudioEventListener, addRecordingInterruptionListener, } from './events';
6
- const defaultAnalysis = {
7
- segmentDurationMs: 100,
8
- bitDepth: 32,
9
- numberOfChannels: 1,
10
- durationMs: 0,
11
- sampleRate: 44100,
12
- samples: 0,
13
- dataPoints: [],
14
- rmsRange: {
15
- min: Number.POSITIVE_INFINITY,
16
- max: Number.NEGATIVE_INFINITY,
17
- },
18
- amplitudeRange: {
19
- min: Number.POSITIVE_INFINITY,
20
- max: Number.NEGATIVE_INFINITY,
21
- },
22
- };
23
- function audioRecorderReducer(state, action) {
24
- switch (action.type) {
25
- case 'START':
26
- return {
27
- ...state,
28
- isRecording: true,
29
- isPaused: false,
30
- durationMs: 0,
31
- size: 0,
32
- compression: undefined,
33
- analysisData: defaultAnalysis,
34
- };
35
- case 'STOP':
36
- return {
37
- ...state,
38
- isRecording: false,
39
- isPaused: false,
40
- durationMs: 0,
41
- size: 0,
42
- compression: undefined,
43
- analysisData: undefined,
44
- };
45
- case 'PAUSE':
46
- return { ...state, isPaused: true, isRecording: false };
47
- case 'RESUME':
48
- return { ...state, isPaused: false, isRecording: true };
49
- case 'UPDATE_RECORDING_STATE':
50
- return {
51
- ...state,
52
- isPaused: action.payload.isPaused,
53
- isRecording: action.payload.isRecording,
54
- };
55
- case 'UPDATE_STATUS': {
56
- const newState = {
57
- ...state,
58
- durationMs: action.payload.durationMs,
59
- size: action.payload.size,
60
- compression: action.payload.compression
61
- ? {
62
- size: action.payload.compression.size,
63
- mimeType: action.payload.compression.mimeType,
64
- bitrate: action.payload.compression.bitrate,
65
- format: action.payload.compression.format,
66
- }
67
- : undefined,
68
- };
69
- return newState;
70
- }
71
- case 'UPDATE_ANALYSIS':
72
- return {
73
- ...state,
74
- analysisData: action.payload,
75
- };
76
- default:
77
- return state;
78
- }
79
- }
80
- export function useAudioRecorder({ logger, audioWorkletUrl, featuresExtratorUrl, } = {}) {
81
- const [state, dispatch] = useReducer(audioRecorderReducer, {
82
- isRecording: false,
83
- isPaused: false,
84
- durationMs: 0,
85
- size: 0,
86
- compression: undefined,
87
- analysisData: undefined,
88
- });
89
- const startResultRef = useRef(null);
90
- const analysisListenerRef = useRef(null);
91
- // analysisRef is the current analysis data (last 10 seconds by default)
92
- const analysisRef = useRef({ ...defaultAnalysis });
93
- // fullAnalysisRef is the full analysis data (all data points)
94
- const fullAnalysisRef = useRef({
95
- ...defaultAnalysis,
96
- });
97
- // Instantiate the module for web with URLs
98
- const ExpoAudioStream = Platform.OS === 'web'
99
- ? ExpoAudioStreamModule({
100
- audioWorkletUrl,
101
- featuresExtratorUrl,
102
- logger,
103
- })
104
- : ExpoAudioStreamModule;
105
- const onAudioStreamRef = useRef(null);
106
- const stateRef = useRef({
107
- isRecording: false,
108
- isPaused: false,
109
- durationMs: 0,
110
- size: 0,
111
- compression: undefined,
112
- });
113
- const recordingConfigRef = useRef(null);
114
- const handleAudioAnalysis = useCallback(async ({ analysis, visualizationDuration, }) => {
115
- const savedAnalysisData = analysisRef.current || {
116
- ...defaultAnalysis,
117
- };
118
- const maxDuration = visualizationDuration;
119
- logger?.debug(`[handleAudioAnalysis] Received audio analysis: maxDuration=${maxDuration} analysis.dataPoints=${analysis.dataPoints.length} analysisData.dataPoints=${savedAnalysisData.dataPoints.length}`, analysis);
120
- // Combine data points
121
- const combinedDataPoints = [
122
- ...savedAnalysisData.dataPoints,
123
- ...analysis.dataPoints,
124
- ];
125
- const fullCombinedDataPoints = [
126
- ...(fullAnalysisRef.current?.dataPoints ?? []),
127
- ...analysis.dataPoints,
128
- ];
129
- // Calculate the new duration
130
- // The number of segments is based on how many segments of segmentDurationMs can fit in visualizationDuration
131
- const numberOfSegments = Math.ceil(visualizationDuration / analysis.segmentDurationMs);
132
- // maxDataPoints should be the number of data points, not milliseconds
133
- const maxDataPoints = numberOfSegments;
134
- logger?.debug(`[handleAudioAnalysis] Combined data points before trimming: numberOfSegments=${numberOfSegments} visualizationDuration=${visualizationDuration} combinedDataPointsLength=${combinedDataPoints.length} vs maxDataPoints=${maxDataPoints}`);
135
- // Trim data points to keep within the maximum number of data points
136
- if (combinedDataPoints.length > maxDataPoints) {
137
- combinedDataPoints.splice(0, combinedDataPoints.length - maxDataPoints);
138
- }
139
- // Keep the full data points
140
- fullAnalysisRef.current = {
141
- ...fullAnalysisRef.current,
142
- dataPoints: fullCombinedDataPoints,
143
- };
144
- fullAnalysisRef.current.durationMs =
145
- fullCombinedDataPoints.length * analysis.segmentDurationMs;
146
- savedAnalysisData.dataPoints = combinedDataPoints;
147
- savedAnalysisData.bitDepth =
148
- analysis.bitDepth || savedAnalysisData.bitDepth;
149
- savedAnalysisData.durationMs =
150
- combinedDataPoints.length * analysis.segmentDurationMs;
151
- // Update amplitude range
152
- const newMin = Math.min(savedAnalysisData.amplitudeRange.min, analysis.amplitudeRange.min);
153
- const newMax = Math.max(savedAnalysisData.amplitudeRange.max, analysis.amplitudeRange.max);
154
- savedAnalysisData.amplitudeRange = {
155
- min: newMin,
156
- max: newMax,
157
- };
158
- fullAnalysisRef.current.amplitudeRange = {
159
- min: newMin,
160
- max: newMax,
161
- };
162
- logger?.debug(`[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`, savedAnalysisData);
163
- // Call the onAudioAnalysis callback if it exists in the recording config
164
- if (recordingConfigRef.current?.onAudioAnalysis) {
165
- recordingConfigRef.current
166
- .onAudioAnalysis(analysis)
167
- .catch((error) => {
168
- logger?.warn(`Error processing audio analysis:`, error);
169
- });
170
- }
171
- // Update the ref
172
- analysisRef.current = savedAnalysisData;
173
- // Dispatch the updated analysis data to state to trigger re-render
174
- dispatch({
175
- type: 'UPDATE_ANALYSIS',
176
- payload: { ...savedAnalysisData },
177
- });
178
- }, [dispatch]);
179
- const handleAudioEvent = useCallback(async (eventData) => {
180
- const { fileUri, deltaSize, totalSize, lastEmittedSize, position, streamUuid, encoded, mimeType, buffer, compression, } = eventData;
181
- logger?.debug(`[handleAudioEvent] Received audio event:`, {
182
- fileUri,
183
- deltaSize,
184
- totalSize,
185
- position,
186
- mimeType,
187
- lastEmittedSize,
188
- streamUuid,
189
- encodedLength: encoded?.length,
190
- compression,
191
- });
192
- if (deltaSize === 0) {
193
- // Ignore packet with no data
194
- return;
195
- }
196
- try {
197
- // Coming from native ( ios / android ) otherwise buffer is set
198
- if (Platform.OS !== 'web') {
199
- // Read the audio file as a base64 string for comparison
200
- if (!encoded) {
201
- logger?.error(`Encoded audio data is missing`);
202
- throw new Error('Encoded audio data is missing');
203
- }
204
- onAudioStreamRef.current?.({
205
- data: encoded,
206
- position,
207
- fileUri,
208
- eventDataSize: deltaSize,
209
- totalSize,
210
- compression: compression && startResultRef.current?.compression
211
- ? {
212
- data: compression.data,
213
- size: compression.totalSize,
214
- mimeType: startResultRef.current.compression
215
- ?.mimeType,
216
- bitrate: startResultRef.current.compression
217
- ?.bitrate,
218
- format: startResultRef.current.compression
219
- ?.format,
220
- }
221
- : undefined,
222
- });
223
- }
224
- else if (buffer) {
225
- // Coming from web
226
- const webEvent = {
227
- data: buffer,
228
- position,
229
- fileUri,
230
- eventDataSize: deltaSize,
231
- totalSize,
232
- compression: compression && startResultRef.current?.compression
233
- ? {
234
- data: compression.data,
235
- size: compression.totalSize,
236
- mimeType: startResultRef.current.compression
237
- ?.mimeType,
238
- bitrate: startResultRef.current.compression
239
- ?.bitrate,
240
- format: startResultRef.current.compression
241
- ?.format,
242
- }
243
- : undefined,
244
- };
245
- onAudioStreamRef.current?.(webEvent);
246
- logger?.debug(`[handleAudioEvent] Audio data sent to onAudioStream`, webEvent);
247
- }
248
- }
249
- catch (error) {
250
- logger?.error(`Error processing audio event:`, error);
251
- }
252
- }, []);
253
- const checkStatus = useCallback(async () => {
254
- try {
255
- const status = ExpoAudioStream.status();
256
- logger?.debug(`Status: paused: ${status.isPaused} isRecording: ${status.isRecording} durationMs: ${status.durationMs} size: ${status.size}`, status.compression);
257
- // Only dispatch if values actually changed
258
- if (status.isRecording !== stateRef.current.isRecording ||
259
- status.isPaused !== stateRef.current.isPaused) {
260
- stateRef.current.isRecording = status.isRecording;
261
- stateRef.current.isPaused = status.isPaused;
262
- dispatch({
263
- type: 'UPDATE_RECORDING_STATE',
264
- payload: {
265
- isRecording: status.isRecording,
266
- isPaused: status.isPaused,
267
- },
268
- });
269
- }
270
- if (status.durationMs !== stateRef.current.durationMs ||
271
- status.size !== stateRef.current.size) {
272
- stateRef.current.durationMs = status.durationMs;
273
- stateRef.current.size = status.size;
274
- stateRef.current.compression = status.compression;
275
- dispatch({
276
- type: 'UPDATE_STATUS',
277
- payload: {
278
- durationMs: status.durationMs,
279
- size: status.size,
280
- compression: status.compression,
281
- },
282
- });
283
- }
284
- }
285
- catch (error) {
286
- logger?.error(`Error getting status:`, error);
287
- }
288
- }, [ExpoAudioStream, logger]); // Only depend on ExpoAudioStream and logger
289
- // Update ref when state changes
290
- useEffect(() => {
291
- stateRef.current = {
292
- isRecording: state.isRecording,
293
- isPaused: state.isPaused,
294
- durationMs: state.durationMs,
295
- size: state.size,
296
- compression: state.compression,
297
- };
298
- }, [
299
- state.isRecording,
300
- state.isPaused,
301
- state.durationMs,
302
- state.size,
303
- state.compression,
304
- ]);
305
- const startRecording = useCallback(async (recordingOptions) => {
306
- recordingConfigRef.current = recordingOptions;
307
- logger?.debug(`start recoding`, recordingOptions);
308
- analysisRef.current = { ...defaultAnalysis }; // Reset analysis data
309
- fullAnalysisRef.current = { ...defaultAnalysis };
310
- const { onAudioStream, ...options } = recordingOptions;
311
- const { enableProcessing } = options;
312
- const maxRecentDataDuration = 10000; // TODO compute maxRecentDataDuration based on screen dimensions
313
- if (typeof onAudioStream === 'function') {
314
- onAudioStreamRef.current = onAudioStream;
315
- }
316
- else {
317
- logger?.warn(`onAudioStream is not a function`, onAudioStream);
318
- onAudioStreamRef.current = null;
319
- }
320
- const startResult = await ExpoAudioStream.startRecording(options);
321
- dispatch({ type: 'START' });
322
- startResultRef.current = startResult;
323
- if (enableProcessing) {
324
- logger?.debug(`Enabling audio analysis listener`);
325
- const listener = addAudioAnalysisListener(async (analysisData) => {
326
- try {
327
- await handleAudioAnalysis({
328
- analysis: analysisData,
329
- visualizationDuration: maxRecentDataDuration,
330
- });
331
- }
332
- catch (error) {
333
- logger?.warn(`Error processing audio analysis:`, error);
334
- }
335
- });
336
- analysisListenerRef.current = listener;
337
- }
338
- return startResult;
339
- }, [handleAudioAnalysis, dispatch]);
340
- const stopRecording = useCallback(async () => {
341
- logger?.debug(`stoping recording`);
342
- const stopResult = await ExpoAudioStream.stopRecording();
343
- stopResult.analysisData = fullAnalysisRef.current;
344
- if (analysisListenerRef.current) {
345
- analysisListenerRef.current.remove();
346
- analysisListenerRef.current = null;
347
- }
348
- onAudioStreamRef.current = null;
349
- logger?.debug(`recording stopped`, stopResult);
350
- dispatch({ type: 'STOP' });
351
- return stopResult;
352
- }, [dispatch]);
353
- const pauseRecording = useCallback(async () => {
354
- logger?.debug(`pause recording`);
355
- const pauseResult = await ExpoAudioStream.pauseRecording();
356
- dispatch({ type: 'PAUSE' });
357
- return pauseResult;
358
- }, [dispatch]);
359
- const resumeRecording = useCallback(async () => {
360
- logger?.debug(`resume recording`);
361
- const resumeResult = await ExpoAudioStream.resumeRecording();
362
- dispatch({ type: 'RESUME' });
363
- return resumeResult;
364
- }, [dispatch]);
365
- useEffect(() => {
366
- let intervalId;
367
- if (state.isRecording || state.isPaused) {
368
- // Immediately check status when starting
369
- checkStatus();
370
- // Start interval
371
- intervalId = setInterval(checkStatus, 1000);
372
- }
373
- return () => {
374
- if (intervalId) {
375
- clearInterval(intervalId);
376
- intervalId = undefined;
377
- }
378
- };
379
- }, [checkStatus, state.isRecording, state.isPaused]);
380
- useEffect(() => {
381
- logger?.debug(`Registering audio event listener`);
382
- const subscribeAudio = addAudioEventListener(handleAudioEvent);
383
- logger?.debug(`Subscribed to audio event listener and analysis listener`, {
384
- subscribeAudio,
385
- });
386
- return () => {
387
- logger?.debug(`Removing audio event listener`);
388
- subscribeAudio.remove();
389
- };
390
- }, [handleAudioEvent, handleAudioAnalysis]);
391
- useEffect(() => {
392
- // Add event subscription for recording interruptions
393
- logger?.debug('Setting up recording interruption listener');
394
- const subscription = addRecordingInterruptionListener((event) => {
395
- logger?.debug('Received recording interruption event:', event);
396
- // Check if we have a callback configured
397
- if (recordingConfigRef.current?.onRecordingInterrupted) {
398
- try {
399
- recordingConfigRef.current.onRecordingInterrupted(event);
400
- }
401
- catch (error) {
402
- logger?.error('Error in recording interruption callback:', error);
403
- }
404
- }
405
- else {
406
- logger?.warn('No recording interruption callback configured');
407
- }
408
- });
409
- return () => {
410
- logger?.debug('Removing recording interruption listener');
411
- subscription.remove();
412
- };
413
- }, []); // Empty dependency array since we want this to run once
414
- return {
415
- startRecording,
416
- stopRecording,
417
- pauseRecording,
418
- resumeRecording,
419
- isPaused: state.isPaused,
420
- isRecording: state.isRecording,
421
- durationMs: state.durationMs,
422
- size: state.size,
423
- compression: state.compression,
424
- analysisData: state.analysisData,
425
- };
426
- }
427
- //# sourceMappingURL=useAudioRecorder.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useAudioRecorder.js","sourceRoot":"","sources":["../src/useAudioRecorder.tsx"],"names":[],"mappings":"AAAA,0BAA0B;AAC1B,OAAO,EAAqB,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AAC/D,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,OAAO,CAAA;AAYlE,OAAO,qBAAqB,MAAM,yBAAyB,CAAA;AAC3D,OAAO,EACH,wBAAwB,EACxB,qBAAqB,EAErB,gCAAgC,GACnC,MAAM,UAAU,CAAA;AAiDjB,MAAM,eAAe,GAAkB;IAC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E,KAAK,CAAC,CAAA;YAE9D,yCAAyC;YACzC,IAAI,kBAAkB,CAAC,OAAO,EAAE,sBAAsB,EAAE,CAAC;gBACrD,IAAI,CAAC;oBACD,kBAAkB,CAAC,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;gBAC5D,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,MAAM,EAAE,KAAK,CACT,2CAA2C,EAC3C,KAAK,CACR,CAAA;gBACL,CAAC;YACL,CAAC;iBAAM,CAAC;gBACJ,MAAM,EAAE,IAAI,CAAC,+CAA+C,CAAC,CAAA;YACjE,CAAC;QACL,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,EAAE;YACR,MAAM,EAAE,KAAK,CAAC,0CAA0C,CAAC,CAAA;YACzD,YAAY,CAAC,MAAM,EAAE,CAAA;QACzB,CAAC,CAAA;IACL,CAAC,EAAE,EAAE,CAAC,CAAA,CAAC,wDAAwD;IAE/D,OAAO;QACH,cAAc;QACd,aAAa;QACb,cAAc;QACd,eAAe;QACf,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,YAAY,EAAE,KAAK,CAAC,YAAY;KACnC,CAAA;AACL,CAAC","sourcesContent":["// src/useAudioRecorder.ts\nimport { EventSubscription, Platform } from 'expo-modules-core'\nimport { useCallback, useEffect, useReducer, useRef } from 'react'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioDataEvent,\n AudioRecording,\n AudioStreamStatus,\n CompressionInfo,\n ConsoleLike,\n RecordingConfig,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport ExpoAudioStreamModule from './ExpoAudioStreamModule'\nimport {\n addAudioAnalysisListener,\n addAudioEventListener,\n AudioEventPayload,\n addRecordingInterruptionListener,\n} from './events'\n\nexport interface UseAudioRecorderProps {\n logger?: ConsoleLike\n audioWorkletUrl?: string\n featuresExtratorUrl?: string\n}\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n stopRecording: () => Promise<AudioRecording>\n pauseRecording: () => Promise<void>\n resumeRecording: () => Promise<void>\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ninterface RecorderReducerState {\n isRecording: boolean\n isPaused: boolean\n durationMs: number\n size: number\n compression?: CompressionInfo\n analysisData?: AudioAnalysis\n}\n\ntype RecorderAction =\n | { type: 'START' | 'STOP' | 'PAUSE' | 'RESUME' }\n | {\n type: 'UPDATE_RECORDING_STATE'\n payload: {\n isRecording: boolean\n isPaused: boolean\n }\n }\n | {\n type: 'UPDATE_STATUS'\n payload: {\n durationMs: number\n size: number\n compression?: CompressionInfo\n }\n }\n | { type: 'UPDATE_ANALYSIS'; payload: AudioAnalysis }\n\nconst defaultAnalysis: AudioAnalysis = {\n segmentDurationMs: 100,\n bitDepth: 32,\n numberOfChannels: 1,\n durationMs: 0,\n sampleRate: 44100,\n samples: 0,\n dataPoints: [],\n rmsRange: {\n min: Number.POSITIVE_INFINITY,\n max: Number.NEGATIVE_INFINITY,\n },\n amplitudeRange: {\n min: Number.POSITIVE_INFINITY,\n max: Number.NEGATIVE_INFINITY,\n },\n}\n\nfunction audioRecorderReducer(\n state: RecorderReducerState,\n action: RecorderAction\n): RecorderReducerState {\n switch (action.type) {\n case 'START':\n return {\n ...state,\n isRecording: true,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: defaultAnalysis,\n }\n case 'STOP':\n return {\n ...state,\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n }\n case 'PAUSE':\n return { ...state, isPaused: true, isRecording: false }\n case 'RESUME':\n return { ...state, isPaused: false, isRecording: true }\n case 'UPDATE_RECORDING_STATE':\n return {\n ...state,\n isPaused: action.payload.isPaused,\n isRecording: action.payload.isRecording,\n }\n case 'UPDATE_STATUS': {\n const newState = {\n ...state,\n durationMs: action.payload.durationMs,\n size: action.payload.size,\n compression: action.payload.compression\n ? {\n size: action.payload.compression.size,\n mimeType: action.payload.compression.mimeType,\n bitrate: action.payload.compression.bitrate,\n format: action.payload.compression.format,\n }\n : undefined,\n }\n return newState\n }\n case 'UPDATE_ANALYSIS':\n return {\n ...state,\n analysisData: action.payload,\n }\n default:\n return state\n }\n}\n\ninterface HandleAudioAnalysisProps {\n analysis: AudioAnalysis\n visualizationDuration: number\n}\n\nexport function useAudioRecorder({\n logger,\n audioWorkletUrl,\n featuresExtratorUrl,\n}: UseAudioRecorderProps = {}): UseAudioRecorderState {\n const [state, dispatch] = useReducer(audioRecorderReducer, {\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined,\n analysisData: undefined,\n })\n\n const startResultRef = useRef<StartRecordingResult | null>(null)\n\n const analysisListenerRef = useRef<EventSubscription | null>(null)\n // analysisRef is the current analysis data (last 10 seconds by default)\n const analysisRef = useRef<AudioAnalysis>({ ...defaultAnalysis })\n // fullAnalysisRef is the full analysis data (all data points)\n const fullAnalysisRef = useRef<AudioAnalysis>({\n ...defaultAnalysis,\n })\n\n // Instantiate the module for web with URLs\n const ExpoAudioStream =\n Platform.OS === 'web'\n ? ExpoAudioStreamModule({\n audioWorkletUrl,\n featuresExtratorUrl,\n logger,\n })\n : ExpoAudioStreamModule\n\n const onAudioStreamRef = useRef<\n ((_: AudioDataEvent) => Promise<void>) | null\n >(null)\n\n const stateRef = useRef({\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n compression: undefined as CompressionInfo | undefined,\n })\n\n const recordingConfigRef = useRef<RecordingConfig | null>(null)\n\n const handleAudioAnalysis = useCallback(\n async ({\n analysis,\n visualizationDuration,\n }: HandleAudioAnalysisProps) => {\n const savedAnalysisData = analysisRef.current || {\n ...defaultAnalysis,\n }\n\n const maxDuration = visualizationDuration\n\n logger?.debug(\n `[handleAudioAnalysis] Received audio analysis: maxDuration=${maxDuration} analysis.dataPoints=${analysis.dataPoints.length} analysisData.dataPoints=${savedAnalysisData.dataPoints.length}`,\n analysis\n )\n\n // Combine data points\n const combinedDataPoints = [\n ...savedAnalysisData.dataPoints,\n ...analysis.dataPoints,\n ]\n\n const fullCombinedDataPoints = [\n ...(fullAnalysisRef.current?.dataPoints ?? []),\n ...analysis.dataPoints,\n ]\n\n // Calculate the new duration\n // The number of segments is based on how many segments of segmentDurationMs can fit in visualizationDuration\n const numberOfSegments = Math.ceil(\n visualizationDuration / analysis.segmentDurationMs\n )\n // maxDataPoints should be the number of data points, not milliseconds\n const maxDataPoints = numberOfSegments\n\n logger?.debug(\n `[handleAudioAnalysis] Combined data points before trimming: numberOfSegments=${numberOfSegments} visualizationDuration=${visualizationDuration} combinedDataPointsLength=${combinedDataPoints.length} vs maxDataPoints=${maxDataPoints}`\n )\n\n // Trim data points to keep within the maximum number of data points\n if (combinedDataPoints.length > maxDataPoints) {\n combinedDataPoints.splice(\n 0,\n combinedDataPoints.length - maxDataPoints\n )\n }\n\n // Keep the full data points\n fullAnalysisRef.current = {\n ...fullAnalysisRef.current,\n dataPoints: fullCombinedDataPoints,\n }\n fullAnalysisRef.current.durationMs =\n fullCombinedDataPoints.length * analysis.segmentDurationMs\n savedAnalysisData.dataPoints = combinedDataPoints\n savedAnalysisData.bitDepth =\n analysis.bitDepth || savedAnalysisData.bitDepth\n savedAnalysisData.durationMs =\n combinedDataPoints.length * analysis.segmentDurationMs\n\n // Update amplitude range\n const newMin = Math.min(\n savedAnalysisData.amplitudeRange.min,\n analysis.amplitudeRange.min\n )\n const newMax = Math.max(\n savedAnalysisData.amplitudeRange.max,\n analysis.amplitudeRange.max\n )\n\n savedAnalysisData.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n fullAnalysisRef.current.amplitudeRange = {\n min: newMin,\n max: newMax,\n }\n\n logger?.debug(\n `[handleAudioAnalysis] Updated analysis data: durationMs=${savedAnalysisData.durationMs}`,\n savedAnalysisData\n )\n\n // Call the onAudioAnalysis callback if it exists in the recording config\n if (recordingConfigRef.current?.onAudioAnalysis) {\n recordingConfigRef.current\n .onAudioAnalysis(analysis)\n .catch((error) => {\n logger?.warn(`Error processing audio analysis:`, error)\n })\n }\n\n // Update the ref\n analysisRef.current = savedAnalysisData\n\n // Dispatch the updated analysis data to state to trigger re-render\n dispatch({\n type: 'UPDATE_ANALYSIS',\n payload: { ...savedAnalysisData },\n })\n },\n [dispatch]\n )\n\n const handleAudioEvent = useCallback(\n async (eventData: AudioEventPayload) => {\n const {\n fileUri,\n deltaSize,\n totalSize,\n lastEmittedSize,\n position,\n streamUuid,\n encoded,\n mimeType,\n buffer,\n compression,\n } = eventData\n logger?.debug(`[handleAudioEvent] Received audio event:`, {\n fileUri,\n deltaSize,\n totalSize,\n position,\n mimeType,\n lastEmittedSize,\n streamUuid,\n encodedLength: encoded?.length,\n compression,\n })\n if (deltaSize === 0) {\n // Ignore packet with no data\n return\n }\n try {\n // Coming from native ( ios / android ) otherwise buffer is set\n if (Platform.OS !== 'web') {\n // Read the audio file as a base64 string for comparison\n if (!encoded) {\n logger?.error(`Encoded audio data is missing`)\n throw new Error('Encoded audio data is missing')\n }\n onAudioStreamRef.current?.({\n data: encoded,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n })\n } else if (buffer) {\n // Coming from web\n const webEvent: AudioDataEvent = {\n data: buffer,\n position,\n fileUri,\n eventDataSize: deltaSize,\n totalSize,\n compression:\n compression && startResultRef.current?.compression\n ? {\n data: compression.data,\n size: compression.totalSize,\n mimeType:\n startResultRef.current.compression\n ?.mimeType,\n bitrate:\n startResultRef.current.compression\n ?.bitrate,\n format: startResultRef.current.compression\n ?.format,\n }\n : undefined,\n }\n onAudioStreamRef.current?.(webEvent)\n logger?.debug(\n `[handleAudioEvent] Audio data sent to onAudioStream`,\n webEvent\n )\n }\n } catch (error) {\n logger?.error(`Error processing audio event:`, error)\n }\n },\n []\n )\n\n const checkStatus = useCallback(async () => {\n try {\n const status: AudioStreamStatus = ExpoAudioStream.status()\n logger?.debug(\n `Status: paused: ${status.isPaused} isRecording: ${status.isRecording} durationMs: ${status.durationMs} size: ${status.size}`,\n status.compression\n )\n\n // Only dispatch if values actually changed\n if (\n status.isRecording !== stateRef.current.isRecording ||\n status.isPaused !== stateRef.current.isPaused\n ) {\n stateRef.current.isRecording = status.isRecording\n stateRef.current.isPaused = status.isPaused\n dispatch({\n type: 'UPDATE_RECORDING_STATE',\n payload: {\n isRecording: status.isRecording,\n isPaused: status.isPaused,\n },\n })\n }\n\n if (\n status.durationMs !== stateRef.current.durationMs ||\n status.size !== stateRef.current.size\n ) {\n stateRef.current.durationMs = status.durationMs\n stateRef.current.size = status.size\n stateRef.current.compression = status.compression\n dispatch({\n type: 'UPDATE_STATUS',\n payload: {\n durationMs: status.durationMs,\n size: status.size,\n compression: status.compression,\n },\n })\n }\n } catch (error) {\n logger?.error(`Error getting status:`, error)\n }\n }, [ExpoAudioStream, logger]) // Only depend on ExpoAudioStream and logger\n\n // Update ref when state changes\n useEffect(() => {\n stateRef.current = {\n isRecording: state.isRecording,\n isPaused: state.isPaused,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n }\n }, [\n state.isRecording,\n state.isPaused,\n state.durationMs,\n state.size,\n state.compression,\n ])\n\n const startRecording = useCallback(\n async (recordingOptions: RecordingConfig) => {\n recordingConfigRef.current = recordingOptions\n logger?.debug(`start recoding`, recordingOptions)\n\n analysisRef.current = { ...defaultAnalysis } // Reset analysis data\n fullAnalysisRef.current = { ...defaultAnalysis }\n const { onAudioStream, ...options } = recordingOptions\n const { enableProcessing } = options\n\n const maxRecentDataDuration = 10000 // TODO compute maxRecentDataDuration based on screen dimensions\n if (typeof onAudioStream === 'function') {\n onAudioStreamRef.current = onAudioStream\n } else {\n logger?.warn(`onAudioStream is not a function`, onAudioStream)\n onAudioStreamRef.current = null\n }\n const startResult: StartRecordingResult =\n await ExpoAudioStream.startRecording(options)\n dispatch({ type: 'START' })\n\n startResultRef.current = startResult\n\n if (enableProcessing) {\n logger?.debug(`Enabling audio analysis listener`)\n const listener = addAudioAnalysisListener(\n async (analysisData) => {\n try {\n await handleAudioAnalysis({\n analysis: analysisData,\n visualizationDuration: maxRecentDataDuration,\n })\n } catch (error) {\n logger?.warn(\n `Error processing audio analysis:`,\n error\n )\n }\n }\n )\n\n analysisListenerRef.current = listener\n }\n\n return startResult\n },\n [handleAudioAnalysis, dispatch]\n )\n\n const stopRecording = useCallback(async () => {\n logger?.debug(`stoping recording`)\n\n const stopResult: AudioRecording = await ExpoAudioStream.stopRecording()\n stopResult.analysisData = fullAnalysisRef.current\n\n if (analysisListenerRef.current) {\n analysisListenerRef.current.remove()\n analysisListenerRef.current = null\n }\n onAudioStreamRef.current = null\n logger?.debug(`recording stopped`, stopResult)\n dispatch({ type: 'STOP' })\n return stopResult\n }, [dispatch])\n\n const pauseRecording = useCallback(async () => {\n logger?.debug(`pause recording`)\n const pauseResult = await ExpoAudioStream.pauseRecording()\n dispatch({ type: 'PAUSE' })\n return pauseResult\n }, [dispatch])\n\n const resumeRecording = useCallback(async () => {\n logger?.debug(`resume recording`)\n const resumeResult = await ExpoAudioStream.resumeRecording()\n dispatch({ type: 'RESUME' })\n return resumeResult\n }, [dispatch])\n\n useEffect(() => {\n let intervalId: NodeJS.Timeout | undefined\n\n if (state.isRecording || state.isPaused) {\n // Immediately check status when starting\n checkStatus()\n\n // Start interval\n intervalId = setInterval(checkStatus, 1000)\n }\n\n return () => {\n if (intervalId) {\n clearInterval(intervalId)\n intervalId = undefined\n }\n }\n }, [checkStatus, state.isRecording, state.isPaused])\n\n useEffect(() => {\n logger?.debug(`Registering audio event listener`)\n const subscribeAudio = addAudioEventListener(handleAudioEvent)\n\n logger?.debug(\n `Subscribed to audio event listener and analysis listener`,\n {\n subscribeAudio,\n }\n )\n\n return () => {\n logger?.debug(`Removing audio event listener`)\n subscribeAudio.remove()\n }\n }, [handleAudioEvent, handleAudioAnalysis])\n\n useEffect(() => {\n // Add event subscription for recording interruptions\n logger?.debug('Setting up recording interruption listener')\n\n const subscription = addRecordingInterruptionListener((event) => {\n logger?.debug('Received recording interruption event:', event)\n\n // Check if we have a callback configured\n if (recordingConfigRef.current?.onRecordingInterrupted) {\n try {\n recordingConfigRef.current.onRecordingInterrupted(event)\n } catch (error) {\n logger?.error(\n 'Error in recording interruption callback:',\n error\n )\n }\n } else {\n logger?.warn('No recording interruption callback configured')\n }\n })\n\n return () => {\n logger?.debug('Removing recording interruption listener')\n subscription.remove()\n }\n }, []) // Empty dependency array since we want this to run once\n\n return {\n startRecording,\n stopRecording,\n pauseRecording,\n resumeRecording,\n isPaused: state.isPaused,\n isRecording: state.isRecording,\n durationMs: state.durationMs,\n size: state.size,\n compression: state.compression,\n analysisData: state.analysisData,\n }\n}\n"]}
@@ -1,9 +0,0 @@
1
- /**
2
- * Fixes duration on MediaRecorder output.
3
- * @param blob Input Blob with incorrect duration.
4
- * @param duration Correct duration (in milliseconds).
5
- * @param type Output blob mimetype (default: video/webm).
6
- * @returns
7
- */
8
- export declare const webmFixDuration: (blob: Blob, duration: number, type?: string) => Promise<Blob>;
9
- //# sourceMappingURL=BlobFix.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"BlobFix.d.ts","sourceRoot":"","sources":["../../src/utils/BlobFix.ts"],"names":[],"mappings":"AAugBA;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,SAClB,IAAI,YACA,MAAM,oBAEjB,QAAQ,IAAI,CA4Bd,CAAA"}