@siteed/expo-audio-studio 2.1.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 (188) hide show
  1. package/CHANGELOG.md +210 -0
  2. package/LICENSE +21 -0
  3. package/README.md +269 -0
  4. package/android/build.gradle +105 -0
  5. package/android/src/main/AndroidManifest.xml +27 -0
  6. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +166 -0
  7. package/android/src/main/java/net/siteed/audiostream/AudioDataEncoder.kt +9 -0
  8. package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +131 -0
  9. package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +103 -0
  10. package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +435 -0
  11. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +2235 -0
  12. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1437 -0
  13. package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +166 -0
  14. package/android/src/main/java/net/siteed/audiostream/AudioTrimmer.kt +1099 -0
  15. package/android/src/main/java/net/siteed/audiostream/Constants.kt +21 -0
  16. package/android/src/main/java/net/siteed/audiostream/EventSender.kt +7 -0
  17. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +739 -0
  18. package/android/src/main/java/net/siteed/audiostream/FFT.kt +99 -0
  19. package/android/src/main/java/net/siteed/audiostream/Features.kt +98 -0
  20. package/android/src/main/java/net/siteed/audiostream/NotificationConfig.kt +70 -0
  21. package/android/src/main/java/net/siteed/audiostream/PermissionUtils.kt +59 -0
  22. package/android/src/main/java/net/siteed/audiostream/RecordingActionReceiver.kt +59 -0
  23. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +205 -0
  24. package/android/src/main/java/net/siteed/audiostream/WaveformConfig.kt +19 -0
  25. package/android/src/main/java/net/siteed/audiostream/WaveformRenderer.kt +159 -0
  26. package/android/src/main/res/drawable/ic_default_action_icon.xml +16 -0
  27. package/android/src/main/res/drawable/ic_microphone.xml +13 -0
  28. package/android/src/main/res/drawable/ic_pause.xml +10 -0
  29. package/android/src/main/res/drawable/ic_play.xml +10 -0
  30. package/android/src/main/res/drawable/ic_stop.xml +10 -0
  31. package/android/src/main/res/layout/notification_recording.xml +37 -0
  32. package/android/src/main/test/java/net/siteed/audiostream/AudioProcessorTest.kt +56 -0
  33. package/app.plugin.js +1 -0
  34. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +179 -0
  35. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
  36. package/build/AudioAnalysis/AudioAnalysis.types.js +3 -0
  37. package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  38. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +68 -0
  39. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
  40. package/build/AudioAnalysis/extractAudioAnalysis.js +203 -0
  41. package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  42. package/build/AudioAnalysis/extractAudioData.d.ts +3 -0
  43. package/build/AudioAnalysis/extractAudioData.d.ts.map +1 -0
  44. package/build/AudioAnalysis/extractAudioData.js +5 -0
  45. package/build/AudioAnalysis/extractAudioData.js.map +1 -0
  46. package/build/AudioAnalysis/extractMelSpectrogram.d.ts +14 -0
  47. package/build/AudioAnalysis/extractMelSpectrogram.d.ts.map +1 -0
  48. package/build/AudioAnalysis/extractMelSpectrogram.js +85 -0
  49. package/build/AudioAnalysis/extractMelSpectrogram.js.map +1 -0
  50. package/build/AudioAnalysis/extractPreview.d.ts +11 -0
  51. package/build/AudioAnalysis/extractPreview.d.ts.map +1 -0
  52. package/build/AudioAnalysis/extractPreview.js +25 -0
  53. package/build/AudioAnalysis/extractPreview.js.map +1 -0
  54. package/build/AudioAnalysis/extractWaveform.d.ts +8 -0
  55. package/build/AudioAnalysis/extractWaveform.d.ts.map +1 -0
  56. package/build/AudioAnalysis/extractWaveform.js +11 -0
  57. package/build/AudioAnalysis/extractWaveform.js.map +1 -0
  58. package/build/AudioRecorder.provider.d.ts +11 -0
  59. package/build/AudioRecorder.provider.d.ts.map +1 -0
  60. package/build/AudioRecorder.provider.js +37 -0
  61. package/build/AudioRecorder.provider.js.map +1 -0
  62. package/build/ExpoAudioStream.native.d.ts +3 -0
  63. package/build/ExpoAudioStream.native.d.ts.map +1 -0
  64. package/build/ExpoAudioStream.native.js +6 -0
  65. package/build/ExpoAudioStream.native.js.map +1 -0
  66. package/build/ExpoAudioStream.types.d.ts +532 -0
  67. package/build/ExpoAudioStream.types.d.ts.map +1 -0
  68. package/build/ExpoAudioStream.types.js +2 -0
  69. package/build/ExpoAudioStream.types.js.map +1 -0
  70. package/build/ExpoAudioStream.web.d.ts +59 -0
  71. package/build/ExpoAudioStream.web.d.ts.map +1 -0
  72. package/build/ExpoAudioStream.web.js +285 -0
  73. package/build/ExpoAudioStream.web.js.map +1 -0
  74. package/build/ExpoAudioStreamModule.d.ts +3 -0
  75. package/build/ExpoAudioStreamModule.d.ts.map +1 -0
  76. package/build/ExpoAudioStreamModule.js +693 -0
  77. package/build/ExpoAudioStreamModule.js.map +1 -0
  78. package/build/WebRecorder.web.d.ts +119 -0
  79. package/build/WebRecorder.web.d.ts.map +1 -0
  80. package/build/WebRecorder.web.js +436 -0
  81. package/build/WebRecorder.web.js.map +1 -0
  82. package/build/constants.d.ts +11 -0
  83. package/build/constants.d.ts.map +1 -0
  84. package/build/constants.js +14 -0
  85. package/build/constants.js.map +1 -0
  86. package/build/events.d.ts +26 -0
  87. package/build/events.d.ts.map +1 -0
  88. package/build/events.js +21 -0
  89. package/build/events.js.map +1 -0
  90. package/build/index.d.ts +15 -0
  91. package/build/index.d.ts.map +1 -0
  92. package/build/index.js +14 -0
  93. package/build/index.js.map +1 -0
  94. package/build/trimAudio.d.ts +25 -0
  95. package/build/trimAudio.d.ts.map +1 -0
  96. package/build/trimAudio.js +67 -0
  97. package/build/trimAudio.js.map +1 -0
  98. package/build/useAudioRecorder.d.ts +21 -0
  99. package/build/useAudioRecorder.d.ts.map +1 -0
  100. package/build/useAudioRecorder.js +427 -0
  101. package/build/useAudioRecorder.js.map +1 -0
  102. package/build/utils/BlobFix.d.ts +9 -0
  103. package/build/utils/BlobFix.d.ts.map +1 -0
  104. package/build/utils/BlobFix.js +498 -0
  105. package/build/utils/BlobFix.js.map +1 -0
  106. package/build/utils/audioProcessing.d.ts +24 -0
  107. package/build/utils/audioProcessing.d.ts.map +1 -0
  108. package/build/utils/audioProcessing.js +133 -0
  109. package/build/utils/audioProcessing.js.map +1 -0
  110. package/build/utils/concatenateBuffers.d.ts +8 -0
  111. package/build/utils/concatenateBuffers.d.ts.map +1 -0
  112. package/build/utils/concatenateBuffers.js +21 -0
  113. package/build/utils/concatenateBuffers.js.map +1 -0
  114. package/build/utils/convertPCMToFloat32.d.ts +13 -0
  115. package/build/utils/convertPCMToFloat32.d.ts.map +1 -0
  116. package/build/utils/convertPCMToFloat32.js +120 -0
  117. package/build/utils/convertPCMToFloat32.js.map +1 -0
  118. package/build/utils/encodingToBitDepth.d.ts +5 -0
  119. package/build/utils/encodingToBitDepth.d.ts.map +1 -0
  120. package/build/utils/encodingToBitDepth.js +13 -0
  121. package/build/utils/encodingToBitDepth.js.map +1 -0
  122. package/build/utils/getWavFileInfo.d.ts +26 -0
  123. package/build/utils/getWavFileInfo.d.ts.map +1 -0
  124. package/build/utils/getWavFileInfo.js +92 -0
  125. package/build/utils/getWavFileInfo.js.map +1 -0
  126. package/build/utils/writeWavHeader.d.ts +49 -0
  127. package/build/utils/writeWavHeader.d.ts.map +1 -0
  128. package/build/utils/writeWavHeader.js +91 -0
  129. package/build/utils/writeWavHeader.js.map +1 -0
  130. package/build/workers/InlineFeaturesExtractor.web.d.ts +2 -0
  131. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
  132. package/build/workers/InlineFeaturesExtractor.web.js +828 -0
  133. package/build/workers/InlineFeaturesExtractor.web.js.map +1 -0
  134. package/build/workers/inlineAudioWebWorker.web.d.ts +2 -0
  135. package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
  136. package/build/workers/inlineAudioWebWorker.web.js +157 -0
  137. package/build/workers/inlineAudioWebWorker.web.js.map +1 -0
  138. package/expo-module.config.json +9 -0
  139. package/ios/AudioAnalysisData.swift +74 -0
  140. package/ios/AudioNotificationManager.swift +135 -0
  141. package/ios/AudioProcessingHelpers.swift +743 -0
  142. package/ios/AudioProcessor.swift +1313 -0
  143. package/ios/AudioStreamError.swift +7 -0
  144. package/ios/AudioStreamManager.swift +1708 -0
  145. package/ios/AudioStreamManagerDelegate.swift +16 -0
  146. package/ios/DataPoint.swift +54 -0
  147. package/ios/DecodingConfig.swift +47 -0
  148. package/ios/ExpoAudioStream.podspec +27 -0
  149. package/ios/ExpoAudioStreamModule.swift +805 -0
  150. package/ios/FFT.swift +62 -0
  151. package/ios/Features.swift +95 -0
  152. package/ios/Logger.swift +7 -0
  153. package/ios/NotificationExtension.swift +15 -0
  154. package/ios/RecordingResult.swift +22 -0
  155. package/ios/RecordingSettings.swift +265 -0
  156. package/ios/WaveformExtractor.swift +105 -0
  157. package/package.json +128 -0
  158. package/plugin/build/index.d.ts +21 -0
  159. package/plugin/build/index.js +192 -0
  160. package/plugin/src/index.ts +279 -0
  161. package/plugin/tsconfig.json +10 -0
  162. package/plugin/tsconfig.tsbuildinfo +1 -0
  163. package/src/AudioAnalysis/AudioAnalysis.types.ts +202 -0
  164. package/src/AudioAnalysis/extractAudioAnalysis.ts +333 -0
  165. package/src/AudioAnalysis/extractAudioData.ts +6 -0
  166. package/src/AudioAnalysis/extractMelSpectrogram.ts +144 -0
  167. package/src/AudioAnalysis/extractPreview.ts +34 -0
  168. package/src/AudioAnalysis/extractWaveform.ts +22 -0
  169. package/src/AudioRecorder.provider.tsx +54 -0
  170. package/src/ExpoAudioStream.native.ts +6 -0
  171. package/src/ExpoAudioStream.types.ts +641 -0
  172. package/src/ExpoAudioStream.web.ts +359 -0
  173. package/src/ExpoAudioStreamModule.ts +967 -0
  174. package/src/WebRecorder.web.ts +580 -0
  175. package/src/constants.ts +18 -0
  176. package/src/events.ts +60 -0
  177. package/src/index.ts +36 -0
  178. package/src/trimAudio.ts +90 -0
  179. package/src/useAudioRecorder.tsx +620 -0
  180. package/src/utils/BlobFix.ts +559 -0
  181. package/src/utils/audioProcessing.ts +205 -0
  182. package/src/utils/concatenateBuffers.ts +24 -0
  183. package/src/utils/convertPCMToFloat32.ts +170 -0
  184. package/src/utils/encodingToBitDepth.ts +18 -0
  185. package/src/utils/getWavFileInfo.ts +132 -0
  186. package/src/utils/writeWavHeader.ts +114 -0
  187. package/src/workers/InlineFeaturesExtractor.web.tsx +827 -0
  188. package/src/workers/inlineAudioWebWorker.web.tsx +156 -0
