teganmosi
Optimize TTFT, add connection pooling, implement streaming ASR with stabilization and waterfall metrics
2d0962c Download runtime/audio_buffer_manager.py from teganmosi/realtime: direct link, hf CLI and curl.
- Browser
- Download file 471 Bytes
-
https://huggingface.co/spaces/teganmosi/realtime/resolve/main/runtime/audio_buffer_manager.py
- Command line
-
hf download hf://spaces/teganmosi/realtime/runtime/audio_buffer_manager.py
-
curl -L -o audio_buffer_manager.py https://huggingface.co/spaces/teganmosi/realtime/resolve/main/runtime/audio_buffer_manager.py
471 Bytes
| import numpy as np | |
| class AudioBufferManager: | |
| def __init__(self): | |
| self.reset() | |
| def reset(self): | |
| self.chunks = [] | |
| def append(self, chunk: np.ndarray): | |
| self.chunks.append(chunk) | |
| def get_current_segment(self) -> np.ndarray: | |
| if self.chunks: | |
| return np.concatenate(self.chunks) | |
| return np.array([], dtype=np.float32) | |
| def get_length_samples(self) -> int: | |
| return sum(len(c) for c in self.chunks) | |