@siteed/expo-audio-stream 1.0.5 → 1.1.2
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.
- package/README.md +21 -5
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
- package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
- package/build/index.js +3 -2
- package/ios/AudioProcessor.swift +7 -5
- package/ios/ExpoAudioStream.podspec +1 -1
- package/ios/ExpoAudioStreamModule.swift +35 -0
- package/package.json +26 -3
- package/src/ExpoAudioStream.types.ts +3 -0
- package/src/ExpoAudioStream.web.ts +0 -1
- package/src/ExpoAudioStreamModule.ts +8 -2
- package/src/index.ts +3 -1
- package/src/logger.ts +0 -1
- package/src/utils/writeWavHeader.ts +5 -0
- package/src/workers/InlineFeaturesExtractor.web.tsx +295 -285
- package/src/workers/inlineAudioWebWorker.web.tsx +229 -221
- package/.eslintrc.js +0 -2
- package/.size-limit.json +0 -6
- package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/app.plugin.js +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -74
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -20
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.js +0 -88
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
- package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
- package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
- package/build/AudioAnalysis/extractWaveform.js +0 -14
- package/build/AudioAnalysis/extractWaveform.js.map +0 -1
- package/build/AudioRecorder.provider.d.ts +0 -23
- package/build/AudioRecorder.provider.d.ts.map +0 -1
- package/build/AudioRecorder.provider.js +0 -36
- package/build/AudioRecorder.provider.js.map +0 -1
- package/build/ExpoAudioStream.native.d.ts +0 -3
- package/build/ExpoAudioStream.native.d.ts.map +0 -1
- package/build/ExpoAudioStream.native.js +0 -6
- package/build/ExpoAudioStream.native.js.map +0 -1
- package/build/ExpoAudioStream.types.d.ts +0 -62
- package/build/ExpoAudioStream.types.d.ts.map +0 -1
- package/build/ExpoAudioStream.types.js +0 -2
- package/build/ExpoAudioStream.types.js.map +0 -1
- package/build/ExpoAudioStream.web.d.ts +0 -42
- package/build/ExpoAudioStream.web.d.ts.map +0 -1
- package/build/ExpoAudioStream.web.js +0 -203
- package/build/ExpoAudioStream.web.js.map +0 -1
- package/build/ExpoAudioStreamModule.d.ts +0 -3
- package/build/ExpoAudioStreamModule.d.ts.map +0 -1
- package/build/ExpoAudioStreamModule.js +0 -19
- package/build/ExpoAudioStreamModule.js.map +0 -1
- package/build/WebRecorder.web.d.ts +0 -51
- package/build/WebRecorder.web.d.ts.map +0 -1
- package/build/WebRecorder.web.js +0 -298
- package/build/WebRecorder.web.js.map +0 -1
- package/build/constants.d.ts +0 -11
- package/build/constants.d.ts.map +0 -1
- package/build/constants.js +0 -14
- package/build/constants.js.map +0 -1
- package/build/events.d.ts +0 -18
- package/build/events.d.ts.map +0 -1
- package/build/events.js +0 -15
- package/build/events.js.map +0 -1
- package/build/index.d.ts +0 -10
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/build/logger.d.ts +0 -9
- package/build/logger.d.ts.map +0 -1
- package/build/logger.js +0 -13
- package/build/logger.js.map +0 -1
- package/build/useAudioRecorder.d.ts +0 -20
- package/build/useAudioRecorder.d.ts.map +0 -1
- package/build/useAudioRecorder.js +0 -271
- package/build/useAudioRecorder.js.map +0 -1
- package/build/utils/BlobFix.d.ts +0 -9
- package/build/utils/BlobFix.d.ts.map +0 -1
- package/build/utils/BlobFix.js +0 -494
- package/build/utils/BlobFix.js.map +0 -1
- package/build/utils/concatenateBuffers.d.ts +0 -8
- package/build/utils/concatenateBuffers.d.ts.map +0 -1
- package/build/utils/concatenateBuffers.js +0 -21
- package/build/utils/concatenateBuffers.js.map +0 -1
- package/build/utils/convertPCMToFloat32.d.ts +0 -11
- package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
- package/build/utils/convertPCMToFloat32.js +0 -54
- package/build/utils/convertPCMToFloat32.js.map +0 -1
- package/build/utils/encodingToBitDepth.d.ts +0 -5
- package/build/utils/encodingToBitDepth.d.ts.map +0 -1
- package/build/utils/encodingToBitDepth.js +0 -13
- package/build/utils/encodingToBitDepth.js.map +0 -1
- package/build/utils/getWavFileInfo.d.ts +0 -26
- package/build/utils/getWavFileInfo.d.ts.map +0 -1
- package/build/utils/getWavFileInfo.js +0 -92
- package/build/utils/getWavFileInfo.js.map +0 -1
- package/build/utils/writeWavHeader.d.ts +0 -9
- package/build/utils/writeWavHeader.d.ts.map +0 -1
- package/build/utils/writeWavHeader.js +0 -41
- package/build/utils/writeWavHeader.js.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
- package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.js +0 -303
- package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
- package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.js +0 -243
- package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
- package/expo-module.config.json +0 -9
- package/plugin/build/index.d.ts +0 -5
- package/plugin/build/index.js +0 -28
- package/plugin/src/index.ts +0 -53
- package/plugin/tsconfig.json +0 -9
- package/publish.sh +0 -8
- package/tsconfig.json +0 -14
|
@@ -1,88 +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 = true, 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();
|
|
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
|
-
const { pcmValues: channelData, min, max, } = await convertPCMToFloat32({
|
|
33
|
-
buffer: arrayBuffer,
|
|
34
|
-
bitDepth: actualBitDepth,
|
|
35
|
-
skipWavHeader,
|
|
36
|
-
});
|
|
37
|
-
logger.log(`extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`);
|
|
38
|
-
return new Promise((resolve, reject) => {
|
|
39
|
-
let worker;
|
|
40
|
-
if (featuresExtratorUrl) {
|
|
41
|
-
worker = new Worker(new URL(featuresExtratorUrl, window.location.href));
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
const blob = new Blob([InlineFeaturesExtractor], {
|
|
45
|
-
type: 'application/javascript',
|
|
46
|
-
});
|
|
47
|
-
const url = URL.createObjectURL(blob);
|
|
48
|
-
worker = new Worker(url);
|
|
49
|
-
}
|
|
50
|
-
worker.onmessage = (event) => {
|
|
51
|
-
resolve(event.data.result);
|
|
52
|
-
};
|
|
53
|
-
worker.onerror = (error) => {
|
|
54
|
-
reject(error);
|
|
55
|
-
};
|
|
56
|
-
worker.postMessage({
|
|
57
|
-
command: 'process',
|
|
58
|
-
channelData,
|
|
59
|
-
sampleRate,
|
|
60
|
-
pointsPerSecond,
|
|
61
|
-
algorithm,
|
|
62
|
-
bitDepth,
|
|
63
|
-
fullAudioDurationMs: durationMs,
|
|
64
|
-
numberOfChannels,
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
if (!fileUri) {
|
|
70
|
-
throw new Error('fileUri is required');
|
|
71
|
-
}
|
|
72
|
-
logger.log(`extractAudioAnalysis`, {
|
|
73
|
-
fileUri,
|
|
74
|
-
pointsPerSecond,
|
|
75
|
-
algorithm,
|
|
76
|
-
});
|
|
77
|
-
const res = await ExpoAudioStreamModule.extractAudioAnalysis({
|
|
78
|
-
fileUri,
|
|
79
|
-
pointsPerSecond,
|
|
80
|
-
skipWavHeader,
|
|
81
|
-
algorithm,
|
|
82
|
-
features,
|
|
83
|
-
});
|
|
84
|
-
logger.log(`extractAudioAnalysis`, res);
|
|
85
|
-
return res;
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=extractAudioAnalysis.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"extractAudioAnalysis.js","sourceRoot":"","sources":["../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":"AAMA,OAAO,qBAAqB,MAAM,0BAA0B,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,EAAE,cAAc,EAAe,MAAM,yBAAyB,CAAA;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAA;AAEhF,MAAM,MAAM,GAAG,SAAS,CAAC,sBAAsB,CAAC,CAAA;AAmBhD,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EACvC,OAAO,EACP,eAAe,GAAG,EAAE,EACpB,WAAW,EACX,QAAQ,EACR,aAAa,GAAG,IAAI,EACpB,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,SAAS,GAAG,KAAK,EACjB,QAAQ,EACR,mBAAmB,GACK,EAA0B,EAAE;IACpD,IAAI,KAAK,EAAE,CAAC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ACD,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE;YAC/B,OAAO;YACP,eAAe;YACf,SAAS;SACZ,CAAC,CAAA;QACF,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;YACzD,OAAO;YACP,eAAe;YACf,aAAa;YACb,SAAS;YACT,QAAQ;SACX,CAAC,CAAA;QACF,MAAM,CAAC,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;QACvC,OAAO,GAAG,CAAA;IACd,CAAC;AACL,CAAC,CAAA","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts\nimport {\n AmplitudeAlgorithm,\n AudioAnalysis,\n AudioFeaturesOptions,\n} from './AudioAnalysis.types'\nimport ExpoAudioStreamModule from '../ExpoAudioStreamModule'\nimport { isWeb } from '../constants'\nimport { getLogger } from '../logger'\nimport { convertPCMToFloat32 } from '../utils/convertPCMToFloat32'\nimport { getWavFileInfo, WavFileInfo } from '../utils/getWavFileInfo'\nimport { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web'\n\nconst logger = getLogger('extractAudioAnalysis')\n\nexport interface ExtractAudioAnalysisProps {\n fileUri?: string // should provide either fileUri or arrayBuffer\n wavMetadata?: WavFileInfo\n arrayBuffer?: ArrayBuffer\n bitDepth?: number\n skipWavHeader?: boolean\n durationMs?: number\n sampleRate?: number\n numberOfChannels?: number\n algorithm?: AmplitudeAlgorithm\n position?: number // Optional number of bytes to skip. Default is 0\n length?: number // Optional number of bytes to read.\n pointsPerSecond?: number // Optional number of points per second. Use to reduce the number of points and compute the number of datapoints to return.\n features?: AudioFeaturesOptions\n featuresExtratorUrl?: string\n}\n\nexport const extractAudioAnalysis = async ({\n fileUri,\n pointsPerSecond = 20,\n arrayBuffer,\n bitDepth,\n skipWavHeader = true,\n durationMs,\n sampleRate,\n numberOfChannels,\n algorithm = 'rms',\n features,\n featuresExtratorUrl,\n}: ExtractAudioAnalysisProps): Promise<AudioAnalysis> => {\n if (isWeb) {\n if (!arrayBuffer && !fileUri) {\n throw new Error('Either arrayBuffer or fileUri must be provided')\n }\n\n if (!arrayBuffer) {\n logger.log(`fetching fileUri`, fileUri)\n const response = await fetch(fileUri!)\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch fileUri: ${response.statusText}`\n )\n }\n\n arrayBuffer = await response.arrayBuffer()\n logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)\n }\n\n // Create a new copy of the ArrayBuffer to avoid detachment issues\n const bufferCopy = arrayBuffer.slice(0)\n logger.log(\n `extractAudioAnalysis 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\n const {\n pcmValues: channelData,\n min,\n max,\n } = await 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(\n new URL(featuresExtratorUrl, window.location.href)\n )\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;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AACD,eAAO,MAAM,eAAe,kDAKzB,oBAAoB,KAAG,OAAO,CAAC,OAAO,CASxC,CAAA"}
|
|
@@ -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,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,MAAM,GAAG,SAAS,CAAC,iBAAiB,CAAC,CAAA;AAO3C,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,eAAe,EACf,MAAM,GAAG,CAAC,EACV,MAAM,GACa,EAAoB,EAAE;IACzC,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;QACzD,OAAO;QACP,eAAe;QACf,MAAM;QACN,MAAM;KACT,CAAC,CAAA;IACF,MAAM,CAAC,GAAG,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAA;IAClC,OAAO,GAAG,CAAA;AACd,CAAC,CAAA","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 { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
|
|
3
|
-
import { AudioRecording, RecordingConfig, StartRecordingResult } from './ExpoAudioStream.types';
|
|
4
|
-
import { UseAudioRecorderProps } from './useAudioRecorder';
|
|
5
|
-
export interface UseAudioRecorderState {
|
|
6
|
-
startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
|
|
7
|
-
stopRecording: () => Promise<AudioRecording | null>;
|
|
8
|
-
pauseRecording: () => void;
|
|
9
|
-
resumeRecording: () => void;
|
|
10
|
-
isRecording: boolean;
|
|
11
|
-
isPaused: boolean;
|
|
12
|
-
durationMs: number;
|
|
13
|
-
size: number;
|
|
14
|
-
analysisData?: AudioAnalysis;
|
|
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,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EACH,cAAc,EACd,eAAe,EACf,oBAAoB,EACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,qBAAqB,EAAoB,MAAM,oBAAoB,CAAA;AAE5E,MAAM,WAAW,qBAAqB;IAClC,cAAc,EAAE,CAAC,CAAC,EAAE,eAAe,KAAK,OAAO,CAAC,oBAAoB,CAAC,CAAA;IACrE,aAAa,EAAE,MAAM,OAAO,CAAC,cAAc,GAAG,IAAI,CAAC,CAAA;IACnD,cAAc,EAAE,MAAM,IAAI,CAAA;IAC1B,eAAe,EAAE,MAAM,IAAI,CAAA;IAC3B,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,CAAC,EAAE,aAAa,CAAA;CAC/B;AAuBD,UAAU,0BAA0B;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE,qBAAqB,CAAA;CACjC;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAUtE,CAAA;AAED,eAAO,MAAM,sBAAsB,6BAQlC,CAAA"}
|
|
@@ -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,CAAA;AAQxD,OAAO,EAAyB,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAc5E,MAAM,WAAW,GAA0B;IACvC,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,CAAC;IACb,IAAI,EAAE,CAAC;IACP,cAAc,EAAE,KAAK,IAAI,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,aAAa,EAAE,KAAK,IAAI,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,cAAc,EAAE,GAAG,EAAE;QACjB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,eAAe,EAAE,GAAG,EAAE;QAClB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;CACJ,CAAA;AAED,MAAM,oBAAoB,GAAG,aAAa,CAAwB,WAAW,CAAC,CAAA;AAO9E,MAAM,CAAC,MAAM,qBAAqB,GAAyC,CAAC,EACxE,QAAQ,EACR,MAAM,GAAG,EAAE,GACd,EAAE,EAAE;IACD,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;IAC9C,OAAO,CACH,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,CAChD;YAAA,CAAC,QAAQ,CACb;QAAA,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CACnC,CAAA;AACL,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACvC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAA;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA","sourcesContent":["// packages/expo-audio-stream/src/AudioRecorder.provider.tsx\nimport React, { createContext, useContext } from 'react'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioRecording,\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<AudioRecording | 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?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.native.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.native.ts"],"names":[],"mappings":";AAKA,wBAAqD"}
|
|
@@ -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,CAAA;AAEvD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,iBAAiB,CAAC,CAAA","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,62 +0,0 @@
|
|
|
1
|
-
import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions } from './AudioAnalysis/AudioAnalysis.types';
|
|
2
|
-
import { AudioAnalysisEvent } from './events';
|
|
3
|
-
export interface AudioStreamStatus {
|
|
4
|
-
isRecording: boolean;
|
|
5
|
-
isPaused: boolean;
|
|
6
|
-
durationMs: number;
|
|
7
|
-
size: number;
|
|
8
|
-
interval: number;
|
|
9
|
-
mimeType: string;
|
|
10
|
-
}
|
|
11
|
-
export interface AudioDataEvent {
|
|
12
|
-
data: string | Float32Array;
|
|
13
|
-
position: number;
|
|
14
|
-
fileUri: string;
|
|
15
|
-
eventDataSize: number;
|
|
16
|
-
totalSize: number;
|
|
17
|
-
}
|
|
18
|
-
export type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit';
|
|
19
|
-
export type SampleRate = 16000 | 44100 | 48000;
|
|
20
|
-
export type BitDepth = 8 | 16 | 32;
|
|
21
|
-
export interface Chunk {
|
|
22
|
-
text: string;
|
|
23
|
-
timestamp: [number, number | null];
|
|
24
|
-
}
|
|
25
|
-
export interface TranscriberData {
|
|
26
|
-
isBusy: boolean;
|
|
27
|
-
text: string;
|
|
28
|
-
chunks: Chunk[];
|
|
29
|
-
}
|
|
30
|
-
export interface AudioRecording {
|
|
31
|
-
fileUri: string;
|
|
32
|
-
filename: string;
|
|
33
|
-
durationMs: number;
|
|
34
|
-
size: number;
|
|
35
|
-
mimeType: string;
|
|
36
|
-
channels: number;
|
|
37
|
-
bitDepth: BitDepth;
|
|
38
|
-
sampleRate: SampleRate;
|
|
39
|
-
transcripts?: TranscriberData[];
|
|
40
|
-
wavPCMData?: Float32Array;
|
|
41
|
-
analysisData?: AudioAnalysis;
|
|
42
|
-
}
|
|
43
|
-
export interface StartRecordingResult {
|
|
44
|
-
fileUri: string;
|
|
45
|
-
mimeType: string;
|
|
46
|
-
channels?: number;
|
|
47
|
-
bitDepth?: BitDepth;
|
|
48
|
-
sampleRate?: SampleRate;
|
|
49
|
-
}
|
|
50
|
-
export interface RecordingConfig {
|
|
51
|
-
sampleRate?: SampleRate;
|
|
52
|
-
channels?: 1 | 2;
|
|
53
|
-
encoding?: EncodingType;
|
|
54
|
-
interval?: number;
|
|
55
|
-
enableProcessing?: boolean;
|
|
56
|
-
pointsPerSecond?: number;
|
|
57
|
-
algorithm?: AmplitudeAlgorithm;
|
|
58
|
-
features?: AudioFeaturesOptions;
|
|
59
|
-
onAudioStream?: (_: AudioDataEvent) => Promise<void>;
|
|
60
|
-
onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>;
|
|
61
|
-
}
|
|
62
|
-
//# 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,EACH,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACvB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,WAAW,iBAAiB;IAC9B,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,cAAc;IAC3B,IAAI,EAAE,MAAM,GAAG,YAAY,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,aAAa,EAAE,MAAM,CAAA;IACrB,SAAS,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,UAAU,CAAA;AACjE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;AAC9C,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,CAAA;AAElC,MAAM,WAAW,KAAK;IAClB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,eAAe;IAC5B,MAAM,EAAE,OAAO,CAAA;IACf,IAAI,EAAE,MAAM,CAAA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oot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AmplitudeAlgorithm,\n AudioAnalysis,\n AudioFeaturesOptions,\n} from './AudioAnalysis/AudioAnalysis.types'\nimport { AudioAnalysisEvent } from './events'\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 | Float32Array\n position: number\n fileUri: string\n eventDataSize: number\n totalSize: number\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 Chunk {\n text: string\n timestamp: [number, number | null]\n}\n\nexport interface TranscriberData {\n isBusy: boolean\n text: string\n chunks: Chunk[]\n}\n\nexport interface AudioRecording {\n fileUri: string\n filename: string\n durationMs: number\n size: number\n mimeType: string\n channels: number\n bitDepth: BitDepth\n sampleRate: SampleRate\n transcripts?: TranscriberData[]\n wavPCMData?: Float32Array // Full PCM data for the recording in WAV format (only on web, for native use the fileUri)\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\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?: AmplitudeAlgorithm // Algorithm to use for amplitude computation (default is \"rms\")\n features?: AudioFeaturesOptions // Feature options to extract (default is empty)\n\n onAudioStream?: (_: AudioDataEvent) => Promise<void> // Callback function to handle audio stream\n onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void> // Callback function to handle audio features extraction results\n}\n"]}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'expo-modules-core';
|
|
2
|
-
import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
|
|
3
|
-
import { AudioRecording, AudioStreamStatus, BitDepth, RecordingConfig, StartRecordingResult } from './ExpoAudioStream.types';
|
|
4
|
-
import { WebRecorder } from './WebRecorder.web';
|
|
5
|
-
export interface EmitAudioEventProps {
|
|
6
|
-
data: Float32Array;
|
|
7
|
-
position: number;
|
|
8
|
-
}
|
|
9
|
-
export type EmitAudioEventFunction = (_: EmitAudioEventProps) => void;
|
|
10
|
-
export type EmitAudioAnalysisFunction = (_: AudioAnalysis) => 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<AudioRecording>;
|
|
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,CAAA;AAEhD,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EACH,cAAc,EACd,iBAAiB,EACjB,QAAQ,EACR,eAAe,EACf,oBAAoB,EACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAO/C,MAAM,WAAW,mBAAmB;IAChC,IAAI,EAAE,YAAY,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACnB;AACD,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,EAAE,mBAAmB,KAAK,IAAI,CAAA;AACrE,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAA;AAElE,MAAM,WAAW,uBAAuB;IACpC,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAA;CAC9B;AAID,qBAAa,kBAAmB,SAAQ,YAAY;IAChD,cAAc,EAAE,WAAW,GAAG,IAAI,CAAA;IAClC,WAAW,EAAE,WAAW,EAAE,CAAA;IAC1B,WAAW,EAAE,OAAO,CAAA;IACpB,QAAQ,EAAE,OAAO,CAAA;IACjB,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACzB,SAAS,EAAE,MAAM,GAAG,KAAK,CAAQ;IACjC,eAAe,CAAC,EAAE,eAAe,CAAA;IACjC,QAAQ,EAAE,QAAQ,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,mBAAmB,EAAE,MAAM,CAAA;gBAEf,EACR,eAAe,EACf,mBAAmB,GACtB,EAAE,uBAAuB;IA6BpB,cAAc;IAUd,cAAc,CAAC,eAAe,GAAE,eAAoB;IAiE1D,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,mBAAmB;IAiBhD,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC;IA2CxC,cAAc;IAad,eAAe;IAarB,MAAM;CAWT"}
|
|
@@ -1,203 +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
|
-
import { writeWavHeader } from './utils/writeWavHeader';
|
|
7
|
-
const logger = getLogger('ExpoAudioStreamWeb');
|
|
8
|
-
export class ExpoAudioStreamWeb extends EventEmitter {
|
|
9
|
-
customRecorder;
|
|
10
|
-
audioChunks;
|
|
11
|
-
isRecording;
|
|
12
|
-
isPaused;
|
|
13
|
-
recordingStartTime;
|
|
14
|
-
pausedTime;
|
|
15
|
-
currentDurationMs;
|
|
16
|
-
currentSize;
|
|
17
|
-
currentInterval;
|
|
18
|
-
lastEmittedSize;
|
|
19
|
-
lastEmittedTime;
|
|
20
|
-
streamUuid;
|
|
21
|
-
extension = 'wav'; // Default extension is 'webm'
|
|
22
|
-
recordingConfig;
|
|
23
|
-
bitDepth; // Bit depth of the audio
|
|
24
|
-
audioWorkletUrl;
|
|
25
|
-
featuresExtratorUrl;
|
|
26
|
-
constructor({ audioWorkletUrl, featuresExtratorUrl, }) {
|
|
27
|
-
const mockNativeModule = {
|
|
28
|
-
addListener: () => {
|
|
29
|
-
// Not used on web
|
|
30
|
-
},
|
|
31
|
-
removeListeners: () => {
|
|
32
|
-
// Not used on web
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
super(mockNativeModule); // Pass the mock native module to the parent class
|
|
36
|
-
this.customRecorder = null;
|
|
37
|
-
this.audioChunks = [];
|
|
38
|
-
this.isRecording = false;
|
|
39
|
-
this.isPaused = false;
|
|
40
|
-
this.recordingStartTime = 0;
|
|
41
|
-
this.pausedTime = 0;
|
|
42
|
-
this.currentDurationMs = 0;
|
|
43
|
-
this.currentSize = 0;
|
|
44
|
-
this.bitDepth = 32; // Default
|
|
45
|
-
this.currentInterval = 1000; // Default interval in ms
|
|
46
|
-
this.lastEmittedSize = 0;
|
|
47
|
-
this.lastEmittedTime = 0;
|
|
48
|
-
this.streamUuid = null; // Initialize UUID on first recording start
|
|
49
|
-
this.audioWorkletUrl = audioWorkletUrl;
|
|
50
|
-
this.featuresExtratorUrl = featuresExtratorUrl;
|
|
51
|
-
}
|
|
52
|
-
// Utility to handle user media stream
|
|
53
|
-
async getMediaStream() {
|
|
54
|
-
try {
|
|
55
|
-
return await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
console.error('Failed to get media stream:', error);
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
// Start recording with options
|
|
63
|
-
async startRecording(recordingConfig = {}) {
|
|
64
|
-
if (this.isRecording) {
|
|
65
|
-
throw new Error('Recording is already in progress');
|
|
66
|
-
}
|
|
67
|
-
this.bitDepth = encodingToBitDepth({
|
|
68
|
-
encoding: recordingConfig.encoding ?? 'pcm_32bit',
|
|
69
|
-
});
|
|
70
|
-
const audioContext = new (window.AudioContext ||
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
72
|
-
// @ts-ignore - Allow webkitAudioContext for Safari
|
|
73
|
-
window.webkitAudioContext)();
|
|
74
|
-
const stream = await this.getMediaStream();
|
|
75
|
-
const source = audioContext.createMediaStreamSource(stream);
|
|
76
|
-
this.customRecorder = new WebRecorder({
|
|
77
|
-
audioContext,
|
|
78
|
-
source,
|
|
79
|
-
recordingConfig,
|
|
80
|
-
audioWorkletUrl: this.audioWorkletUrl,
|
|
81
|
-
emitAudioEventCallback: ({ data, position, }) => {
|
|
82
|
-
this.audioChunks.push(data);
|
|
83
|
-
this.currentSize += data.byteLength;
|
|
84
|
-
this.emitAudioEvent({ data, position });
|
|
85
|
-
this.lastEmittedTime = Date.now();
|
|
86
|
-
this.lastEmittedSize = this.currentSize;
|
|
87
|
-
},
|
|
88
|
-
emitAudioAnalysisCallback: (audioAnalysisData) => {
|
|
89
|
-
logger.log(`Emitted AudioAnalysis:`, audioAnalysisData);
|
|
90
|
-
this.emit('AudioAnalysis', audioAnalysisData);
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
await this.customRecorder.init();
|
|
94
|
-
this.customRecorder.start();
|
|
95
|
-
// // Set a timer to stop recording after 5 seconds
|
|
96
|
-
// setTimeout(() => {
|
|
97
|
-
// logger.log("AUTO Stopping recording");
|
|
98
|
-
// this.customRecorder?.stopAndPlay();
|
|
99
|
-
// this.isRecording = false;
|
|
100
|
-
// }, 3000);
|
|
101
|
-
this.isRecording = true;
|
|
102
|
-
this.recordingConfig = recordingConfig;
|
|
103
|
-
this.recordingStartTime = Date.now();
|
|
104
|
-
this.pausedTime = 0;
|
|
105
|
-
this.lastEmittedSize = 0;
|
|
106
|
-
this.lastEmittedTime = 0;
|
|
107
|
-
this.streamUuid = Date.now().toString();
|
|
108
|
-
const fileUri = `${this.streamUuid}.${this.extension}`;
|
|
109
|
-
const streamConfig = {
|
|
110
|
-
fileUri,
|
|
111
|
-
mimeType: `audio/${this.extension}`,
|
|
112
|
-
bitDepth: this.bitDepth,
|
|
113
|
-
channels: recordingConfig.channels ?? 1,
|
|
114
|
-
sampleRate: recordingConfig.sampleRate ?? 44100,
|
|
115
|
-
};
|
|
116
|
-
return streamConfig;
|
|
117
|
-
}
|
|
118
|
-
emitAudioEvent({ data, position }) {
|
|
119
|
-
const fileUri = `${this.streamUuid}.${this.extension}`;
|
|
120
|
-
const audioEventPayload = {
|
|
121
|
-
fileUri,
|
|
122
|
-
mimeType: `audio/${this.extension}`,
|
|
123
|
-
lastEmittedSize: this.lastEmittedSize, // Since this might be continuously streaming, adjust accordingly
|
|
124
|
-
deltaSize: data.byteLength,
|
|
125
|
-
position,
|
|
126
|
-
totalSize: this.currentSize,
|
|
127
|
-
buffer: data,
|
|
128
|
-
streamUuid: this.streamUuid ?? '', // Generate or manage UUID for stream identification
|
|
129
|
-
};
|
|
130
|
-
this.emit('AudioData', audioEventPayload);
|
|
131
|
-
}
|
|
132
|
-
// Stop recording
|
|
133
|
-
async stopRecording() {
|
|
134
|
-
if (!this.customRecorder) {
|
|
135
|
-
throw new Error('Recorder is not initialized');
|
|
136
|
-
}
|
|
137
|
-
const fullPcmBufferArray = await this.customRecorder.stop();
|
|
138
|
-
// concat all audio chunks
|
|
139
|
-
logger.debug(`Stopped recording`, fullPcmBufferArray);
|
|
140
|
-
this.isRecording = false;
|
|
141
|
-
this.currentDurationMs = Date.now() - this.recordingStartTime;
|
|
142
|
-
const wavConfig = {
|
|
143
|
-
buffer: fullPcmBufferArray.buffer,
|
|
144
|
-
sampleRate: this.recordingConfig?.sampleRate ?? 44100,
|
|
145
|
-
numChannels: this.recordingConfig?.channels ?? 1,
|
|
146
|
-
bitDepth: this.bitDepth,
|
|
147
|
-
};
|
|
148
|
-
logger.debug(`Writing wav header`, wavConfig);
|
|
149
|
-
const wavBuffer = writeWavHeader(wavConfig).slice(0);
|
|
150
|
-
// Create blob fileUri from audio chunks
|
|
151
|
-
const blob = new Blob([wavBuffer], {
|
|
152
|
-
type: `audio/${this.extension}`,
|
|
153
|
-
});
|
|
154
|
-
const fileUri = URL.createObjectURL(blob);
|
|
155
|
-
const result = {
|
|
156
|
-
fileUri,
|
|
157
|
-
filename: `${this.streamUuid}.${this.extension}`,
|
|
158
|
-
wavPCMData: fullPcmBufferArray,
|
|
159
|
-
bitDepth: this.bitDepth,
|
|
160
|
-
channels: this.recordingConfig?.channels ?? 1,
|
|
161
|
-
sampleRate: this.recordingConfig?.sampleRate ?? 44100,
|
|
162
|
-
durationMs: this.currentDurationMs,
|
|
163
|
-
size: this.currentSize,
|
|
164
|
-
mimeType: `audio/${this.extension}`,
|
|
165
|
-
};
|
|
166
|
-
return result;
|
|
167
|
-
}
|
|
168
|
-
// Pause recording
|
|
169
|
-
async pauseRecording() {
|
|
170
|
-
if (!this.isRecording || this.isPaused) {
|
|
171
|
-
throw new Error('Recording is not active or already paused');
|
|
172
|
-
}
|
|
173
|
-
if (this.customRecorder) {
|
|
174
|
-
this.customRecorder.pause();
|
|
175
|
-
}
|
|
176
|
-
this.isPaused = true;
|
|
177
|
-
this.pausedTime = Date.now();
|
|
178
|
-
}
|
|
179
|
-
// Resume recording
|
|
180
|
-
async resumeRecording() {
|
|
181
|
-
if (!this.isPaused) {
|
|
182
|
-
throw new Error('Recording is not paused');
|
|
183
|
-
}
|
|
184
|
-
if (this.customRecorder) {
|
|
185
|
-
this.customRecorder.resume();
|
|
186
|
-
}
|
|
187
|
-
this.isPaused = false;
|
|
188
|
-
this.recordingStartTime += Date.now() - this.pausedTime;
|
|
189
|
-
}
|
|
190
|
-
// Get current status
|
|
191
|
-
status() {
|
|
192
|
-
const status = {
|
|
193
|
-
isRecording: this.isRecording,
|
|
194
|
-
isPaused: this.isPaused,
|
|
195
|
-
durationMs: Date.now() - this.recordingStartTime,
|
|
196
|
-
size: this.currentSize,
|
|
197
|
-
interval: this.currentInterval,
|
|
198
|
-
mimeType: `audio/${this.extension}`,
|
|
199
|
-
};
|
|
200
|
-
return status;
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
//# 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,CAAA;AAUhD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAcvD,MAAM,MAAM,GAAG,SAAS,CAAC,oBAAoB,CAAC,CAAA;AAE9C,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAChD,cAAc,CAAoB;IAClC,WAAW,CAAe;IAC1B,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,kBAAkB,CAAQ;IAC1B,UAAU,CAAQ;IAClB,iBAAiB,CAAQ;IACzB,WAAW,CAAQ;IACnB,eAAe,CAAQ;IACvB,eAAe,CAAQ;IACvB,eAAe,CAAQ;IACvB,UAAU,CAAe;IACzB,SAAS,GAAmB,KAAK,CAAA,CAAC,8BAA8B;IAChE,eAAe,CAAkB;IACjC,QAAQ,CAAU,CAAC,yBAAyB;IAC5C,eAAe,CAAQ;IACvB,mBAAmB,CAAQ;IAE3B,YAAY,EACR,eAAe,EACf,mBAAmB,GACG;QACtB,MAAM,gBAAgB,GAAG;YACrB,WAAW,EAAE,GAAG,EAAE;gBACd,kBAAkB;YACtB,CAAC;YACD,eAAe,EAAE,GAAG,EAAE;gBAClB,kBAAkB;YACtB,CAAC;SACJ,CAAA;QACD,KA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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;SACtC,CAAA;QACD,OAAO,MAAM,CAAA;IACjB,CAAC;CACJ","sourcesContent":["// src/ExpoAudioStreamModule.web.ts\nimport { EventEmitter } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioRecording,\n AudioStreamStatus,\n BitDepth,\n RecordingConfig,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport { WebRecorder } from './WebRecorder.web'\nimport { AudioEventPayload } from './events'\nimport { getLogger } from './logger'\nimport { concatenateBuffers } from './utils/concatenateBuffers'\nimport { encodingToBitDepth } from './utils/encodingToBitDepth'\nimport { writeWavHeader } from './utils/writeWavHeader'\n\nexport interface EmitAudioEventProps {\n data: Float32Array\n position: number\n}\nexport type EmitAudioEventFunction = (_: EmitAudioEventProps) => void\nexport type EmitAudioAnalysisFunction = (_: AudioAnalysis) => 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: () => {\n // Not used on web\n },\n removeListeners: () => {\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 // eslint-disable-next-line @typescript-eslint/ban-ts-comment\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 emitAudioEventCallback: ({\n data,\n position,\n }: 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: AudioAnalysis) => {\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<AudioRecording> {\n if (!this.customRecorder) {\n throw new Error('Recorder is not initialized')\n }\n\n const fullPcmBufferArray = await this.customRecorder.stop()\n\n // concat all audio chunks\n logger.debug(`Stopped recording`, fullPcmBufferArray)\n this.isRecording = false\n this.currentDurationMs = Date.now() - this.recordingStartTime\n\n const wavConfig = {\n buffer: fullPcmBufferArray.buffer,\n sampleRate: this.recordingConfig?.sampleRate ?? 44100,\n numChannels: this.recordingConfig?.channels ?? 1,\n bitDepth: this.bitDepth,\n }\n logger.debug(`Writing wav header`, wavConfig)\n const wavBuffer = writeWavHeader(wavConfig).slice(0)\n\n // Create blob fileUri from audio chunks\n const blob = new Blob([wavBuffer], {\n type: `audio/${this.extension}`,\n })\n const fileUri = URL.createObjectURL(blob)\n\n const result: AudioRecording = {\n fileUri,\n filename: `${this.streamUuid}.${this.extension}`,\n wavPCMData: fullPcmBufferArray,\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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStreamModule.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStreamModule.ts"],"names":[],"mappings":"AASA,QAAA,IAAI,qBAAqB,EAAE,GAAG,CAAA;AAe9B,eAAe,qBAAqB,CAAA"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { requireNativeModule } from 'expo-modules-core';
|
|
2
|
-
import { Platform } from 'react-native';
|
|
3
|
-
import { ExpoAudioStreamWeb, } from './ExpoAudioStream.web';
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
5
|
-
let ExpoAudioStreamModule;
|
|
6
|
-
if (Platform.OS === 'web') {
|
|
7
|
-
let instance = null;
|
|
8
|
-
ExpoAudioStreamModule = ((webProps) => {
|
|
9
|
-
if (!instance) {
|
|
10
|
-
instance = new ExpoAudioStreamWeb(webProps);
|
|
11
|
-
}
|
|
12
|
-
return instance;
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
ExpoAudioStreamModule = requireNativeModule('ExpoAudioStream');
|
|
17
|
-
}
|
|
18
|
-
export default ExpoAudioStreamModule;
|
|
19
|
-
//# 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,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AAEvC,OAAO,EACH,kBAAkB,GAErB,MAAM,uBAAuB,CAAA;AAE9B,8DAA8D;AAC9D,IAAI,qBAA0B,CAAA;AAE9B,IAAI,QAAQ,CAAC,EAAE,KAAK,KAAK,EAAE,CAAC;IACxB,IAAI,QAAQ,GAA8B,IAAI,CAAA;IAE9C,qBAAqB,GAAG,CAAC,CAAC,QAAiC,EAAE,EAAE;QAC3D,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,QAAQ,GAAG,IAAI,kBAAkB,CAAC,QAAQ,CAAC,CAAA;QAC/C,CAAC;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC,CAAC,CAAA;AACN,CAAC;KAAM,CAAC;IACJ,qBAAqB,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAA;AAClE,CAAC;AAED,eAAe,qBAAqB,CAAA","sourcesContent":["import { requireNativeModule } from 'expo-modules-core'\nimport { Platform } from 'react-native'\n\nimport {\n ExpoAudioStreamWeb,\n ExpoAudioStreamWebProps,\n} from './ExpoAudioStream.web'\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\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"]}
|