speech_segment_buffer
A buffer that keeps one stretch of speech, with the audio just before it.
- class pipecat.audio.speech_segment_buffer.SpeechSegmentBuffer(*, pre_speech_secs: float = 1.0, max_secs: float | None = None)[source]
Bases:
objectKeeps the audio of one stretch of speech, with the audio just before it.
Between stretches of speech it keeps only the last
pre_speech_secsof audio, which holds the start of the speech the VAD reports late. Fromstart()tostop()it keeps everything, or the lastmax_secsof it, andstop()returns the segment. The audio is 16-bit mono PCM.Example:
buffer = SpeechSegmentBuffer() buffer.set_sample_rate(16000) buffer.append(audio) # every input audio chunk buffer.start() # when the VAD reports speech segment = buffer.stop() # when the VAD reports silence
- __init__(*, pre_speech_secs: float = 1.0, max_secs: float | None = None)[source]
Initialize the buffer.
- Parameters:
pre_speech_secs – Seconds of audio kept from before speech starts. The VAD can report speech most of a second after it starts.
max_secs – The most seconds a segment keeps, its last ones, or None to keep it all.
- set_sample_rate(sample_rate: int)[source]
Set the sample rate of the audio to come.
- Parameters:
sample_rate – Audio sample rate in Hz.