@siteed/expo-audio-stream 1.0.3 → 1.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 (132) hide show
  1. package/README.md +26 -175
  2. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
  3. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
  4. package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
  5. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
  6. package/build/index.js +8 -7
  7. package/ios/AudioProcessor.swift +7 -5
  8. package/ios/AudioStreamManager.swift +1 -0
  9. package/ios/ExpoAudioStream.podspec +1 -1
  10. package/ios/ExpoAudioStreamModule.swift +36 -0
  11. package/ios/RecordingResult.swift +1 -0
  12. package/package.json +95 -65
  13. package/src/AudioAnalysis/AudioAnalysis.types.ts +59 -60
  14. package/src/AudioAnalysis/extractAudioAnalysis.ts +132 -121
  15. package/src/AudioAnalysis/extractWaveform.ts +18 -18
  16. package/src/AudioRecorder.provider.tsx +53 -53
  17. package/src/ExpoAudioStream.native.ts +2 -2
  18. package/src/ExpoAudioStream.types.ts +59 -53
  19. package/src/ExpoAudioStream.web.ts +231 -205
  20. package/src/ExpoAudioStreamModule.ts +22 -15
  21. package/src/WebRecorder.web.ts +407 -390
  22. package/src/constants.ts +11 -11
  23. package/src/events.ts +27 -13
  24. package/src/index.ts +17 -15
  25. package/src/logger.ts +15 -19
  26. package/src/useAudioRecorder.tsx +394 -389
  27. package/src/utils/BlobFix.ts +550 -0
  28. package/src/utils/concatenateBuffers.ts +24 -0
  29. package/src/utils/convertPCMToFloat32.ts +72 -45
  30. package/src/utils/encodingToBitDepth.ts +14 -14
  31. package/src/utils/getWavFileInfo.ts +106 -99
  32. package/src/utils/writeWavHeader.ts +50 -45
  33. package/src/workers/InlineFeaturesExtractor.web.tsx +296 -286
  34. package/src/workers/inlineAudioWebWorker.web.tsx +230 -222
  35. package/.eslintrc.js +0 -2
  36. package/.size-limit.json +0 -6
  37. package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  39. package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
  40. package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
  41. package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
  42. package/android/.gradle/8.1.1/gc.properties +0 -0
  43. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  44. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  45. package/android/.gradle/vcs-1/gc.properties +0 -0
  46. package/app.plugin.js +0 -1
  47. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -76
  48. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  49. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  50. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  51. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -4
  52. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  53. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -101
  54. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  55. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  56. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  57. package/build/AudioAnalysis/extractWaveform.js +0 -14
  58. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  59. package/build/AudioRecorder.provider.d.ts +0 -23
  60. package/build/AudioRecorder.provider.d.ts.map +0 -1
  61. package/build/AudioRecorder.provider.js +0 -36
  62. package/build/AudioRecorder.provider.js.map +0 -1
  63. package/build/ExpoAudioStream.native.d.ts +0 -3
  64. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  65. package/build/ExpoAudioStream.native.js +0 -6
  66. package/build/ExpoAudioStream.native.js.map +0 -1
  67. package/build/ExpoAudioStream.types.d.ts +0 -60
  68. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  69. package/build/ExpoAudioStream.types.js +0 -2
  70. package/build/ExpoAudioStream.types.js.map +0 -1
  71. package/build/ExpoAudioStream.web.d.ts +0 -42
  72. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  73. package/build/ExpoAudioStream.web.js +0 -185
  74. package/build/ExpoAudioStream.web.js.map +0 -1
  75. package/build/ExpoAudioStreamModule.d.ts +0 -3
  76. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  77. package/build/ExpoAudioStreamModule.js +0 -18
  78. package/build/ExpoAudioStreamModule.js.map +0 -1
  79. package/build/WebRecorder.web.d.ts +0 -51
  80. package/build/WebRecorder.web.d.ts.map +0 -1
  81. package/build/WebRecorder.web.js +0 -288
  82. package/build/WebRecorder.web.js.map +0 -1
  83. package/build/constants.d.ts +0 -11
  84. package/build/constants.d.ts.map +0 -1
  85. package/build/constants.js +0 -14
  86. package/build/constants.js.map +0 -1
  87. package/build/events.d.ts +0 -6
  88. package/build/events.d.ts.map +0 -1
  89. package/build/events.js +0 -15
  90. package/build/events.js.map +0 -1
  91. package/build/index.d.ts +0 -10
  92. package/build/index.d.ts.map +0 -1
  93. package/build/index.js.map +0 -1
  94. package/build/logger.d.ts +0 -9
  95. package/build/logger.d.ts.map +0 -1
  96. package/build/logger.js +0 -17
  97. package/build/logger.js.map +0 -1
  98. package/build/useAudioRecorder.d.ts +0 -37
  99. package/build/useAudioRecorder.d.ts.map +0 -1
  100. package/build/useAudioRecorder.js +0 -271
  101. package/build/useAudioRecorder.js.map +0 -1
  102. package/build/utils/convertPCMToFloat32.d.ts +0 -11
  103. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  104. package/build/utils/convertPCMToFloat32.js +0 -41
  105. package/build/utils/convertPCMToFloat32.js.map +0 -1
  106. package/build/utils/encodingToBitDepth.d.ts +0 -5
  107. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  108. package/build/utils/encodingToBitDepth.js +0 -13
  109. package/build/utils/encodingToBitDepth.js.map +0 -1
  110. package/build/utils/getWavFileInfo.d.ts +0 -25
  111. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  112. package/build/utils/getWavFileInfo.js +0 -89
  113. package/build/utils/getWavFileInfo.js.map +0 -1
  114. package/build/utils/writeWavHeader.d.ts +0 -9
  115. package/build/utils/writeWavHeader.d.ts.map +0 -1
  116. package/build/utils/writeWavHeader.js +0 -41
  117. package/build/utils/writeWavHeader.js.map +0 -1
  118. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  119. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  120. package/build/workers/InlineFeaturesExtractor.web.js +0 -303
  121. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  122. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  123. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  124. package/build/workers/inlineAudioWebWorker.web.js +0 -243
  125. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  126. package/expo-module.config.json +0 -18
  127. package/plugin/build/index.d.ts +0 -5
  128. package/plugin/build/index.js +0 -28
  129. package/plugin/src/index.ts +0 -53
  130. package/plugin/tsconfig.json +0 -14
  131. package/publish.sh +0 -8
  132. package/tsconfig.json +0 -9
