@siteed/expo-audio-stream 1.0.2 → 1.0.5
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/.size-limit.json +6 -0
- package/README.md +18 -176
- package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
- package/app.plugin.js +1 -1
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +74 -0
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
- package/build/AudioAnalysis/AudioAnalysis.types.js +3 -0
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +20 -0
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
- package/build/AudioAnalysis/extractAudioAnalysis.js +88 -0
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
- package/build/AudioAnalysis/extractWaveform.d.ts +8 -0
- package/build/AudioAnalysis/extractWaveform.d.ts.map +1 -0
- package/build/AudioAnalysis/extractWaveform.js +14 -0
- package/build/AudioAnalysis/extractWaveform.js.map +1 -0
- package/build/AudioRecorder.provider.d.ts +15 -2
- package/build/AudioRecorder.provider.d.ts.map +1 -1
- package/build/AudioRecorder.provider.js +21 -8
- package/build/AudioRecorder.provider.js.map +1 -1
- package/build/ExpoAudioStream.native.d.ts.map +1 -1
- package/build/ExpoAudioStream.native.js +2 -2
- package/build/ExpoAudioStream.native.js.map +1 -1
- package/build/ExpoAudioStream.types.d.ts +33 -89
- package/build/ExpoAudioStream.types.d.ts.map +1 -1
- package/build/ExpoAudioStream.types.js.map +1 -1
- package/build/ExpoAudioStream.web.d.ts +10 -9
- package/build/ExpoAudioStream.web.d.ts.map +1 -1
- package/build/ExpoAudioStream.web.js +44 -25
- package/build/ExpoAudioStream.web.js.map +1 -1
- package/build/ExpoAudioStreamModule.d.ts.map +1 -1
- package/build/ExpoAudioStreamModule.js +13 -8
- package/build/ExpoAudioStreamModule.js.map +1 -1
- package/build/{WebRecorder.d.ts → WebRecorder.web.d.ts} +13 -9
- package/build/WebRecorder.web.d.ts.map +1 -0
- package/build/{WebRecorder.js → WebRecorder.web.js} +118 -63
- package/build/WebRecorder.web.js.map +1 -0
- package/build/constants.d.ts +11 -0
- package/build/constants.d.ts.map +1 -0
- package/build/constants.js +14 -0
- package/build/constants.js.map +1 -0
- package/build/events.d.ts +18 -0
- package/build/events.d.ts.map +1 -0
- package/build/events.js +15 -0
- package/build/events.js.map +1 -0
- package/build/index.d.ts +9 -17
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -113
- package/build/index.js.map +1 -1
- package/build/logger.d.ts +9 -0
- package/build/logger.d.ts.map +1 -0
- package/build/logger.js +13 -0
- package/build/logger.js.map +1 -0
- package/build/useAudioRecorder.d.ts +20 -0
- package/build/useAudioRecorder.d.ts.map +1 -0
- package/build/{useAudioRecording.js → useAudioRecorder.js} +90 -86
- package/build/useAudioRecorder.js.map +1 -0
- package/build/utils/BlobFix.d.ts +9 -0
- package/build/utils/BlobFix.d.ts.map +1 -0
- package/build/utils/BlobFix.js +494 -0
- package/build/utils/BlobFix.js.map +1 -0
- package/build/utils/concatenateBuffers.d.ts +8 -0
- package/build/utils/concatenateBuffers.d.ts.map +1 -0
- package/build/utils/concatenateBuffers.js +21 -0
- package/build/utils/concatenateBuffers.js.map +1 -0
- package/build/utils/convertPCMToFloat32.d.ts +11 -0
- package/build/utils/convertPCMToFloat32.d.ts.map +1 -0
- package/build/utils/convertPCMToFloat32.js +54 -0
- package/build/utils/convertPCMToFloat32.js.map +1 -0
- package/build/utils/encodingToBitDepth.d.ts +5 -0
- package/build/utils/encodingToBitDepth.d.ts.map +1 -0
- package/build/utils/encodingToBitDepth.js +13 -0
- package/build/utils/encodingToBitDepth.js.map +1 -0
- package/build/utils/getWavFileInfo.d.ts +26 -0
- package/build/utils/getWavFileInfo.d.ts.map +1 -0
- package/build/utils/getWavFileInfo.js +92 -0
- package/build/utils/getWavFileInfo.js.map +1 -0
- package/build/utils/writeWavHeader.d.ts +9 -0
- package/build/utils/writeWavHeader.d.ts.map +1 -0
- package/build/utils/writeWavHeader.js +41 -0
- package/build/utils/writeWavHeader.js.map +1 -0
- package/build/workers/InlineFeaturesExtractor.web.d.ts +2 -0
- package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
- package/build/workers/InlineFeaturesExtractor.web.js +303 -0
- package/build/workers/InlineFeaturesExtractor.web.js.map +1 -0
- package/build/workers/inlineAudioWebWorker.web.d.ts +2 -0
- package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
- package/build/workers/inlineAudioWebWorker.web.js +243 -0
- package/build/workers/inlineAudioWebWorker.web.js.map +1 -0
- package/expo-module.config.json +8 -17
- package/ios/AudioStreamManager.swift +40 -2
- package/ios/ExpoAudioStreamModule.swift +11 -0
- package/ios/RecordingResult.swift +1 -0
- package/package.json +72 -64
- package/plugin/build/index.d.ts +1 -1
- package/plugin/build/index.js +7 -7
- package/plugin/src/index.ts +47 -47
- package/plugin/tsconfig.json +8 -13
- package/publish.sh +0 -0
- package/src/AudioAnalysis/AudioAnalysis.types.ts +84 -0
- package/src/AudioAnalysis/extractAudioAnalysis.ts +147 -0
- package/src/AudioAnalysis/extractWaveform.ts +25 -0
- package/src/AudioRecorder.provider.tsx +59 -31
- package/src/ExpoAudioStream.native.ts +2 -2
- package/src/ExpoAudioStream.types.ts +58 -116
- package/src/ExpoAudioStream.web.ts +233 -205
- package/src/ExpoAudioStreamModule.ts +18 -12
- package/src/WebRecorder.web.ts +433 -0
- package/src/constants.ts +18 -0
- package/src/events.ts +39 -0
- package/src/index.ts +15 -176
- package/src/logger.ts +23 -0
- package/src/useAudioRecorder.tsx +420 -0
- package/src/utils/BlobFix.ts +550 -0
- package/src/utils/concatenateBuffers.ts +24 -0
- package/src/utils/convertPCMToFloat32.ts +75 -0
- package/src/utils/encodingToBitDepth.ts +18 -0
- package/src/utils/getWavFileInfo.ts +132 -0
- package/src/utils/writeWavHeader.ts +56 -0
- package/src/workers/InlineFeaturesExtractor.web.tsx +302 -0
- package/src/workers/inlineAudioWebWorker.web.tsx +242 -0
- package/tsconfig.json +12 -7
- package/build/WebRecorder.d.ts.map +0 -1
- package/build/WebRecorder.js.map +0 -1
- package/build/inlineAudioWebWorker.d.ts +0 -3
- package/build/inlineAudioWebWorker.d.ts.map +0 -1
- package/build/inlineAudioWebWorker.js +0 -340
- package/build/inlineAudioWebWorker.js.map +0 -1
- package/build/useAudioRecording.d.ts +0 -38
- package/build/useAudioRecording.d.ts.map +0 -1
- package/build/useAudioRecording.js.map +0 -1
- package/build/utils.d.ts +0 -31
- package/build/utils.d.ts.map +0 -1
- package/build/utils.js +0 -143
- package/build/utils.js.map +0 -1
- package/src/WebRecorder.ts +0 -364
- package/src/inlineAudioWebWorker.tsx +0 -340
- package/src/useAudioRecording.tsx +0 -410
- package/src/utils.ts +0 -189
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
buffer?: ArrayBuffer;
|
|
4
|
-
fileUri: string;
|
|
5
|
-
lastEmittedSize: number;
|
|
6
|
-
position: number;
|
|
7
|
-
deltaSize: number;
|
|
8
|
-
totalSize: number;
|
|
9
|
-
mimeType: string;
|
|
10
|
-
streamUuid: string;
|
|
11
|
-
}
|
|
12
|
-
export interface AudioStreamResult {
|
|
13
|
-
fileUri: string;
|
|
14
|
-
webAudioUri?: string;
|
|
15
|
-
durationMs: number;
|
|
16
|
-
size: number;
|
|
17
|
-
mimeType: string;
|
|
18
|
-
channels?: number;
|
|
19
|
-
bitDepth?: number;
|
|
20
|
-
sampleRate?: number;
|
|
21
|
-
}
|
|
22
|
-
export interface StartAudioStreamResult {
|
|
23
|
-
fileUri: string;
|
|
24
|
-
mimeType: string;
|
|
25
|
-
channels?: number;
|
|
26
|
-
bitDepth?: number;
|
|
27
|
-
sampleRate?: number;
|
|
28
|
-
}
|
|
1
|
+
import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions } from './AudioAnalysis/AudioAnalysis.types';
|
|
2
|
+
import { AudioAnalysisEvent } from './events';
|
|
29
3
|
export interface AudioStreamStatus {
|
|
30
4
|
isRecording: boolean;
|
|
31
5
|
isPaused: boolean;
|
|
@@ -35,84 +9,54 @@ export interface AudioStreamStatus {
|
|
|
35
9
|
mimeType: string;
|
|
36
10
|
}
|
|
37
11
|
export interface AudioDataEvent {
|
|
38
|
-
data: string |
|
|
12
|
+
data: string | Float32Array;
|
|
39
13
|
position: number;
|
|
40
14
|
fileUri: string;
|
|
41
15
|
eventDataSize: number;
|
|
42
16
|
totalSize: number;
|
|
43
17
|
}
|
|
44
|
-
export
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
zcr: number;
|
|
51
|
-
spectralCentroid: number;
|
|
52
|
-
spectralFlatness: number;
|
|
53
|
-
spectralRolloff: number;
|
|
54
|
-
spectralBandwidth: number;
|
|
55
|
-
chromagram: number[];
|
|
56
|
-
tempo: number;
|
|
57
|
-
hnr: number;
|
|
58
|
-
}
|
|
59
|
-
export interface AudioFeaturesOptions {
|
|
60
|
-
energy?: boolean;
|
|
61
|
-
mfcc?: boolean;
|
|
62
|
-
rms?: boolean;
|
|
63
|
-
zcr?: boolean;
|
|
64
|
-
spectralCentroid?: boolean;
|
|
65
|
-
spectralFlatness?: boolean;
|
|
66
|
-
spectralRolloff?: boolean;
|
|
67
|
-
spectralBandwidth?: boolean;
|
|
68
|
-
chromagram?: boolean;
|
|
69
|
-
tempo?: boolean;
|
|
70
|
-
hnr?: boolean;
|
|
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];
|
|
71
24
|
}
|
|
72
|
-
export interface
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
dB?: number;
|
|
77
|
-
silent?: boolean;
|
|
78
|
-
features?: AudioFeatures;
|
|
79
|
-
startTime?: number;
|
|
80
|
-
endTime?: number;
|
|
81
|
-
startPosition?: number;
|
|
82
|
-
endPosition?: number;
|
|
83
|
-
samples?: number;
|
|
84
|
-
speaker?: number;
|
|
25
|
+
export interface TranscriberData {
|
|
26
|
+
isBusy: boolean;
|
|
27
|
+
text: string;
|
|
28
|
+
chunks: Chunk[];
|
|
85
29
|
}
|
|
86
|
-
export interface
|
|
87
|
-
|
|
30
|
+
export interface AudioRecording {
|
|
31
|
+
fileUri: string;
|
|
32
|
+
filename: string;
|
|
88
33
|
durationMs: number;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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;
|
|
102
49
|
}
|
|
103
|
-
export type EncodingType = "pcm_32bit" | "pcm_16bit" | "pcm_8bit";
|
|
104
|
-
export type SampleRate = 16000 | 44100 | 48000;
|
|
105
50
|
export interface RecordingConfig {
|
|
106
51
|
sampleRate?: SampleRate;
|
|
107
52
|
channels?: 1 | 2;
|
|
108
53
|
encoding?: EncodingType;
|
|
109
54
|
interval?: number;
|
|
110
|
-
maxRecentDataDuration?: number;
|
|
111
55
|
enableProcessing?: boolean;
|
|
112
56
|
pointsPerSecond?: number;
|
|
113
|
-
algorithm?:
|
|
57
|
+
algorithm?: AmplitudeAlgorithm;
|
|
114
58
|
features?: AudioFeaturesOptions;
|
|
115
59
|
onAudioStream?: (_: AudioDataEvent) => Promise<void>;
|
|
116
|
-
|
|
60
|
+
onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>;
|
|
117
61
|
}
|
|
118
62
|
//# sourceMappingURL=ExpoAudioStream.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.types.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"
|
|
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,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AE,oBAAoB,CAAA;IAE/B,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,eAAe,CAAC,EAAE,CAAC,CAAC,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
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 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,12 +1,13 @@
|
|
|
1
|
-
import { EventEmitter } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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';
|
|
4
5
|
export interface EmitAudioEventProps {
|
|
5
|
-
data:
|
|
6
|
+
data: Float32Array;
|
|
6
7
|
position: number;
|
|
7
8
|
}
|
|
8
9
|
export type EmitAudioEventFunction = (_: EmitAudioEventProps) => void;
|
|
9
|
-
export type EmitAudioAnalysisFunction = (_:
|
|
10
|
+
export type EmitAudioAnalysisFunction = (_: AudioAnalysis) => void;
|
|
10
11
|
export interface ExpoAudioStreamWebProps {
|
|
11
12
|
audioWorkletUrl: string;
|
|
12
13
|
featuresExtratorUrl: string;
|
|
@@ -24,16 +25,16 @@ export declare class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
24
25
|
lastEmittedSize: number;
|
|
25
26
|
lastEmittedTime: number;
|
|
26
27
|
streamUuid: string | null;
|
|
27
|
-
extension:
|
|
28
|
+
extension: 'webm' | 'wav';
|
|
28
29
|
recordingConfig?: RecordingConfig;
|
|
29
|
-
bitDepth:
|
|
30
|
+
bitDepth: BitDepth;
|
|
30
31
|
audioWorkletUrl: string;
|
|
31
32
|
featuresExtratorUrl: string;
|
|
32
33
|
constructor({ audioWorkletUrl, featuresExtratorUrl, }: ExpoAudioStreamWebProps);
|
|
33
34
|
getMediaStream(): Promise<MediaStream>;
|
|
34
|
-
startRecording(recordingConfig?: RecordingConfig): Promise<
|
|
35
|
+
startRecording(recordingConfig?: RecordingConfig): Promise<StartRecordingResult>;
|
|
35
36
|
emitAudioEvent({ data, position }: EmitAudioEventProps): void;
|
|
36
|
-
stopRecording(): Promise<
|
|
37
|
+
stopRecording(): Promise<AudioRecording>;
|
|
37
38
|
pauseRecording(): Promise<void>;
|
|
38
39
|
resumeRecording(): Promise<void>;
|
|
39
40
|
status(): AudioStreamStatus;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.web.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.web.ts"],"names":[],"mappings":"
|
|
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,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
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');
|
|
6
8
|
export class ExpoAudioStreamWeb extends EventEmitter {
|
|
7
9
|
customRecorder;
|
|
8
10
|
audioChunks;
|
|
@@ -16,17 +18,17 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
16
18
|
lastEmittedSize;
|
|
17
19
|
lastEmittedTime;
|
|
18
20
|
streamUuid;
|
|
19
|
-
extension =
|
|
21
|
+
extension = 'wav'; // Default extension is 'webm'
|
|
20
22
|
recordingConfig;
|
|
21
23
|
bitDepth; // Bit depth of the audio
|
|
22
24
|
audioWorkletUrl;
|
|
23
25
|
featuresExtratorUrl;
|
|
24
26
|
constructor({ audioWorkletUrl, featuresExtratorUrl, }) {
|
|
25
27
|
const mockNativeModule = {
|
|
26
|
-
addListener: (
|
|
28
|
+
addListener: () => {
|
|
27
29
|
// Not used on web
|
|
28
30
|
},
|
|
29
|
-
removeListeners: (
|
|
31
|
+
removeListeners: () => {
|
|
30
32
|
// Not used on web
|
|
31
33
|
},
|
|
32
34
|
};
|
|
@@ -53,19 +55,20 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
53
55
|
return await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
54
56
|
}
|
|
55
57
|
catch (error) {
|
|
56
|
-
console.error(
|
|
58
|
+
console.error('Failed to get media stream:', error);
|
|
57
59
|
throw error;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
// Start recording with options
|
|
61
63
|
async startRecording(recordingConfig = {}) {
|
|
62
64
|
if (this.isRecording) {
|
|
63
|
-
throw new Error(
|
|
65
|
+
throw new Error('Recording is already in progress');
|
|
64
66
|
}
|
|
65
67
|
this.bitDepth = encodingToBitDepth({
|
|
66
|
-
encoding: recordingConfig.encoding ??
|
|
68
|
+
encoding: recordingConfig.encoding ?? 'pcm_32bit',
|
|
67
69
|
});
|
|
68
70
|
const audioContext = new (window.AudioContext ||
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
69
72
|
// @ts-ignore - Allow webkitAudioContext for Safari
|
|
70
73
|
window.webkitAudioContext)();
|
|
71
74
|
const stream = await this.getMediaStream();
|
|
@@ -75,8 +78,7 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
75
78
|
source,
|
|
76
79
|
recordingConfig,
|
|
77
80
|
audioWorkletUrl: this.audioWorkletUrl,
|
|
78
|
-
|
|
79
|
-
emitAudioEventCallback: ({ data, position }) => {
|
|
81
|
+
emitAudioEventCallback: ({ data, position, }) => {
|
|
80
82
|
this.audioChunks.push(data);
|
|
81
83
|
this.currentSize += data.byteLength;
|
|
82
84
|
this.emitAudioEvent({ data, position });
|
|
@@ -84,15 +86,15 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
84
86
|
this.lastEmittedSize = this.currentSize;
|
|
85
87
|
},
|
|
86
88
|
emitAudioAnalysisCallback: (audioAnalysisData) => {
|
|
87
|
-
|
|
88
|
-
this.emit(
|
|
89
|
+
logger.log(`Emitted AudioAnalysis:`, audioAnalysisData);
|
|
90
|
+
this.emit('AudioAnalysis', audioAnalysisData);
|
|
89
91
|
},
|
|
90
92
|
});
|
|
91
93
|
await this.customRecorder.init();
|
|
92
94
|
this.customRecorder.start();
|
|
93
95
|
// // Set a timer to stop recording after 5 seconds
|
|
94
96
|
// setTimeout(() => {
|
|
95
|
-
//
|
|
97
|
+
// logger.log("AUTO Stopping recording");
|
|
96
98
|
// this.customRecorder?.stopAndPlay();
|
|
97
99
|
// this.isRecording = false;
|
|
98
100
|
// }, 3000);
|
|
@@ -123,20 +125,37 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
123
125
|
position,
|
|
124
126
|
totalSize: this.currentSize,
|
|
125
127
|
buffer: data,
|
|
126
|
-
streamUuid: this.streamUuid ??
|
|
128
|
+
streamUuid: this.streamUuid ?? '', // Generate or manage UUID for stream identification
|
|
127
129
|
};
|
|
128
|
-
this.emit(
|
|
130
|
+
this.emit('AudioData', audioEventPayload);
|
|
129
131
|
}
|
|
130
132
|
// Stop recording
|
|
131
133
|
async stopRecording() {
|
|
132
|
-
if (this.customRecorder) {
|
|
133
|
-
|
|
134
|
-
log.debug(`Stopped recording`, fullPcmBuffer);
|
|
134
|
+
if (!this.customRecorder) {
|
|
135
|
+
throw new Error('Recorder is not initialized');
|
|
135
136
|
}
|
|
137
|
+
const fullPcmBufferArray = await this.customRecorder.stop();
|
|
138
|
+
// concat all audio chunks
|
|
139
|
+
logger.debug(`Stopped recording`, fullPcmBufferArray);
|
|
136
140
|
this.isRecording = false;
|
|
137
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);
|
|
138
155
|
const result = {
|
|
139
|
-
fileUri
|
|
156
|
+
fileUri,
|
|
157
|
+
filename: `${this.streamUuid}.${this.extension}`,
|
|
158
|
+
wavPCMData: fullPcmBufferArray,
|
|
140
159
|
bitDepth: this.bitDepth,
|
|
141
160
|
channels: this.recordingConfig?.channels ?? 1,
|
|
142
161
|
sampleRate: this.recordingConfig?.sampleRate ?? 44100,
|
|
@@ -149,10 +168,10 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
149
168
|
// Pause recording
|
|
150
169
|
async pauseRecording() {
|
|
151
170
|
if (!this.isRecording || this.isPaused) {
|
|
152
|
-
throw new Error(
|
|
171
|
+
throw new Error('Recording is not active or already paused');
|
|
153
172
|
}
|
|
154
173
|
if (this.customRecorder) {
|
|
155
|
-
this.customRecorder.
|
|
174
|
+
this.customRecorder.pause();
|
|
156
175
|
}
|
|
157
176
|
this.isPaused = true;
|
|
158
177
|
this.pausedTime = Date.now();
|
|
@@ -160,7 +179,7 @@ export class ExpoAudioStreamWeb extends EventEmitter {
|
|
|
160
179
|
// Resume recording
|
|
161
180
|
async resumeRecording() {
|
|
162
181
|
if (!this.isPaused) {
|
|
163
|
-
throw new Error(
|
|
182
|
+
throw new Error('Recording is not paused');
|
|
164
183
|
}
|
|
165
184
|
if (this.customRecorder) {
|
|
166
185
|
this.customRecorder.resume();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.web.js","sourceRoot":"","sources":["../src/ExpoAudioStream.web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAc7C,4DAA4D;AAC5D,MAAM,GAAG,GAAG,OAAO,CAAC;AACpB,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,CAAS,CAAC,yBAAyB;IAC3C,eA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,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC/D,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,IAAI,CAAC,cAAc,CAAC,IAAI,EAAE,CAAC;QAC7B,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 debug from \"debug\";\nimport { EventEmitter } from \"expo-modules-core\";\n\nimport {\n AudioAnalysisData,\n AudioEventPayload,\n AudioStreamResult,\n AudioStreamStatus,\n RecordingConfig,\n StartAudioStreamResult,\n} from \"./ExpoAudioStream.types\";\nimport { WebRecorder } from \"./WebRecorder\";\nimport { encodingToBitDepth } from \"./utils\";\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\n// const log = debug(\"expo-audio-stream:useAudioRecording\");\nconst log = console;\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: number; // 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 console.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 // console.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: StartAudioStreamResult = {\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<AudioStreamResult | null> {\n if (this.customRecorder) {\n const fullPcmBuffer = await this.customRecorder.stop();\n log.debug(`Stopped recording`, fullPcmBuffer);\n }\n this.isRecording = false;\n this.currentDurationMs = Date.now() - this.recordingStartTime;\n const result: AudioStreamResult = {\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.stop();\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
|
+
{"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,WAA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AAW,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAChE,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAA;QAC/B,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;IAChC,CAAC;IAED,mBAAmB;IACnB,KAAK,CAAC,eAAe;QACjB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACjB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;QAC9C,CAAC;QAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACtB,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE,CAAA;QAChC,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QACrB,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,UAAU,CAAA;IAC3D,CAAC;IAED,qBAAqB;IACrB,MAAM;QACF,MAAM,MAAM,GAAsB;YAC9B,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;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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStreamModule.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStreamModule.ts"],"names":[],"mappings":"
|
|
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,14 +1,19 @@
|
|
|
1
|
-
import { requireNativeModule } from
|
|
2
|
-
import { Platform } from
|
|
3
|
-
import { ExpoAudioStreamWeb, } from
|
|
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
|
|
4
5
|
let ExpoAudioStreamModule;
|
|
5
|
-
if (Platform.OS ===
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
});
|
|
9
14
|
}
|
|
10
15
|
else {
|
|
11
|
-
ExpoAudioStreamModule = requireNativeModule(
|
|
16
|
+
ExpoAudioStreamModule = requireNativeModule('ExpoAudioStream');
|
|
12
17
|
}
|
|
13
18
|
export default ExpoAudioStreamModule;
|
|
14
19
|
//# sourceMappingURL=ExpoAudioStreamModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStreamModule.js","sourceRoot":"","sources":["../src/ExpoAudioStreamModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,
|
|
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"]}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
|
|
2
|
+
import { RecordingConfig } from './ExpoAudioStream.types';
|
|
3
|
+
import { EmitAudioAnalysisFunction, EmitAudioEventFunction } from './ExpoAudioStream.web';
|
|
3
4
|
interface AudioFeaturesEvent {
|
|
4
5
|
data: {
|
|
5
6
|
command: string;
|
|
6
|
-
result:
|
|
7
|
+
result: AudioAnalysis;
|
|
7
8
|
};
|
|
8
9
|
}
|
|
9
10
|
export declare class WebRecorder {
|
|
10
11
|
private audioContext;
|
|
11
12
|
private audioWorkletNode;
|
|
12
|
-
private featureExtractorWorker
|
|
13
|
+
private featureExtractorWorker?;
|
|
13
14
|
private source;
|
|
14
15
|
private audioWorkletUrl;
|
|
15
16
|
private emitAudioEventCallback;
|
|
@@ -19,21 +20,24 @@ export declare class WebRecorder {
|
|
|
19
20
|
private numberOfChannels;
|
|
20
21
|
private bitDepth;
|
|
21
22
|
private exportBitDepth;
|
|
22
|
-
private
|
|
23
|
+
private buffer;
|
|
24
|
+
private bufferSize;
|
|
23
25
|
private audioAnalysisData;
|
|
24
|
-
constructor({ audioContext, source, recordingConfig,
|
|
26
|
+
constructor({ audioContext, source, recordingConfig, audioWorkletUrl, emitAudioEventCallback, emitAudioAnalysisCallback, }: {
|
|
25
27
|
audioContext: AudioContext;
|
|
26
28
|
source: MediaStreamAudioSourceNode;
|
|
27
29
|
recordingConfig: RecordingConfig;
|
|
28
|
-
featuresExtratorUrl: string;
|
|
29
30
|
audioWorkletUrl: string;
|
|
30
31
|
emitAudioEventCallback: EmitAudioEventFunction;
|
|
31
32
|
emitAudioAnalysisCallback: EmitAudioAnalysisFunction;
|
|
32
33
|
});
|
|
33
34
|
init(): Promise<void>;
|
|
35
|
+
initFeatureExtractorWorker(featuresExtratorUrl?: string): void;
|
|
36
|
+
initFallbackWorker(): void;
|
|
37
|
+
handleWorkerError(error: ErrorEvent): void;
|
|
34
38
|
handleFeatureExtractorMessage(event: AudioFeaturesEvent): void;
|
|
35
39
|
start(): void;
|
|
36
|
-
stop(): Promise<
|
|
40
|
+
stop(): Promise<Float32Array>;
|
|
37
41
|
pause(): void;
|
|
38
42
|
stopMediaStreamTracks(): void;
|
|
39
43
|
playRecordedData({ recordedData, }: {
|
|
@@ -44,4 +48,4 @@ export declare class WebRecorder {
|
|
|
44
48
|
resume(): void;
|
|
45
49
|
}
|
|
46
50
|
export {};
|
|
47
|
-
//# sourceMappingURL=WebRecorder.d.ts.map
|
|
51
|
+
//# sourceMappingURL=WebRecorder.web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebRecorder.web.d.ts","sourceRoot":"","sources":["../src/WebRecorder.web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AACnE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACzD,OAAO,EACH,yBAAyB,EACzB,sBAAsB,EACzB,MAAM,uBAAuB,CAAA;AAc9B,UAAU,kBAAkB;IACxB,IAAI,EAAE;QACF,OAAO,EAAE,MAAM,CAAA;QACf,MAAM,EAAE,aAAa,CAAA;KACxB,CAAA;CACJ;AAWD,qBAAa,WAAW;IACpB,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,gBAAgB,CAAmB;IAC3C,OAAO,CAAC,sBAAsB,CAAC,CAAQ;IACvC,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,eAAe,CAAQ;IAC/B,OAAO,CAAC,sBAAsB,CAAwB;IACtD,OAAO,CAAC,yBAAyB,CAA2B;IAC5D,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,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