@siteed/expo-audio-studio
Version:
Comprehensive audio processing library for React Native and Expo with recording, analysis, visualization, and streaming capabilities across iOS, Android, and web
119 lines • 4.41 kB
TypeScript
import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types';
import { ConsoleLike, RecordingConfig } from './ExpoAudioStream.types';
import { EmitAudioAnalysisFunction, EmitAudioEventFunction } from './ExpoAudioStream.web';
interface AudioFeaturesEvent {
data: {
command: string;
result: AudioAnalysis;
};
}
export declare class WebRecorder {
private audioContext;
private audioWorkletNode;
private featureExtractorWorker?;
private source;
private emitAudioEventCallback;
private emitAudioAnalysisCallback;
private config;
private position;
private numberOfChannels;
private bitDepth;
private exportBitDepth;
private audioAnalysisData;
private packetCount;
private logger?;
private compressedMediaRecorder;
private compressedChunks;
private compressedSize;
private pendingCompressedChunk;
private readonly wavMimeType;
private dataPointIdCounter;
/**
* Initializes a new WebRecorder instance for audio recording and processing
* @param audioContext - The AudioContext to use for recording
* @param source - The MediaStreamAudioSourceNode providing the audio input
* @param recordingConfig - Configuration options for the recording
* @param emitAudioEventCallback - Callback function for audio data events
* @param emitAudioAnalysisCallback - Callback function for audio analysis events
* @param logger - Optional logger for debugging information
*/
constructor({ audioContext, source, recordingConfig, emitAudioEventCallback, emitAudioAnalysisCallback, logger, }: {
audioContext: AudioContext;
source: MediaStreamAudioSourceNode;
recordingConfig: RecordingConfig;
emitAudioEventCallback: EmitAudioEventFunction;
emitAudioAnalysisCallback: EmitAudioAnalysisFunction;
logger?: ConsoleLike;
});
/**
* Initializes the audio worklet using an inline script
* Creates and connects the audio processing pipeline
*/
init(): Promise<void>;
/**
* Initializes the feature extractor worker for audio analysis
* Creates an inline worker from a blob for audio feature extraction
*/
initFeatureExtractorWorker(): void;
/**
* Processes audio analysis results from the feature extractor worker
* Updates the audio analysis data and emits events
* @param event - The event containing audio analysis results
*/
handleFeatureExtractorMessage(event: AudioFeaturesEvent): void;
/**
* Resets the data point ID counter
* Used when starting a new recording
*/
resetDataPointCounter(): void;
/**
* Starts the audio recording process
* Connects the audio nodes and begins capturing audio data
*/
start(): void;
/**
* Stops the audio recording process and returns the recorded data
* @returns Promise resolving to an object containing PCM data and optional compressed blob
*/
stop(): Promise<{
pcmData: Float32Array;
compressedBlob?: Blob;
}>;
/**
* Cleans up resources when recording is stopped
* Closes audio context and disconnects nodes
*/
private cleanup;
/**
* Pauses the audio recording process
* Disconnects audio nodes and pauses the media recorder
*/
pause(): void;
/**
* Stops all media stream tracks to release hardware resources
* Ensures recording indicators (like microphone icon) are turned off
*/
stopMediaStreamTracks(): void;
/**
* Determines the audio format capabilities of the current audio context
* @param sampleRate - The sample rate to check
* @returns Object containing format information (sample rate, bit depth, channels)
*/
private checkAudioContextFormat;
/**
* Resumes a paused recording
* Reconnects audio nodes and resumes the media recorder
*/
resume(): void;
/**
* Initializes the compressed media recorder if compression is enabled
* Sets up event handlers for compressed audio data
*/
private initializeCompressedRecorder;
/**
* Processes features if enabled
*/
processFeatures(chunk: Float32Array, sampleRate: number, chunkPosition: number, startPosition: number, endPosition: number, samples: number): void;
}
export {};
//# sourceMappingURL=WebRecorder.web.d.ts.map