@@ -1,101 +0,0 @@
1
- import ExpoAudioStreamModule from "../ExpoAudioStreamModule";
2
- import { isWeb } from "../constants";
3
- import { getLogger } from "../logger";
4
- import { convertPCMToFloat32 } from "../utils/convertPCMToFloat32";
5
- import { getWavFileInfo } from "../utils/getWavFileInfo";
6
- import { InlineFeaturesExtractor } from "../workers/InlineFeaturesExtractor.web";
7
- const logger = getLogger("extractAudioAnalysis");
8
- export const extractAudioAnalysis = async ({ fileUri, pointsPerSecond = 20, arrayBuffer, bitDepth, skipWavHeader, durationMs, sampleRate, numberOfChannels, algorithm = "rms", features, featuresExtratorUrl, }) => {
9
- if (isWeb) {
10
- if (!arrayBuffer && !fileUri) {
11
- throw new Error("Either arrayBuffer or fileUri must be provided");
12
- }
13
- if (!arrayBuffer) {
14
- logger.log(`fetching fileUri`, fileUri);
15
- const response = await fetch(fileUri);
16
- if (!response.ok) {
17
- throw new Error(`Failed to fetch fileUri: ${response.statusText}`);
18
- }
19
- arrayBuffer = (await response.arrayBuffer()).slice(0);
20
- logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer);
21
- }
22
- // Create a new copy of the ArrayBuffer to avoid detachment issues
23
- const bufferCopy = arrayBuffer.slice(0);
24
- logger.log(`extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`, bufferCopy.slice(0, 100));
25
- let actualBitDepth = bitDepth;
26
- if (!actualBitDepth) {
27
- logger.log(`extractAudioAnalysis bitDepth not provided -- getting wav file info`);
28
- const fileInfo = await getWavFileInfo(bufferCopy);
29
- actualBitDepth = fileInfo.bitDepth;
30
- }
31
- logger.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`);
32
- // let copyChannelData: Float32Array;
33
- // try {
34
- // const audioContext = new (window.AudioContext ||
35
- // // @ts-ignore
36
- // window.webkitAudioContext)();
37
- // const audioBuffer = await audioContext.decodeAudioData(bufferCopy);
38
- // const channelData = audioBuffer.getChannelData(0); // Use only the first channel
39
- // copyChannelData = new Float32Array(channelData); // Create a new Float32Array
40
- // } catch (error) {
41
- // console.warn("Failed to decode audio data:", error);
42
- // // Fall back to creating a new Float32Array from the ArrayBuffer if decoding fails
43
- // copyChannelData = new Float32Array(arrayBuffer);
44
- // }
45
- const { pcmValues: channelData, min, max, } = convertPCMToFloat32({
46
- buffer: arrayBuffer,
47
- bitDepth: actualBitDepth,
48
- skipWavHeader,
49
- });
50
- logger.log(`extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`);
51
- return new Promise((resolve, reject) => {
52
- let worker;
53
- if (featuresExtratorUrl) {
54
- worker = new Worker(new URL(featuresExtratorUrl, window.location.href));
55
- }
56
- else {
57
- const blob = new Blob([InlineFeaturesExtractor], {
58
- type: "application/javascript",
59
- });
60
- const url = URL.createObjectURL(blob);
61
- worker = new Worker(url);
62
- }
63
- worker.onmessage = (event) => {
64
- resolve(event.data.result);
65
- };
66
- worker.onerror = (error) => {
67
- reject(error);
68
- };
69
- worker.postMessage({
70
- command: "process",
71
- channelData,
72
- sampleRate,
73
- pointsPerSecond,
74
- algorithm,
75
- bitDepth,
76
- fullAudioDurationMs: durationMs,
77
- numberOfChannels,
78
- });
79
- });
80
- }
81
- else {
82
- if (!fileUri) {
83
- throw new Error("fileUri is required");
84
- }
85
- logger.log(`extractAudioAnalysis`, {
86
- fileUri,
87
- pointsPerSecond,
88
- algorithm,
89
- });
90
- const res = await ExpoAudioStreamModule.extractAudioAnalysis({
91
- fileUri,
92
- pointsPerSecond,
93
- skipWavHeader,
94
- algorithm,
95
- features,
96
- });
97
- logger.log(`extractAudioAnalysis`, res);
98
- return res;
99
- }
100
- };
101
- //# sourceMappingURL=extractAudioAnalysis.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractAudioAnalysis.js","sourceRoot":"","sources":["../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":"AAEA,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEjF,MAAM,MAAM,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAC;AAEjD,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACzC,OAAO,EACP,eAAe,GAAG,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,CAAC,KAAK,EAAE,EAAE;gBACzB,MAAM,CAAC,KAAK,CAAC,CAAC;YAChB,CAAC,CAAC;YAEF,MAAM,CAAC,WAAW,CAAC;gBACjB,OAAO,EAAE,SAAS;gBAClB,WAAW;gBACX,UAAU;gBACV,eAAe;gBACf,SAAS;gBACT,QAAQ;gBACR,mBAAmB,EAAE,UAAU;gBAC/B,gBAAgB;aACjB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE;YACjC,OAAO;YACP,eAAe;YACf,SAAS;SACV,CAAC,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;YAC3D,OAAO;YACP,eAAe;YACf,aAAa;YACb,SAAS;YACT,QAAQ;SACT,CAAC,CAAC;QACH,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;QACxC,OAAO,GAAG,CAAC;IACb,CAAC;AACH,CAAC,CAAC","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts\nimport { AudioAnalysisData } from \"./AudioAnalysis.types\";\nimport ExpoAudioStreamModule from \"../ExpoAudioStreamModule\";\nimport { isWeb } from \"../constants\";\nimport { getLogger } from \"../logger\";\nimport { ExtractMetadataProps } from \"../useAudioRecorder\";\nimport { convertPCMToFloat32 } from \"../utils/convertPCMToFloat32\";\nimport { getWavFileInfo } from \"../utils/getWavFileInfo\";\nimport { InlineFeaturesExtractor } from \"../workers/InlineFeaturesExtractor.web\";\n\nconst logger = getLogger(\"extractAudioAnalysis\");\n\nexport const extractAudioAnalysis = async ({\n fileUri,\n pointsPerSecond = 20,\n arrayBuffer,\n bitDepth,\n skipWavHeader,\n durationMs,\n sampleRate,\n numberOfChannels,\n algorithm = \"rms\",\n features,\n featuresExtratorUrl,\n}: ExtractMetadataProps): Promise<AudioAnalysisData> => {\n if (isWeb) {\n if (!arrayBuffer && !fileUri) {\n throw new Error(\"Either arrayBuffer or fileUri must be provided\");\n }\n\n if (!arrayBuffer) {\n logger.log(`fetching fileUri`, fileUri);\n const response = await fetch(fileUri!);\n\n if (!response.ok) {\n throw new Error(`Failed to fetch fileUri: ${response.statusText}`);\n }\n\n arrayBuffer = (await response.arrayBuffer()).slice(0);\n logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer);\n }\n\n // Create a new copy of the ArrayBuffer to avoid detachment issues\n const bufferCopy = arrayBuffer.slice(0);\n logger.log(\n `extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,\n bufferCopy.slice(0, 100),\n );\n\n let actualBitDepth = bitDepth;\n if (!actualBitDepth) {\n logger.log(\n `extractAudioAnalysis bitDepth not provided -- getting wav file info`,\n );\n const fileInfo = await getWavFileInfo(bufferCopy);\n actualBitDepth = fileInfo.bitDepth;\n }\n logger.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`);\n // let copyChannelData: Float32Array;\n // try {\n // const audioContext = new (window.AudioContext ||\n // // @ts-ignore\n // window.webkitAudioContext)();\n // const audioBuffer = await audioContext.decodeAudioData(bufferCopy);\n // const channelData = audioBuffer.getChannelData(0); // Use only the first channel\n // copyChannelData = new Float32Array(channelData); // Create a new Float32Array\n // } catch (error) {\n // console.warn(\"Failed to decode audio data:\", error);\n // // Fall back to creating a new Float32Array from the ArrayBuffer if decoding fails\n // copyChannelData = new Float32Array(arrayBuffer);\n // }\n\n const {\n pcmValues: channelData,\n min,\n max,\n } = convertPCMToFloat32({\n buffer: arrayBuffer,\n bitDepth: actualBitDepth,\n skipWavHeader,\n });\n logger.log(\n `extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`,\n );\n\n return new Promise((resolve, reject) => {\n let worker: Worker;\n if (featuresExtratorUrl) {\n worker = new Worker(new URL(featuresExtratorUrl, window.location.href));\n } else {\n const blob = new Blob([InlineFeaturesExtractor], {\n type: \"application/javascript\",\n });\n const url = URL.createObjectURL(blob);\n worker = new Worker(url);\n }\n\n worker.onmessage = (event) => {\n resolve(event.data.result);\n };\n\n worker.onerror = (error) => {\n reject(error);\n };\n\n worker.postMessage({\n command: \"process\",\n channelData,\n sampleRate,\n pointsPerSecond,\n algorithm,\n bitDepth,\n fullAudioDurationMs: durationMs,\n numberOfChannels,\n });\n });\n } else {\n if (!fileUri) {\n throw new Error(\"fileUri is required\");\n }\n logger.log(`extractAudioAnalysis`, {\n fileUri,\n pointsPerSecond,\n algorithm,\n });\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n pointsPerSecond,\n skipWavHeader,\n algorithm,\n features,\n });\n logger.log(`extractAudioAnalysis`, res);\n return res;\n }\n};\n"]}
@@ -1,8 +0,0 @@
1
- export interface ExtractWaveformProps {
2
- fileUri: string;
3
- numberOfSamples: number;
4
- offset?: number;
5
- length?: number;
6
- }
7
- export declare const extractWaveform: ({ fileUri, numberOfSamples, offset, length, }: ExtractWaveformProps) => Promise<unknown>;
8
- //# sourceMappingURL=extractWaveform.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractWaveform.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/extractWaveform.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AACD,eAAO,MAAM,eAAe,kDAKzB,oBAAoB,KAAG,OAAO,CAAC,OAAO,CASxC,CAAC"}
@@ -1,14 +0,0 @@
1
- import ExpoAudioStreamModule from "../ExpoAudioStreamModule";
2
- import { getLogger } from "../logger";
3
- const logger = getLogger("extractWaveform");
4
- export const extractWaveform = async ({ fileUri, numberOfSamples, offset = 0, length, }) => {
5
- const res = await ExpoAudioStreamModule.extractAudioAnalysis({
6
- fileUri,
7
- numberOfSamples,
8
- offset,
9
- length,
10
- });
11
- logger.log(`extractWaveform`, res);
12
- return res;
13
- };
14
- //# sourceMappingURL=extractWaveform.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extractWaveform.js","sourceRoot":"","sources":["../../src/AudioAnalysis/extractWaveform.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAO5C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EACpC,OAAO,EACP,eAAe,EACf,MAAM,GAAG,CAAC,EACV,MAAM,GACe,EAAoB,EAAE;IAC3C,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;QAC3D,OAAO;QACP,eAAe;QACf,MAAM;QACN,MAAM;KACP,CAAC,CAAC;IACH,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;IACnC,OAAO,GAAG,CAAC;AACb,CAAC,CAAC","sourcesContent":["import ExpoAudioStreamModule from \"../ExpoAudioStreamModule\";\nimport { getLogger } from \"../logger\";\n\nconst logger = getLogger(\"extractWaveform\");\nexport interface ExtractWaveformProps {\n fileUri: string;\n numberOfSamples: number;\n offset?: number;\n length?: number;\n}\nexport const extractWaveform = async ({\n fileUri,\n numberOfSamples,\n offset = 0,\n length,\n}: ExtractWaveformProps): Promise<unknown> => {\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n numberOfSamples,\n offset,\n length,\n });\n logger.log(`extractWaveform`, res);\n return res;\n};\n"]}
@@ -1,23 +0,0 @@
1
- import React from "react";
2
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
3
- import { AudioRecordingResult, RecordingConfig, StartRecordingResult } from "./ExpoAudioStream.types";
4
- import { UseAudioRecorderProps } from "./useAudioRecorder";
5
- export interface UseAudioRecorderState {
6
- startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
7
- stopRecording: () => Promise<AudioRecordingResult | null>;
8
- pauseRecording: () => void;
9
- resumeRecording: () => void;
10
- isRecording: boolean;
11
- isPaused: boolean;
12
- durationMs: number;
13
- size: number;
14
- analysisData?: AudioAnalysisData;
15
- }
16
- interface AudioRecorderProviderProps {
17
- children: React.ReactNode;
18
- config?: UseAudioRecorderProps;
19
- }
20
- export declare const AudioRecorderProvider: React.FC<AudioRecorderProviderProps>;
21
- export declare const useSharedAudioRecorder: () => UseAudioRecorderState;
22
- export {};
23
- //# sourceMappingURL=AudioRecorder.provider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudioRecorder.provider.d.ts","sourceRoot":"","sources":["../src/AudioRecorder.provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoC,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,oBAAoB,CAAC;AAE7E,MAAM,WAAW,qBAAqB;IACpC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACtE,aAAa,EAAE,MAAM,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC,CAAC;IAC1D,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAuBD,UAAU,0BAA0B;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAUtE,CAAC;AAEF,eAAO,MAAM,sBAAsB,6BAQlC,CAAC"}
@@ -1,36 +0,0 @@
1
- // packages/expo-audio-stream/src/AudioRecorder.provider.tsx
2
- import React, { createContext, useContext } from "react";
3
- import { useAudioRecorder } from "./useAudioRecorder";
4
- const initContext = {
5
- isRecording: false,
6
- isPaused: false,
7
- durationMs: 0,
8
- size: 0,
9
- startRecording: async () => {
10
- throw new Error("AudioRecorderProvider not found");
11
- },
12
- stopRecording: async () => {
13
- throw new Error("AudioRecorderProvider not found");
14
- },
15
- pauseRecording: () => {
16
- throw new Error("AudioRecorderProvider not found");
17
- },
18
- resumeRecording: () => {
19
- throw new Error("AudioRecorderProvider not found");
20
- },
21
- };
22
- const AudioRecorderContext = createContext(initContext);
23
- export const AudioRecorderProvider = ({ children, config = {}, }) => {
24
- const audioRecorder = useAudioRecorder(config);
25
- return (<AudioRecorderContext.Provider value={audioRecorder}>
26
- {children}
27
- </AudioRecorderContext.Provider>);
28
- };
29
- export const useSharedAudioRecorder = () => {
30
- const context = useContext(AudioRecorderContext);
31
- if (!context) {
32
- throw new Error("useSharedAudioRecorder must be used within an AudioRecorderProvider");
33
- }
34
- return context;
35
- };
36
- //# sourceMappingURL=AudioRecorder.provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AudioRecorder.provider.js","sourceRoot":"","sources":["../src/AudioRecorder.provider.tsx"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAQzD,OAAO,EAAyB,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAc7E,MAAM,WAAW,GAA0B;IACzC,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,CAAC;IACb,IAAI,EAAE,CAAC;IACP,cAAc,EAAE,KAAK,IAAI,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,aAAa,EAAE,KAAK,IAAI,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IACrD,CAAC;CACF,CAAC;AAEF,MAAM,oBAAoB,GAAG,aAAa,CAAwB,WAAW,CAAC,CAAC;AAO/E,MAAM,CAAC,MAAM,qBAAqB,GAAyC,CAAC,EAC1E,QAAQ,EACR,MAAM,GAAG,EAAE,GACZ,EAAE,EAAE;IACH,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,OAAO,CACL,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,CAClD;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACjD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC","sourcesContent":["// packages/expo-audio-stream/src/AudioRecorder.provider.tsx\nimport React, { createContext, useContext } from \"react\";\n\nimport { AudioAnalysisData } from \"./AudioAnalysis/AudioAnalysis.types\";\nimport {\n AudioRecordingResult,\n RecordingConfig,\n StartRecordingResult,\n} from \"./ExpoAudioStream.types\";\nimport { UseAudioRecorderProps, useAudioRecorder } from \"./useAudioRecorder\";\n\nexport interface UseAudioRecorderState {\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;\n stopRecording: () => Promise<AudioRecordingResult | null>;\n pauseRecording: () => void;\n resumeRecording: () => void;\n isRecording: boolean;\n isPaused: boolean;\n durationMs: number; // Duration of the recording\n size: number; // Size in bytes of the recorded audio\n analysisData?: AudioAnalysisData;\n}\n\nconst initContext: UseAudioRecorderState = {\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n startRecording: async () => {\n throw new Error(\"AudioRecorderProvider not found\");\n },\n stopRecording: async () => {\n throw new Error(\"AudioRecorderProvider not found\");\n },\n pauseRecording: () => {\n throw new Error(\"AudioRecorderProvider not found\");\n },\n resumeRecording: () => {\n throw new Error(\"AudioRecorderProvider not found\");\n },\n};\n\nconst AudioRecorderContext = createContext<UseAudioRecorderState>(initContext);\n\ninterface AudioRecorderProviderProps {\n children: React.ReactNode;\n config?: UseAudioRecorderProps;\n}\n\nexport const AudioRecorderProvider: React.FC<AudioRecorderProviderProps> = ({\n children,\n config = {},\n}) => {\n const audioRecorder = useAudioRecorder(config);\n return (\n <AudioRecorderContext.Provider value={audioRecorder}>\n {children}\n </AudioRecorderContext.Provider>\n );\n};\n\nexport const useSharedAudioRecorder = () => {\n const context = useContext(AudioRecorderContext);\n if (!context) {\n throw new Error(\n \"useSharedAudioRecorder must be used within an AudioRecorderProvider\",\n );\n }\n return context;\n};\n"]}
@@ -1,3 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
3
- //# sourceMappingURL=ExpoAudioStream.native.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.native.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.native.ts"],"names":[],"mappings":";AAKA,wBAAsD"}
@@ -1,6 +0,0 @@
1
- // src/ExpoAudioStreamModule.ts
2
- import { requireNativeModule } from "expo-modules-core";
3
- // It loads the native module object from the JSI or falls back to
4
- // the bridge module (from NativeModulesProxy) if the remote debugger is on.
5
- export default requireNativeModule("ExpoAudioStream");
6
- //# sourceMappingURL=ExpoAudioStream.native.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.native.js","sourceRoot":"","sources":["../src/ExpoAudioStream.native.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,iBAAiB,CAAC,CAAC","sourcesContent":["// src/ExpoAudioStreamModule.ts\nimport { requireNativeModule } from \"expo-modules-core\";\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nexport default requireNativeModule(\"ExpoAudioStream\");\n"]}
@@ -1,60 +0,0 @@
1
- import { AudioAnalysisData, AudioFeaturesOptions } from "./AudioAnalysis/AudioAnalysis.types";
2
- export interface AudioStreamStatus {
3
- isRecording: boolean;
4
- isPaused: boolean;
5
- durationMs: number;
6
- size: number;
7
- interval: number;
8
- mimeType: string;
9
- }
10
- export interface AudioDataEvent {
11
- data: string | ArrayBuffer;
12
- position: number;
13
- fileUri: string;
14
- eventDataSize: number;
15
- totalSize: number;
16
- }
17
- export interface AudioEventPayload {
18
- encoded?: string;
19
- buffer?: ArrayBuffer;
20
- fileUri: string;
21
- lastEmittedSize: number;
22
- position: number;
23
- deltaSize: number;
24
- totalSize: number;
25
- mimeType: string;
26
- streamUuid: string;
27
- }
28
- export type EncodingType = "pcm_32bit" | "pcm_16bit" | "pcm_8bit";
29
- export type SampleRate = 16000 | 44100 | 48000;
30
- export type BitDepth = 8 | 16 | 32;
31
- export interface AudioRecordingResult {
32
- fileUri: string;
33
- webAudioUri?: string;
34
- durationMs: number;
35
- size: number;
36
- mimeType: string;
37
- channels: number;
38
- bitDepth: BitDepth;
39
- sampleRate: SampleRate;
40
- }
41
- export interface StartRecordingResult {
42
- fileUri: string;
43
- mimeType: string;
44
- channels?: number;
45
- bitDepth?: BitDepth;
46
- sampleRate?: SampleRate;
47
- }
48
- export interface RecordingConfig {
49
- sampleRate?: SampleRate;
50
- channels?: 1 | 2;
51
- encoding?: EncodingType;
52
- interval?: number;
53
- enableProcessing?: boolean;
54
- pointsPerSecond?: number;
55
- algorithm?: string;
56
- features?: AudioFeaturesOptions;
57
- onAudioStream?: (_: AudioDataEvent) => Promise<void>;
58
- onProcessingResult?: (_: AudioAnalysisData) => Promise<void>;
59
- }
60
- //# sourceMappingURL=ExpoAudioStream.types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.types.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qCAAqC,CAAC;AAE7C,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,MAAM,CAAC;IACxB,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,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,kBAAkB,CAAC,EAAE,CAAC,CAAC,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9D"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ExpoAudioStream.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AudioAnalysisData,\n AudioFeaturesOptions,\n} from \"./AudioAnalysis/AudioAnalysis.types\";\n\nexport interface AudioStreamStatus {\n isRecording: boolean;\n isPaused: boolean;\n durationMs: number;\n size: number;\n interval: number;\n mimeType: string;\n}\n\nexport interface AudioDataEvent {\n data: string | ArrayBuffer;\n position: number;\n fileUri: string;\n eventDataSize: number;\n totalSize: number;\n}\n\nexport interface AudioEventPayload {\n encoded?: string;\n buffer?: ArrayBuffer;\n fileUri: string;\n lastEmittedSize: number;\n position: number;\n deltaSize: number;\n totalSize: number;\n mimeType: string;\n streamUuid: string;\n}\n\nexport type EncodingType = \"pcm_32bit\" | \"pcm_16bit\" | \"pcm_8bit\";\nexport type SampleRate = 16000 | 44100 | 48000;\nexport type BitDepth = 8 | 16 | 32;\n\nexport interface AudioRecordingResult {\n fileUri: string;\n webAudioUri?: string;\n durationMs: number;\n size: number;\n mimeType: string;\n channels: number;\n bitDepth: BitDepth;\n sampleRate: SampleRate;\n}\n\nexport interface StartRecordingResult {\n fileUri: string;\n mimeType: string;\n channels?: number;\n bitDepth?: BitDepth;\n sampleRate?: SampleRate;\n}\n\nexport interface RecordingConfig {\n sampleRate?: SampleRate; // Sample rate for recording\n channels?: 1 | 2; // 1 or 2 (MONO or STEREO)\n encoding?: EncodingType; // Encoding type for the recording\n interval?: number; // Interval in milliseconds at which to emit recording data\n\n // Optional parameters for audio processing\n enableProcessing?: boolean; // Boolean to enable/disable audio processing (default is false)\n pointsPerSecond?: number; // Number of data points to extract per second of audio (default is 1000)\n algorithm?: string; // Algorithm to use for extraction (default is \"rms\")\n features?: AudioFeaturesOptions; // Feature options to extract (default is empty)\n\n // Optional paramters from web\n onAudioStream?: (_: AudioDataEvent) => Promise<void>; // Callback function to handle audio stream\n onProcessingResult?: (_: AudioAnalysisData) => Promise<void>; // Callback function to handle processing results\n}\n"]}
@@ -1,42 +0,0 @@
1
- import { EventEmitter } from "expo-modules-core";
2
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
3
- import { AudioRecordingResult, AudioStreamStatus, BitDepth, RecordingConfig, StartRecordingResult } from "./ExpoAudioStream.types";
4
- import { WebRecorder } from "./WebRecorder.web";
5
- export interface EmitAudioEventProps {
6
- data: ArrayBuffer;
7
- position: number;
8
- }
9
- export type EmitAudioEventFunction = (_: EmitAudioEventProps) => void;
10
- export type EmitAudioAnalysisFunction = (_: AudioAnalysisData) => void;
11
- export interface ExpoAudioStreamWebProps {
12
- audioWorkletUrl: string;
13
- featuresExtratorUrl: string;
14
- }
15
- export declare class ExpoAudioStreamWeb extends EventEmitter {
16
- customRecorder: WebRecorder | null;
17
- audioChunks: ArrayBuffer[];
18
- isRecording: boolean;
19
- isPaused: boolean;
20
- recordingStartTime: number;
21
- pausedTime: number;
22
- currentDurationMs: number;
23
- currentSize: number;
24
- currentInterval: number;
25
- lastEmittedSize: number;
26
- lastEmittedTime: number;
27
- streamUuid: string | null;
28
- extension: "webm" | "wav";
29
- recordingConfig?: RecordingConfig;
30
- bitDepth: BitDepth;
31
- audioWorkletUrl: string;
32
- featuresExtratorUrl: string;
33
- constructor({ audioWorkletUrl, featuresExtratorUrl, }: ExpoAudioStreamWebProps);
34
- getMediaStream(): Promise<MediaStream>;
35
- startRecording(recordingConfig?: RecordingConfig): Promise<StartRecordingResult>;
36
- emitAudioEvent({ data, position }: EmitAudioEventProps): void;
37
- stopRecording(): Promise<AudioRecordingResult | null>;
38
- pauseRecording(): Promise<void>;
39
- resumeRecording(): Promise<void>;
40
- status(): AudioStreamStatus;
41
- }
42
- //# sourceMappingURL=ExpoAudioStream.web.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.web.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAEL,oBAAoB,EACpB,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,oBAAoB,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAC;AACtE,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAEvE,MAAM,WAAW,uBAAuB;IACtC,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAID,qBAAa,kBAAmB,SAAQ,YAAY;IAClD,cAAc,EAAE,WAAW,GAAG,IAAI,CAAC;IACnC,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B,WAAW,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,OAAO,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,SAAS,EAAE,MAAM,GAAG,KAAK,CAAS;IAClC,eAAe,CAAC,EAAE,eAAe,CAAC;IAClC,QAAQ,EAAE,QAAQ,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,MAAM,CAAC;gBAEhB,EACV,eAAe,EACf,mBAAmB,GACpB,EAAE,uBAAuB;IA6BpB,cAAc;IAUd,cAAc,CAAC,eAAe,GAAE,eAAoB;IA8D1D,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,mBAAmB;IAiBhD,aAAa,IAAI,OAAO,CAAC,oBAAoB,GAAG,IAAI,CAAC;IAqBrD,cAAc;IAad,eAAe;IAarB,MAAM;CAWP"}
@@ -1,185 +0,0 @@
1
- // src/ExpoAudioStreamModule.web.ts
2
- import { EventEmitter } from "expo-modules-core";
3
- import { WebRecorder } from "./WebRecorder.web";
4
- import { getLogger } from "./logger";
5
- import { encodingToBitDepth } from "./utils/encodingToBitDepth";
6
- const logger = getLogger("ExpoAudioStreamWeb");
7
- export class ExpoAudioStreamWeb extends EventEmitter {
8
- customRecorder;
9
- audioChunks;
10
- isRecording;
11
- isPaused;
12
- recordingStartTime;
13
- pausedTime;
14
- currentDurationMs;
15
- currentSize;
16
- currentInterval;
17
- lastEmittedSize;
18
- lastEmittedTime;
19
- streamUuid;
20
- extension = "wav"; // Default extension is 'webm'
21
- recordingConfig;
22
- bitDepth; // Bit depth of the audio
23
- audioWorkletUrl;
24
- featuresExtratorUrl;
25
- constructor({ audioWorkletUrl, featuresExtratorUrl, }) {
26
- const mockNativeModule = {
27
- addListener: (eventName) => {
28
- // Not used on web
29
- },
30
- removeListeners: (count) => {
31
- // Not used on web
32
- },
33
- };
34
- super(mockNativeModule); // Pass the mock native module to the parent class
35
- this.customRecorder = null;
36
- this.audioChunks = [];
37
- this.isRecording = false;
38
- this.isPaused = false;
39
- this.recordingStartTime = 0;
40
- this.pausedTime = 0;
41
- this.currentDurationMs = 0;
42
- this.currentSize = 0;
43
- this.bitDepth = 32; // Default
44
- this.currentInterval = 1000; // Default interval in ms
45
- this.lastEmittedSize = 0;
46
- this.lastEmittedTime = 0;
47
- this.streamUuid = null; // Initialize UUID on first recording start
48
- this.audioWorkletUrl = audioWorkletUrl;
49
- this.featuresExtratorUrl = featuresExtratorUrl;
50
- }
51
- // Utility to handle user media stream
52
- async getMediaStream() {
53
- try {
54
- return await navigator.mediaDevices.getUserMedia({ audio: true });
55
- }
56
- catch (error) {
57
- console.error("Failed to get media stream:", error);
58
- throw error;
59
- }
60
- }
61
- // Start recording with options
62
- async startRecording(recordingConfig = {}) {
63
- if (this.isRecording) {
64
- throw new Error("Recording is already in progress");
65
- }
66
- this.bitDepth = encodingToBitDepth({
67
- encoding: recordingConfig.encoding ?? "pcm_32bit",
68
- });
69
- const audioContext = new (window.AudioContext ||
70
- // @ts-ignore - Allow webkitAudioContext for Safari
71
- window.webkitAudioContext)();
72
- const stream = await this.getMediaStream();
73
- const source = audioContext.createMediaStreamSource(stream);
74
- this.customRecorder = new WebRecorder({
75
- audioContext,
76
- source,
77
- recordingConfig,
78
- audioWorkletUrl: this.audioWorkletUrl,
79
- featuresExtratorUrl: this.featuresExtratorUrl,
80
- emitAudioEventCallback: ({ data, position }) => {
81
- this.audioChunks.push(data);
82
- this.currentSize += data.byteLength;
83
- this.emitAudioEvent({ data, position });
84
- this.lastEmittedTime = Date.now();
85
- this.lastEmittedSize = this.currentSize;
86
- },
87
- emitAudioAnalysisCallback: (audioAnalysisData) => {
88
- logger.log(`Emitted AudioAnalysis:`, audioAnalysisData);
89
- this.emit("AudioAnalysis", audioAnalysisData);
90
- },
91
- });
92
- await this.customRecorder.init();
93
- this.customRecorder.start();
94
- // // Set a timer to stop recording after 5 seconds
95
- // setTimeout(() => {
96
- // logger.log("AUTO Stopping recording");
97
- // this.customRecorder?.stopAndPlay();
98
- // this.isRecording = false;
99
- // }, 3000);
100
- this.isRecording = true;
101
- this.recordingConfig = recordingConfig;
102
- this.recordingStartTime = Date.now();
103
- this.pausedTime = 0;
104
- this.lastEmittedSize = 0;
105
- this.lastEmittedTime = 0;
106
- this.streamUuid = Date.now().toString();
107
- const fileUri = `${this.streamUuid}.${this.extension}`;
108
- const streamConfig = {
109
- fileUri,
110
- mimeType: `audio/${this.extension}`,
111
- bitDepth: this.bitDepth,
112
- channels: recordingConfig.channels ?? 1,
113
- sampleRate: recordingConfig.sampleRate ?? 44100,
114
- };
115
- return streamConfig;
116
- }
117
- emitAudioEvent({ data, position }) {
118
- const fileUri = `${this.streamUuid}.${this.extension}`;
119
- const audioEventPayload = {
120
- fileUri,
121
- mimeType: `audio/${this.extension}`,
122
- lastEmittedSize: this.lastEmittedSize, // Since this might be continuously streaming, adjust accordingly
123
- deltaSize: data.byteLength,
124
- position,
125
- totalSize: this.currentSize,
126
- buffer: data,
127
- streamUuid: this.streamUuid ?? "", // Generate or manage UUID for stream identification
128
- };
129
- this.emit("AudioData", audioEventPayload);
130
- }
131
- // Stop recording
132
- async stopRecording() {
133
- if (this.customRecorder) {
134
- const fullPcmBuffer = await this.customRecorder.stop();
135
- logger.debug(`Stopped recording`, fullPcmBuffer);
136
- }
137
- this.isRecording = false;
138
- this.currentDurationMs = Date.now() - this.recordingStartTime;
139
- const result = {
140
- fileUri: `${this.streamUuid}.${this.extension}`,
141
- bitDepth: this.bitDepth,
142
- channels: this.recordingConfig?.channels ?? 1,
143
- sampleRate: this.recordingConfig?.sampleRate ?? 44100,
144
- durationMs: this.currentDurationMs,
145
- size: this.currentSize,
146
- mimeType: `audio/${this.extension}`,
147
- };
148
- return result;
149
- }
150
- // Pause recording
151
- async pauseRecording() {
152
- if (!this.isRecording || this.isPaused) {
153
- throw new Error("Recording is not active or already paused");
154
- }
155
- if (this.customRecorder) {
156
- this.customRecorder.pause();
157
- }
158
- this.isPaused = true;
159
- this.pausedTime = Date.now();
160
- }
161
- // Resume recording
162
- async resumeRecording() {
163
- if (!this.isPaused) {
164
- throw new Error("Recording is not paused");
165
- }
166
- if (this.customRecorder) {
167
- this.customRecorder.resume();
168
- }
169
- this.isPaused = false;
170
- this.recordingStartTime += Date.now() - this.pausedTime;
171
- }
172
- // Get current status
173
- status() {
174
- const status = {
175
- isRecording: this.isRecording,
176
- isPaused: this.isPaused,
177
- durationMs: Date.now() - this.recordingStartTime,
178
- size: this.currentSize,
179
- interval: this.currentInterval,
180
- mimeType: `audio/${this.extension}`,
181
- };
182
- return status;
183
- }
184
- }
185
- //# sourceMappingURL=ExpoAudioStream.web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStream.web.js","sourceRoot":"","sources":["../src/ExpoAudioStream.web.ts"],"names":[],"mappings":"AAAA,mCAAmC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWjD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAchE,MAAM,MAAM,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAE/C,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAClD,cAAc,CAAqB;IACnC,WAAW,CAAgB;IAC3B,WAAW,CAAU;IACrB,QAAQ,CAAU;IAClB,kBAAkB,CAAS;IAC3B,UAAU,CAAS;IACnB,iBAAiB,CAAS;IAC1B,WAAW,CAAS;IACpB,eAAe,CAAS;IACxB,eAAe,CAAS;IACxB,eAAe,CAAS;IACxB,UAAU,CAAgB;IAC1B,SAAS,GAAmB,KAAK,CAAC,CAAC,8BAA8B;IACjE,eAAe,CAAmB;IAClC,QAAQ,CAAW,CAAC,yBAAyB;IAC7C,eAAe,CAAS;IACxB,mBAAmB,CAAS;IAE5B,YAAY,EACV,eAAe,EACf,mBAAmB,GACK;QACxB,MAAM,gBAAgB,GAAG;YACvB,WAAW,EAAE,CAAC,SAAiB,EAAE,EAAE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QAC9B,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC/B,CAAC;IAED,mBAAmB;IACnB,KAAK,CAAC,eAAe;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;QAC7C,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;QAC/B,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAC;IAC1D,CAAC;IAED,qBAAqB;IACrB,MAAM;QACJ,MAAM,MAAM,GAAsB;YAChC,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,kBAAkB;YAChD,IAAI,EAAE,IAAI,CAAC,WAAW;YACtB,QAAQ,EAAE,IAAI,CAAC,eAAe;YAC9B,QAAQ,EAAE,SAAS,IAAI,CAAC,SAAS,EAAE;SACpC,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// src/ExpoAudioStreamModule.web.ts\nimport { EventEmitter } from \"expo-modules-core\";\n\nimport { AudioAnalysisData } from \"./AudioAnalysis/AudioAnalysis.types\";\nimport {\n AudioEventPayload,\n AudioRecordingResult,\n AudioStreamStatus,\n BitDepth,\n RecordingConfig,\n StartRecordingResult,\n} from \"./ExpoAudioStream.types\";\nimport { WebRecorder } from \"./WebRecorder.web\";\nimport { getLogger } from \"./logger\";\nimport { encodingToBitDepth } from \"./utils/encodingToBitDepth\";\n\nexport interface EmitAudioEventProps {\n data: ArrayBuffer;\n position: number;\n}\nexport type EmitAudioEventFunction = (_: EmitAudioEventProps) => void;\nexport type EmitAudioAnalysisFunction = (_: AudioAnalysisData) => void;\n\nexport interface ExpoAudioStreamWebProps {\n audioWorkletUrl: string;\n featuresExtratorUrl: string;\n}\n\nconst logger = getLogger(\"ExpoAudioStreamWeb\");\n\nexport class ExpoAudioStreamWeb extends EventEmitter {\n customRecorder: WebRecorder | null;\n audioChunks: ArrayBuffer[];\n isRecording: boolean;\n isPaused: boolean;\n recordingStartTime: number;\n pausedTime: number;\n currentDurationMs: number;\n currentSize: number;\n currentInterval: number;\n lastEmittedSize: number;\n lastEmittedTime: number;\n streamUuid: string | null;\n extension: \"webm\" | \"wav\" = \"wav\"; // Default extension is 'webm'\n recordingConfig?: RecordingConfig;\n bitDepth: BitDepth; // Bit depth of the audio\n audioWorkletUrl: string;\n featuresExtratorUrl: string;\n\n constructor({\n audioWorkletUrl,\n featuresExtratorUrl,\n }: ExpoAudioStreamWebProps) {\n const mockNativeModule = {\n addListener: (eventName: string) => {\n // Not used on web\n },\n removeListeners: (count: number) => {\n // Not used on web\n },\n };\n super(mockNativeModule); // Pass the mock native module to the parent class\n\n this.customRecorder = null;\n this.audioChunks = [];\n this.isRecording = false;\n this.isPaused = false;\n this.recordingStartTime = 0;\n this.pausedTime = 0;\n this.currentDurationMs = 0;\n this.currentSize = 0;\n this.bitDepth = 32; // Default\n this.currentInterval = 1000; // Default interval in ms\n this.lastEmittedSize = 0;\n this.lastEmittedTime = 0;\n this.streamUuid = null; // Initialize UUID on first recording start\n this.audioWorkletUrl = audioWorkletUrl;\n this.featuresExtratorUrl = featuresExtratorUrl;\n }\n\n // Utility to handle user media stream\n async getMediaStream() {\n try {\n return await navigator.mediaDevices.getUserMedia({ audio: true });\n } catch (error) {\n console.error(\"Failed to get media stream:\", error);\n throw error;\n }\n }\n\n // Start recording with options\n async startRecording(recordingConfig: RecordingConfig = {}) {\n if (this.isRecording) {\n throw new Error(\"Recording is already in progress\");\n }\n\n this.bitDepth = encodingToBitDepth({\n encoding: recordingConfig.encoding ?? \"pcm_32bit\",\n });\n\n const audioContext = new (window.AudioContext ||\n // @ts-ignore - Allow webkitAudioContext for Safari\n window.webkitAudioContext)();\n const stream = await this.getMediaStream();\n\n const source = audioContext.createMediaStreamSource(stream);\n\n this.customRecorder = new WebRecorder({\n audioContext,\n source,\n recordingConfig,\n audioWorkletUrl: this.audioWorkletUrl,\n featuresExtratorUrl: this.featuresExtratorUrl,\n emitAudioEventCallback: ({ data, position }: EmitAudioEventProps) => {\n this.audioChunks.push(data);\n this.currentSize += data.byteLength;\n this.emitAudioEvent({ data, position });\n this.lastEmittedTime = Date.now();\n this.lastEmittedSize = this.currentSize;\n },\n emitAudioAnalysisCallback: (audioAnalysisData: AudioAnalysisData) => {\n logger.log(`Emitted AudioAnalysis:`, audioAnalysisData);\n this.emit(\"AudioAnalysis\", audioAnalysisData);\n },\n });\n await this.customRecorder.init();\n this.customRecorder.start();\n\n // // Set a timer to stop recording after 5 seconds\n // setTimeout(() => {\n // logger.log(\"AUTO Stopping recording\");\n // this.customRecorder?.stopAndPlay();\n // this.isRecording = false;\n // }, 3000);\n\n this.isRecording = true;\n this.recordingConfig = recordingConfig;\n this.recordingStartTime = Date.now();\n this.pausedTime = 0;\n this.lastEmittedSize = 0;\n this.lastEmittedTime = 0;\n this.streamUuid = Date.now().toString();\n const fileUri = `${this.streamUuid}.${this.extension}`;\n const streamConfig: StartRecordingResult = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n bitDepth: this.bitDepth,\n channels: recordingConfig.channels ?? 1,\n sampleRate: recordingConfig.sampleRate ?? 44100,\n };\n return streamConfig;\n }\n\n emitAudioEvent({ data, position }: EmitAudioEventProps) {\n const fileUri = `${this.streamUuid}.${this.extension}`;\n const audioEventPayload: AudioEventPayload = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n lastEmittedSize: this.lastEmittedSize, // Since this might be continuously streaming, adjust accordingly\n deltaSize: data.byteLength,\n position,\n totalSize: this.currentSize,\n buffer: data,\n streamUuid: this.streamUuid ?? \"\", // Generate or manage UUID for stream identification\n };\n\n this.emit(\"AudioData\", audioEventPayload);\n }\n\n // Stop recording\n async stopRecording(): Promise<AudioRecordingResult | null> {\n if (this.customRecorder) {\n const fullPcmBuffer = await this.customRecorder.stop();\n logger.debug(`Stopped recording`, fullPcmBuffer);\n }\n this.isRecording = false;\n this.currentDurationMs = Date.now() - this.recordingStartTime;\n const result: AudioRecordingResult = {\n fileUri: `${this.streamUuid}.${this.extension}`,\n bitDepth: this.bitDepth,\n channels: this.recordingConfig?.channels ?? 1,\n sampleRate: this.recordingConfig?.sampleRate ?? 44100,\n durationMs: this.currentDurationMs,\n size: this.currentSize,\n mimeType: `audio/${this.extension}`,\n };\n\n return result;\n }\n\n // Pause recording\n async pauseRecording() {\n if (!this.isRecording || this.isPaused) {\n throw new Error(\"Recording is not active or already paused\");\n }\n\n if (this.customRecorder) {\n this.customRecorder.pause();\n }\n this.isPaused = true;\n this.pausedTime = Date.now();\n }\n\n // Resume recording\n async resumeRecording() {\n if (!this.isPaused) {\n throw new Error(\"Recording is not paused\");\n }\n\n if (this.customRecorder) {\n this.customRecorder.resume();\n }\n this.isPaused = false;\n this.recordingStartTime += Date.now() - this.pausedTime;\n }\n\n // Get current status\n status() {\n const status: AudioStreamStatus = {\n isRecording: this.isRecording,\n isPaused: this.isPaused,\n durationMs: Date.now() - this.recordingStartTime,\n size: this.currentSize,\n interval: this.currentInterval,\n mimeType: `audio/${this.extension}`,\n };\n return status;\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- declare let ExpoAudioStreamModule: any;
2
- export default ExpoAudioStreamModule;
3
- //# sourceMappingURL=ExpoAudioStreamModule.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStreamModule.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStreamModule.ts"],"names":[],"mappings":"AAQA,QAAA,IAAI,qBAAqB,EAAE,GAAG,CAAC;AAe/B,eAAe,qBAAqB,CAAC"}
@@ -1,18 +0,0 @@
1
- import { requireNativeModule } from "expo-modules-core";
2
- import { Platform } from "react-native";
3
- import { ExpoAudioStreamWeb, } from "./ExpoAudioStream.web";
4
- let ExpoAudioStreamModule;
5
- if (Platform.OS === "web") {
6
- let instance = null;
7
- ExpoAudioStreamModule = (webProps) => {
8
- if (!instance) {
9
- instance = new ExpoAudioStreamWeb(webProps);
10
- }
11
- return instance;
12
- };
13
- }
14
- else {
15
- ExpoAudioStreamModule = requireNativeModule("ExpoAudioStream");
16
- }
17
- export default ExpoAudioStreamModule;
18
- //# sourceMappingURL=ExpoAudioStreamModule.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExpoAudioStreamModule.js","sourceRoot":"","sources":["../src/ExpoAudioStreamModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EACL,kBAAkB,GAEnB,MAAM,uBAAuB,CAAC;AAE/B,IAAI,qBAA0B,CAAC;AAE/B,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;IAC1B,IAAI,QAAQ,GAA8B,IAAI,CAAC;IAE/C,qBAAqB,GAAG,CAAC,QAAiC,EAAE,EAAE;QAC5D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;AACJ,CAAC;KAAM,CAAC;IACN,qBAAqB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAC;AACjE,CAAC;AAED,eAAe,qBAAqB,CAAC","sourcesContent":["import { requireNativeModule } from \"expo-modules-core\";\nimport { Platform } from \"react-native\";\n\nimport {\n ExpoAudioStreamWeb,\n ExpoAudioStreamWebProps,\n} from \"./ExpoAudioStream.web\";\n\nlet ExpoAudioStreamModule: any;\n\nif (Platform.OS === \"web\") {\n let instance: ExpoAudioStreamWeb | null = null;\n\n ExpoAudioStreamModule = (webProps: ExpoAudioStreamWebProps) => {\n if (!instance) {\n instance = new ExpoAudioStreamWeb(webProps);\n }\n return instance;\n };\n} else {\n ExpoAudioStreamModule = requireNativeModule(\"ExpoAudioStream\");\n}\n\nexport default ExpoAudioStreamModule;\n"]}