UNPKG

echogarden

Version:

An easy-to-use speech toolset. Includes tools for synthesis, recognition, alignment, speech translation, language detection, source separation and more.

52 lines 1.69 kB
export class DynamicTypedArray { TypedArrayConstructor; elements; length = 0; constructor(TypedArrayConstructor, initialCapacity = 4) { this.TypedArrayConstructor = TypedArrayConstructor; this.elements = new TypedArrayConstructor(initialCapacity); } add(newElement) { const newLength = this.length + 1; if (newLength > this.capacity) { this.ensureCapacity(newLength); } this.elements[this.length] = newElement; this.length = newLength; } addMany(...newElements) { this.addArray(newElements); } addArray(newElements) { const newLength = this.length + newElements.length; if (newLength > this.capacity) { this.ensureCapacity(newLength); } this.elements.set(newElements, this.length); this.length = newLength; } ensureCapacity(requiredCapacity) { if (requiredCapacity > this.capacity) { const newCapacity = requiredCapacity * 2; const newElements = new this.TypedArrayConstructor(newCapacity); newElements.set(this.toTypedArray()); this.elements = newElements; } } get capacity() { return this.elements.length; } toTypedArray() { return this.elements.subarray(0, this.length); } clear() { this.length = 0; } } export function createDynamicUint8Array(initialCapacity) { return new DynamicTypedArray(Uint8Array, initialCapacity); } export function createDynamicUint16Array(initialCapacity) { return new DynamicTypedArray(Uint16Array, initialCapacity); } //# sourceMappingURL=DynamicTypedArray.js.map