Files
esp32-server/app/audio/buffer.py
Macky b8950b38a4 feat: Phase 1 testable bridge skeleton (18 tests green)
Xiaozhi WebSocket endpoint with handshake/auth, mock STT/TTS/Hermes
backends, Thai chunker, barge-in queue, latency logger, GPU planner,
voice-profile guard (reasoning=none, session_search only).

CON-002: no GPU/audio libs loaded at import. MUST-NOT-001: all model
names/tokens from config.
2026-10-03 11:45:31 +07:00

30 lines
762 B
Python

"""In-memory PCM ring buffer for a single utterance.
Kept deliberately dependency-free (REQ-002). The buffer accumulates the
current utterance's PCM and is flushed at end-of-speech, so STT always
transcribes one utterance, not a rolling window.
"""
from __future__ import annotations
class PCMBuffer:
def __init__(self) -> None:
self._chunks: list[bytes] = []
self._bytes = 0
def feed(self, pcm: bytes) -> None:
self._chunks.append(bytes(pcm))
self._bytes += len(pcm)
def total_bytes(self) -> int:
return self._bytes
def get(self) -> bytes:
data = b"".join(self._chunks)
self.clear()
return data
def clear(self) -> None:
self._chunks = []
self._bytes = 0