@@ -0,0 +1 @@
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;IACnC,iBAAiB,EAAE,GAAG;IACtB,QAAQ,EAAE,EAAE;IACZ,gBAAgB,EAAE,CAAC;IACnB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,KAAK;IACjB,OAAO,EAAE,CAAC;IACV,UAAU,EAAE,EAAE;IACd,QAAQ,EAAE;QACN,GAAG,EAAE,MAAM,CAAC,iBAAiB;QAC7B,GAAG,EAAE,MAAM,CAAC,iBAAiB;KAChC;IACD,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAC,iBAAiB;QAC7B,GAAG,EA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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"]}
@@ -0,0 +1,9 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,498 @@
1
+ /*
2
+ * There is a bug where `navigator.mediaDevices.getUserMedia` + `MediaRecorder`
3
+ * creates WEBM files without duration metadata. See:
4
+ * - https://bugs.chromium.org/p/chromium/issues/detail?id=642012
5
+ * - https://stackoverflow.com/a/39971175/13989043
6
+ *
7
+ * This file contains a function that fixes the duration metadata of a WEBM file.
8
+ * - Answer found: https://stackoverflow.com/a/75218309/13989043
9
+ * - Code adapted from: https://github.com/mat-sz/webm-fix-duration
10
+ * (forked from https://github.com/yusitnikov/fix-webm-duration)
11
+ */
12
+ const sections = {
13
+ 0xa45dfa3: { name: 'EBML', type: 'Container' },
14
+ 0x286: { name: 'EBMLVersion', type: 'Uint' },
15
+ 0x2f7: { name: 'EBMLReadVersion', type: 'Uint' },
16
+ 0x2f2: { name: 'EBMLMaxIDLength', type: 'Uint' },
17
+ 0x2f3: { name: 'EBMLMaxSizeLength', type: 'Uint' },
18
+ 0x282: { name: 'DocType', type: 'String' },
19
+ 0x287: { name: 'DocTypeVersion', type: 'Uint' },
20
+ 0x285: { name: 'DocTypeReadVersion', type: 'Uint' },
21
+ 0x6c: { name: 'Void', type: 'Binary' },
22
+ 0x3f: { name: 'CRC-32', type: 'Binary' },
23
+ 0xb538667: { name: 'SignatureSlot', type: 'Container' },
24
+ 0x3e8a: { name: 'SignatureAlgo', type: 'Uint' },
25
+ 0x3e9a: { name: 'SignatureHash', type: 'Uint' },
26
+ 0x3ea5: { name: 'SignaturePublicKey', type: 'Binary' },
27
+ 0x3eb5: { name: 'Signature', type: 'Binary' },
28
+ 0x3e5b: { name: 'SignatureElements', type: 'Container' },
29
+ 0x3e7b: { name: 'SignatureElementList', type: 'Container' },
30
+ 0x2532: { name: 'SignedElement', type: 'Binary' },
31
+ 0x8538067: { name: 'Segment', type: 'Container' },
32
+ 0x14d9b74: { name: 'SeekHead', type: 'Container' },
33
+ 0xdbb: { name: 'Seek', type: 'Container' },
34
+ 0x13ab: { name: 'SeekID', type: 'Binary' },
35
+ 0x13ac: { name: 'SeekPosition', type: 'Uint' },
36
+ 0x549a966: { name: 'Info', type: 'Container' },
37
+ 0x33a4: { name: 'SegmentUID', type: 'Binary' },
38
+ 0x3384: { name: 'SegmentFilename', type: 'String' },
39
+ 0x1cb923: { name: 'PrevUID', type: 'Binary' },
40
+ 0x1c83ab: { name: 'PrevFilename', type: 'String' },
41
+ 0x1eb923: { name: 'NextUID', type: 'Binary' },
42
+ 0x1e83bb: { name: 'NextFilename', type: 'String' },
43
+ 0x444: { name: 'SegmentFamily', type: 'Binary' },
44
+ 0x2924: { name: 'ChapterTranslate', type: 'Container' },
45
+ 0x29fc: { name: 'ChapterTranslateEditionUID', type: 'Uint' },
46
+ 0x29bf: { name: 'ChapterTranslateCodec', type: 'Uint' },
47
+ 0x29a5: { name: 'ChapterTranslateID', type: 'Binary' },
48
+ 0xad7b1: { name: 'TimecodeScale', type: 'Uint' },
49
+ 0x489: { name: 'Duration', type: 'Float' },
50
+ 0x461: { name: 'DateUTC', type: 'Date' },
51
+ 0x3ba9: { name: 'Title', type: 'String' },
52
+ 0xd80: { name: 'MuxingApp', type: 'String' },
53
+ 0x1741: { name: 'WritingApp', type: 'String' },
54
+ // 0xf43b675: { name: 'Cluster', type: 'Container' },
55
+ 0x67: { name: 'Timecode', type: 'Uint' },
56
+ 0x1854: { name: 'SilentTracks', type: 'Container' },
57
+ 0x18d7: { name: 'SilentTrackNumber', type: 'Uint' },
58
+ 0x27: { name: 'Position', type: 'Uint' },
59
+ 0x2b: { name: 'PrevSize', type: 'Uint' },
60
+ 0x23: { name: 'SimpleBlock', type: 'Binary' },
61
+ 0x20: { name: 'BlockGroup', type: 'Container' },
62
+ 0x21: { name: 'Block', type: 'Binary' },
63
+ 0x22: { name: 'BlockVirtual', type: 'Binary' },
64
+ 0x35a1: { name: 'BlockAdditions', type: 'Container' },
65
+ 0x26: { name: 'BlockMore', type: 'Container' },
66
+ 0x6e: { name: 'BlockAddID', type: 'Uint' },
67
+ 0x25: { name: 'BlockAdditional', type: 'Binary' },
68
+ 0x1b: { name: 'BlockDuration', type: 'Uint' },
69
+ 0x7a: { name: 'ReferencePriority', type: 'Uint' },
70
+ 0x7b: { name: 'ReferenceBlock', type: 'Int' },
71
+ 0x7d: { name: 'ReferenceVirtual', type: 'Int' },
72
+ 0x24: { name: 'CodecState', type: 'Binary' },
73
+ 0x35a2: { name: 'DiscardPadding', type: 'Int' },
74
+ 0xe: { name: 'Slices', type: 'Container' },
75
+ 0x68: { name: 'TimeSlice', type: 'Container' },
76
+ 0x4c: { name: 'LaceNumber', type: 'Uint' },
77
+ 0x4d: { name: 'FrameNumber', type: 'Uint' },
78
+ 0x4b: { name: 'BlockAdditionID', type: 'Uint' },
79
+ 0x4e: { name: 'Delay', type: 'Uint' },
80
+ 0x4f: { name: 'SliceDuration', type: 'Uint' },
81
+ 0x48: { name: 'ReferenceFrame', type: 'Container' },
82
+ 0x49: { name: 'ReferenceOffset', type: 'Uint' },
83
+ 0x4a: { name: 'ReferenceTimeCode', type: 'Uint' },
84
+ 0x2f: { name: 'EncryptedBlock', type: 'Binary' },
85
+ 0x654ae6b: { name: 'Tracks', type: 'Container' },
86
+ 0x2e: { name: 'TrackEntry', type: 'Container' },
87
+ 0x57: { name: 'TrackNumber', type: 'Uint' },
88
+ 0x33c5: { name: 'TrackUID', type: 'Uint' },
89
+ 0x3: { name: 'TrackType', type: 'Uint' },
90
+ 0x39: { name: 'FlagEnabled', type: 'Uint' },
91
+ 0x8: { name: 'FlagDefault', type: 'Uint' },
92
+ 0x15aa: { name: 'FlagForced', type: 'Uint' },
93
+ 0x1c: { name: 'FlagLacing', type: 'Uint' },
94
+ 0x2de7: { name: 'MinCache', type: 'Uint' },
95
+ 0x2df8: { name: 'MaxCache', type: 'Uint' },
96
+ 0x3e383: { name: 'DefaultDuration', type: 'Uint' },
97
+ 0x34e7a: { name: 'DefaultDecodedFieldDuration', type: 'Uint' },
98
+ 0x3314f: { name: 'TrackTimecodeScale', type: 'Float' },
99
+ 0x137f: { name: 'TrackOffset', type: 'Int' },
100
+ 0x15ee: { name: 'MaxBlockAdditionID', type: 'Uint' },
101
+ 0x136e: { name: 'Name', type: 'String' },
102
+ 0x2b59c: { name: 'Language', type: 'String' },
103
+ 0x6: { name: 'CodecID', type: 'String' },
104
+ 0x23a2: { name: 'CodecPrivate', type: 'Binary' },
105
+ 0x58688: { name: 'CodecName', type: 'String' },
106
+ 0x3446: { name: 'AttachmentLink', type: 'Uint' },
107
+ 0x1a9697: { name: 'CodecSettings', type: 'String' },
108
+ 0x1b4040: { name: 'CodecInfoURL', type: 'String' },
109
+ 0x6b240: { name: 'CodecDownloadURL', type: 'String' },
110
+ 0x2a: { name: 'CodecDecodeAll', type: 'Uint' },
111
+ 0x2fab: { name: 'TrackOverlay', type: 'Uint' },
112
+ 0x16aa: { name: 'CodecDelay', type: 'Uint' },
113
+ 0x16bb: { name: 'SeekPreRoll', type: 'Uint' },
114
+ 0x2624: { name: 'TrackTranslate', type: 'Container' },
115
+ 0x26fc: { name: 'TrackTranslateEditionUID', type: 'Uint' },
116
+ 0x26bf: { name: 'TrackTranslateCodec', type: 'Uint' },
117
+ 0x26a5: { name: 'TrackTranslateTrackID', type: 'Binary' },
118
+ 0x60: { name: 'Video', type: 'Container' },
119
+ 0x1a: { name: 'FlagInterlaced', type: 'Uint' },
120
+ 0x13b8: { name: 'StereoMode', type: 'Uint' },
121
+ 0x13c0: { name: 'AlphaMode', type: 'Uint' },
122
+ 0x13b9: { name: 'OldStereoMode', type: 'Uint' },
123
+ 0x30: { name: 'PixelWidth', type: 'Uint' },
124
+ 0x3a: { name: 'PixelHeight', type: 'Uint' },
125
+ 0x14aa: { name: 'PixelCropBottom', type: 'Uint' },
126
+ 0x14bb: { name: 'PixelCropTop', type: 'Uint' },
127
+ 0x14cc: { name: 'PixelCropLeft', type: 'Uint' },
128
+ 0x14dd: { name: 'PixelCropRight', type: 'Uint' },
129
+ 0x14b0: { name: 'DisplayWidth', type: 'Uint' },
130
+ 0x14ba: { name: 'DisplayHeight', type: 'Uint' },
131
+ 0x14b2: { name: 'DisplayUnit', type: 'Uint' },
132
+ 0x14b3: { name: 'AspectRatioType', type: 'Uint' },
133
+ 0xeb524: { name: 'ColourSpace', type: 'Binary' },
134
+ 0xfb523: { name: 'GammaValue', type: 'Float' },
135
+ 0x383e3: { name: 'FrameRate', type: 'Float' },
136
+ 0x61: { name: 'Audio', type: 'Container' },
137
+ 0x35: { name: 'SamplingFrequency', type: 'Float' },
138
+ 0x38b5: { name: 'OutputSamplingFrequency', type: 'Float' },
139
+ 0x1f: { name: 'Channels', type: 'Uint' },
140
+ 0x3d7b: { name: 'ChannelPositions', type: 'Binary' },
141
+ 0x2264: { name: 'BitDepth', type: 'Uint' },
142
+ 0x62: { name: 'TrackOperation', type: 'Container' },
143
+ 0x63: { name: 'TrackCombinePlanes', type: 'Container' },
144
+ 0x64: { name: 'TrackPlane', type: 'Container' },
145
+ 0x65: { name: 'TrackPlaneUID', type: 'Uint' },
146
+ 0x66: { name: 'TrackPlaneType', type: 'Uint' },
147
+ 0x69: { name: 'TrackJoinBlocks', type: 'Container' },
148
+ 0x6d: { name: 'TrackJoinUID', type: 'Uint' },
149
+ 0x40: { name: 'TrickTrackUID', type: 'Uint' },
150
+ 0x41: { name: 'TrickTrackSegmentUID', type: 'Binary' },
151
+ 0x46: { name: 'TrickTrackFlag', type: 'Uint' },
152
+ 0x47: { name: 'TrickMasterTrackUID', type: 'Uint' },
153
+ 0x44: { name: 'TrickMasterTrackSegmentUID', type: 'Binary' },
154
+ 0x2d80: { name: 'ContentEncodings', type: 'Container' },
155
+ 0x2240: { name: 'ContentEncoding', type: 'Container' },
156
+ 0x1031: { name: 'ContentEncodingOrder', type: 'Uint' },
157
+ 0x1032: { name: 'ContentEncodingScope', type: 'Uint' },
158
+ 0x1033: { name: 'ContentEncodingType', type: 'Uint' },
159
+ 0x1034: { name: 'ContentCompression', type: 'Container' },
160
+ 0x254: { name: 'ContentCompAlgo', type: 'Uint' },
161
+ 0x255: { name: 'ContentCompSettings', type: 'Binary' },
162
+ 0x1035: { name: 'ContentEncryption', type: 'Container' },
163
+ 0x7e1: { name: 'ContentEncAlgo', type: 'Uint' },
164
+ 0x7e2: { name: 'ContentEncKeyID', type: 'Binary' },
165
+ 0x7e3: { name: 'ContentSignature', type: 'Binary' },
166
+ 0x7e4: { name: 'ContentSigKeyID', type: 'Binary' },
167
+ 0x7e5: { name: 'ContentSigAlgo', type: 'Uint' },
168
+ 0x7e6: { name: 'ContentSigHashAlgo', type: 'Uint' },
169
+ 0xc53bb6b: { name: 'Cues', type: 'Container' },
170
+ 0x3b: { name: 'CuePoint', type: 'Container' },
171
+ 0x33: { name: 'CueTime', type: 'Uint' },
172
+ 0x37: { name: 'CueTrackPositions', type: 'Container' },
173
+ 0x77: { name: 'CueTrack', type: 'Uint' },
174
+ 0x71: { name: 'CueClusterPosition', type: 'Uint' },
175
+ 0x70: { name: 'CueRelativePosition', type: 'Uint' },
176
+ 0x32: { name: 'CueDuration', type: 'Uint' },
177
+ 0x1378: { name: 'CueBlockNumber', type: 'Uint' },
178
+ 0x6a: { name: 'CueCodecState', type: 'Uint' },
179
+ 0x5b: { name: 'CueReference', type: 'Container' },
180
+ 0x16: { name: 'CueRefTime', type: 'Uint' },
181
+ 0x17: { name: 'CueRefCluster', type: 'Uint' },
182
+ 0x135f: { name: 'CueRefNumber', type: 'Uint' },
183
+ 0x6b: { name: 'CueRefCodecState', type: 'Uint' },
184
+ 0x941a469: { name: 'Attachments', type: 'Container' },
185
+ 0x21a7: { name: 'AttachedFile', type: 'Container' },
186
+ 0x67e: { name: 'FileDescription', type: 'String' },
187
+ 0x66e: { name: 'FileName', type: 'String' },
188
+ 0x660: { name: 'FileMimeType', type: 'String' },
189
+ 0x65c: { name: 'FileData', type: 'Binary' },
190
+ 0x6ae: { name: 'FileUID', type: 'Uint' },
191
+ 0x675: { name: 'FileReferral', type: 'Binary' },
192
+ 0x661: { name: 'FileUsedStartTime', type: 'Uint' },
193
+ 0x662: { name: 'FileUsedEndTime', type: 'Uint' },
194
+ 0x43a770: { name: 'Chapters', type: 'Container' },
195
+ 0x5b9: { name: 'EditionEntry', type: 'Container' },
196
+ 0x5bc: { name: 'EditionUID', type: 'Uint' },
197
+ 0x5bd: { name: 'EditionFlagHidden', type: 'Uint' },
198
+ 0x5db: { name: 'EditionFlagDefault', type: 'Uint' },
199
+ 0x5dd: { name: 'EditionFlagOrdered', type: 'Uint' },
200
+ 0x36: { name: 'ChapterAtom', type: 'Container' },
201
+ 0x33c4: { name: 'ChapterUID', type: 'Uint' },
202
+ 0x1654: { name: 'ChapterStringUID', type: 'String' },
203
+ 0x11: { name: 'ChapterTimeStart', type: 'Uint' },
204
+ 0x12: { name: 'ChapterTimeEnd', type: 'Uint' },
205
+ 0x18: { name: 'ChapterFlagHidden', type: 'Uint' },
206
+ 0x598: { name: 'ChapterFlagEnabled', type: 'Uint' },
207
+ 0x2e67: { name: 'ChapterSegmentUID', type: 'Binary' },
208
+ 0x2ebc: { name: 'ChapterSegmentEditionUID', type: 'Uint' },
209
+ 0x23c3: { name: 'ChapterPhysicalEquiv', type: 'Uint' },
210
+ 0xf: { name: 'ChapterTrack', type: 'Container' },
211
+ 0x9: { name: 'ChapterTrackNumber', type: 'Uint' },
212
+ 0x0: { name: 'ChapterDisplay', type: 'Container' },
213
+ 0x5: { name: 'ChapString', type: 'String' },
214
+ 0x37c: { name: 'ChapLanguage', type: 'String' },
215
+ 0x37e: { name: 'ChapCountry', type: 'String' },
216
+ 0x2944: { name: 'ChapProcess', type: 'Container' },
217
+ 0x2955: { name: 'ChapProcessCodecID', type: 'Uint' },
218
+ 0x50d: { name: 'ChapProcessPrivate', type: 'Binary' },
219
+ 0x2911: { name: 'ChapProcessCommand', type: 'Container' },
220
+ 0x2922: { name: 'ChapProcessTime', type: 'Uint' },
221
+ 0x2933: { name: 'ChapProcessData', type: 'Binary' },
222
+ 0x254c367: { name: 'Tags', type: 'Container' },
223
+ 0x3373: { name: 'Tag', type: 'Container' },
224
+ 0x23c0: { name: 'Targets', type: 'Container' },
225
+ 0x28ca: { name: 'TargetTypeValue', type: 'Uint' },
226
+ 0x23ca: { name: 'TargetType', type: 'String' },
227
+ 0x23c5: { name: 'TagTrackUID', type: 'Uint' },
228
+ 0x23c9: { name: 'TagEditionUID', type: 'Uint' },
229
+ 0x23c4: { name: 'TagChapterUID', type: 'Uint' },
230
+ 0x23c6: { name: 'TagAttachmentUID', type: 'Uint' },
231
+ 0x27c8: { name: 'SimpleTag', type: 'Container' },
232
+ 0x5a3: { name: 'TagName', type: 'String' },
233
+ 0x47a: { name: 'TagLanguage', type: 'String' },
234
+ 0x484: { name: 'TagDefault', type: 'Uint' },
235
+ 0x487: { name: 'TagString', type: 'String' },
236
+ 0x485: { name: 'TagBinary', type: 'Binary' },
237
+ };
238
+ class WebmBase {
239
+ name;
240
+ type;
241
+ source;
242
+ data;
243
+ constructor(name = 'Unknown', type = 'Unknown') {
244
+ this.name = name;
245
+ this.type = type;
246
+ }
247
+ updateBySource() { }
248
+ setSource(source) {
249
+ this.source = source;
250
+ this.updateBySource();
251
+ }
252
+ updateByData() { }
253
+ setData(data) {
254
+ this.data = data;
255
+ this.updateByData();
256
+ }
257
+ }
258
+ class WebmUint extends WebmBase {
259
+ constructor(name, type) {
260
+ super(name, type || 'Uint');
261
+ }
262
+ updateBySource() {
263
+ // use hex representation of a number instead of number value
264
+ this.data = '';
265
+ for (let i = 0; i < this.source.length; i++) {
266
+ const hex = this.source[i].toString(16);
267
+ this.data += padHex(hex);
268
+ }
269
+ }
270
+ updateByData() {
271
+ const length = this.data.length / 2;
272
+ this.source = new Uint8Array(length);
273
+ for (let i = 0; i < length; i++) {
274
+ const hex = this.data.substr(i * 2, 2);
275
+ this.source[i] = parseInt(hex, 16);
276
+ }
277
+ }
278
+ getValue() {
279
+ return parseInt(this.data, 16);
280
+ }
281
+ setValue(value) {
282
+ this.setData(padHex(value.toString(16)));
283
+ }
284
+ }
285
+ function padHex(hex) {
286
+ return hex.length % 2 === 1 ? '0' + hex : hex;
287
+ }
288
+ class WebmFloat extends WebmBase {
289
+ constructor(name, type) {
290
+ super(name, type || 'Float');
291
+ }
292
+ getFloatArrayType() {
293
+ return this.source && this.source.length === 4
294
+ ? Float32Array
295
+ : Float64Array;
296
+ }
297
+ updateBySource() {
298
+ const byteArray = this.source.reverse();
299
+ const floatArrayType = this.getFloatArrayType();
300
+ const buffer = new ArrayBuffer(byteArray.buffer.byteLength);
301
+ new Uint8Array(buffer).set(new Uint8Array(byteArray.buffer));
302
+ const floatArray = new floatArrayType(buffer);
303
+ this.data = floatArray[0];
304
+ }
305
+ updateByData() {
306
+ const floatArrayType = this.getFloatArrayType();
307
+ const floatArray = new floatArrayType([this.data]);
308
+ const byteArray = new Uint8Array(floatArray.buffer);
309
+ this.source = byteArray.reverse();
310
+ }
311
+ getValue() {
312
+ return this.data;
313
+ }
314
+ setValue(value) {
315
+ this.setData(value);
316
+ }
317
+ }
318
+ class WebmContainer extends WebmBase {
319
+ offset = 0;
320
+ data = [];
321
+ constructor(name, type) {
322
+ super(name, type || 'Container');
323
+ }
324
+ readByte() {
325
+ return this.source[this.offset++];
326
+ }
327
+ readUint() {
328
+ const firstByte = this.readByte();
329
+ const bytes = 8 - firstByte.toString(2).length;
330
+ let value = firstByte - (1 << (7 - bytes));
331
+ for (let i = 0; i < bytes; i++) {
332
+ // don't use bit operators to support x86
333
+ value *= 256;
334
+ value += this.readByte();
335
+ }
336
+ return value;
337
+ }
338
+ updateBySource() {
339
+ let end = undefined;
340
+ this.data = [];
341
+ for (this.offset = 0; this.offset < this.source.length; this.offset = end) {
342
+ const id = this.readUint();
343
+ const len = this.readUint();
344
+ end = Math.min(this.offset + len, this.source.length);
345
+ const data = this.source.slice(this.offset, end);
346
+ const info = sections[id] || { name: 'Unknown', type: 'Unknown' };
347
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
+ let ctr = WebmBase;
349
+ switch (info.type) {
350
+ case 'Container':
351
+ ctr = WebmContainer;
352
+ break;
353
+ case 'Uint':
354
+ ctr = WebmUint;
355
+ break;
356
+ case 'Float':
357
+ ctr = WebmFloat;
358
+ break;
359
+ }
360
+ const section = new ctr(info.name, info.type);
361
+ section.setSource(data);
362
+ this.data.push({
363
+ id,
364
+ idHex: id.toString(16),
365
+ data: section,
366
+ });
367
+ }
368
+ }
369
+ writeUint(x, draft = false) {
370
+ let flag = 0x80;
371
+ let bytes = 1;
372
+ // eslint-disable-next-line no-empty
373
+ for (; x >= flag && bytes < 8; bytes++, flag *= 0x80) { }
374
+ if (!draft) {
375
+ let value = flag + x;
376
+ for (let i = bytes - 1; i >= 0; i--) {
377
+ // don't use bit operators to support x86
378
+ const c = value % 256;
379
+ this.source[this.offset + i] = c;
380
+ value = (value - c) / 256;
381
+ }
382
+ }
383
+ this.offset += bytes;
384
+ }
385
+ writeSections(draft = false) {
386
+ this.offset = 0;
387
+ for (let i = 0; i < this.data.length; i++) {
388
+ const section = this.data[i], content = section.data.source, contentLength = content.length;
389
+ this.writeUint(section.id, draft);
390
+ this.writeUint(contentLength, draft);
391
+ if (!draft) {
392
+ this.source.set(content, this.offset);
393
+ }
394
+ this.offset += contentLength;
395
+ }
396
+ return this.offset;
397
+ }
398
+ updateByData() {
399
+ // run without accessing this.source to determine total length - need to know it to create Uint8Array
400
+ const length = this.writeSections(true);
401
+ this.source = new Uint8Array(length);
402
+ // now really write data
403
+ this.writeSections();
404
+ }
405
+ getSectionById(id) {
406
+ for (let i = 0; i < this.data.length; i++) {
407
+ const section = this.data[i];
408
+ if (section.id === id) {
409
+ return section.data;
410
+ }
411
+ }
412
+ return undefined;
413
+ }
414
+ }
415
+ class WebmFile extends WebmContainer {
416
+ constructor(source) {
417
+ super('File', 'File');
418
+ this.setSource(source);
419
+ }
420
+ fixDuration(duration) {
421
+ const segmentSection = this.getSectionById(0x8538067);
422
+ if (!segmentSection) {
423
+ return false;
424
+ }
425
+ const infoSection = segmentSection.getSectionById(0x549a966);
426
+ if (!infoSection) {
427
+ return false;
428
+ }
429
+ const timeScaleSection = infoSection.getSectionById(0xad7b1);
430
+ if (!timeScaleSection) {
431
+ return false;
432
+ }
433
+ let durationSection = infoSection.getSectionById(0x489);
434
+ if (durationSection) {
435
+ if (durationSection.getValue() <= 0) {
436
+ durationSection.setValue(duration);
437
+ }
438
+ else {
439
+ return false;
440
+ }
441
+ }
442
+ else {
443
+ // append Duration section
444
+ durationSection = new WebmFloat('Duration', 'Float');
445
+ durationSection.setValue(duration);
446
+ infoSection.data.push({
447
+ id: 0x489,
448
+ data: durationSection,
449
+ });
450
+ }
451
+ // set default time scale to 1 millisecond (1000000 nanoseconds)
452
+ timeScaleSection.setValue(1000000);
453
+ infoSection.updateByData();
454
+ segmentSection.updateByData();
455
+ this.updateByData();
456
+ return true;
457
+ }
458
+ toBlob(type = 'video/webm') {
459
+ const buffer = new ArrayBuffer(this.source.buffer.byteLength);
460
+ new Uint8Array(buffer).set(new Uint8Array(this.source.buffer));
461
+ return new Blob([buffer], { type });
462
+ }
463
+ }
464
+ /**
465
+ * Fixes duration on MediaRecorder output.
466
+ * @param blob Input Blob with incorrect duration.
467
+ * @param duration Correct duration (in milliseconds).
468
+ * @param type Output blob mimetype (default: video/webm).
469
+ * @returns
470
+ */
471
+ export const webmFixDuration = (blob, duration, type = 'video/webm') => {
472
+ return new Promise((resolve, reject) => {
473
+ try {
474
+ const reader = new FileReader();
475
+ reader.addEventListener('loadend', () => {
476
+ try {
477
+ const result = reader.result;
478
+ const file = new WebmFile(new Uint8Array(result));
479
+ if (file.fixDuration(duration)) {
480
+ resolve(file.toBlob(type));
481
+ }
482
+ else {
483
+ resolve(blob);
484
+ }
485
+ }
486
+ catch (ex) {
487
+ reject(ex);
488
+ }
489
+ });
490
+ reader.addEventListener('error', () => reject(new Error('FileReader error')));
491
+ reader.readAsArrayBuffer(blob);
492
+ }
493
+ catch (ex) {
494
+ reject(ex);
495
+ }
496
+ });
497
+ };
498
+ //# sourceMappingURL=BlobFix.js.map