import EE from 'eventemitter3'; export interface SpectrogramData { /** * The float32 data for the spectrogram. * * Stored frame by frame. For example, the first N elements * belong to the first time frame and the next N elements belong * to the second time frame, and so forth. */ data: Float32Array; /** * Number of points per frame, i.e., FFT length per frame. */ frameSize: number; /** * Duration of each frame in milliseconds. */ frameDurationMillis?: number; /** * Index to the key frame (0-based). * * A key frame is a frame in the spectrogram that belongs to * the utterance of interest. It is used to distinguish the * utterance part from the background-noise part. * * A typical use of key frame index: when multiple training examples are * extracted from a spectroram, every example is guaranteed to include * the key frame. * * Key frame is not required. If it is missing, heuristics algorithms * (e.g., finding the highest-intensity frame) can be used to calculate * the key frame. */ keyFrameIndex?: number; } export interface RawAudioData { /** Samples of the snippet. */ data: Float32Array; /** Sampling rate, in Hz. */ sampleRateHz: number; } export interface AudioExample { /** A label for the example. */ label: string; /** Spectrogram data. */ spectrogram: SpectrogramData; /** * A 224x224 heatmap image of this 1-second spectrogram example. */ spectrogramCanvas?: HTMLCanvasElement; /** * Raw audio in PCM (pulse-code modulation) format. * * Optional. */ rawAudio?: RawAudioData; } export interface RecordingProgress { progress: number; elapsedTimeMillis: number; } declare type SoundRecorderEvents = 'example' | 'update' | 'start' | 'stop' | 'error'; export interface RecordExampleOptions { /** The size of each frame in the spectrogram, i.e., the FFT length. */ frameSize: number; /** * Whether to include raw audio data in the example. * * Default: false. */ includeRawAudio?: boolean; durationMillis?: number; /** Sampling rate of the raw audio data, in Hz. */ sampleRateHz: number; /** * Optional initial warmup period (ms). * During this period, no examples are emitted, but visualization continues. * * Default: 0. */ warmupMillis?: number; columnTruncateLength?: number; overlapFactor?: number; includeCanvas?: boolean; deviceId?: string; } export default class SoundRecorder extends EE { canvas: HTMLCanvasElement | null; private stream; private audioContext; private analyser; private source; private frameIntervalTask; private audioElement; private isRecording; private stopRequested; private allFreqFrames; private lastRenderTime; private lastMainDrawWidth; private currentFrameDurationMillis; private currentSampleRateHz; private lastEmitTime; private startTime; private includeRawAudioCapture; private mediaRecorder; private sourceAudioBlob; private pendingExamples; private isFinishing; private startRawAudioCapture; private stopRawAudioCapture; private decodeBlobToMonoPcm; private sliceRawAudioAndPatchExamples; private finish; private emitOneSecondExample; private createFromStream; private createFromBlob; startRecording(word: string, options: RecordExampleOptions, blob?: Blob): Promise; stopRecording(): void; private renderSpectrogram; } export {};