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.
30 lines
762 B
Python
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
|