@steelbrain/media-buffer-speech
Version:
Speech buffering that accumulates audio chunks and releases them after natural pause periods
57 lines • 2.3 kB
text/typescript
/**
* Configuration options for pause detection
*/
export interface BufferSpeechOptions {
/** Duration in seconds to wait for pause before releasing buffer. Default: 2.0 */
durationSeconds?: number;
/** Maximum buffer duration in seconds before triggering overflow warning. Default: 60.0 */
maxBufferSeconds?: number;
/** Called when buffer overflow or other errors occur */
onError?: (error: Error) => void;
/** Called for debug information and internal state logging */
onDebugLog?: (message: string) => void;
/** If true, don't emit buffered chunks downstream. Only trigger onBuffered callback. Default: false */
noEmit?: boolean;
/** Called when buffer is ready to be processed (after pause detected). Use with noEmit for .tee() patterns */
onBuffered?: () => void;
}
/**
* Creates a TransformStream that buffers incoming chunks and releases them
* after a configurable pause period with no new data.
*
* Perfect for detecting natural break points in continuous streams like speech.
*
* @example
* ```typescript
* // Wait for 2-second pause before processing
* const pauseDetector = bufferSpeech({
* durationSeconds: 2.0,
* maxBufferSeconds: 60.0,
* onError: (err) => console.error('Buffer overflow:', err)
* });
*
* await audioStream
* .pipeThrough(speechFilter()) // Filter for speech
* .pipeThrough(pauseDetector) // Wait for natural pauses
* .pipeTo(transcriptionProcessor); // Process complete segments
*
* // .tee() pattern for live transcription with turn detection
* const [liveStream, turnStream] = audioStream.tee();
*
* // Branch 1: Live transcription
* liveStream.pipeThrough(speechFilter()).pipeTo(liveTranscriber);
*
* // Branch 2: Turn detection signaling
* const turnDetector = bufferSpeech({
* durationSeconds: 3.0,
* noEmit: true, // Don't emit chunks
* onBuffered: () => { // Signal when turn is complete
* console.log('Turn complete - process accumulated transcript');
* processAccumulatedTranscript();
* }
* });
* turnStream.pipeThrough(speechFilter()).pipeThrough(turnDetector);
* ```
*/
export declare function bufferSpeech<T>(options?: BufferSpeechOptions): TransformStream<T, T[]>;
//# sourceMappingURL=index.d.ts.map