@echogarden/gnuspeech-wasm
Version:
WebAssembly port of the GnuSpeech speech synthesizer.
25 lines • 779 B
JavaScript
export function encodeUtf8(text) {
const textEncoder = new TextEncoder();
return textEncoder.encode(text);
}
export function decodeUtf8(encodedString) {
const maxChunkLength = 2 ** 24;
const decoder = new ChunkedUtf8Decoder();
for (let offset = 0; offset < encodedString.length; offset += maxChunkLength) {
const chunk = encodedString.subarray(offset, offset + maxChunkLength);
decoder.writeChunk(chunk);
}
return decoder.toString();
}
export class ChunkedUtf8Decoder {
str = '';
textDecoder = new TextDecoder('utf-8');
writeChunk(chunk) {
const decodedChunk = this.textDecoder.decode(chunk);
this.str += decodedChunk;
}
toString() {
return this.str;
}
}
//# sourceMappingURL=Utf8.js.map