File size: 471 Bytes
2d0962c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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)
|