fix: copy sherpa TTS samples to avoid external buffer crash

Same fix as the Silero VAD — sherpa-onnx returns Float32Arrays backed
by native memory which Node.js rejects as "External buffers are not
allowed". Copy into JS-managed memory before passing to audio pipeline.
This commit is contained in:
Mohamed Boudra
2026-04-04 23:45:28 +07:00
parent a693ff560c
commit 5c1e869bc5
@@ -95,12 +95,15 @@ export class SherpaOnnxTTS implements TextToSpeechProvider {
}
const audio = this.tts.generate({ text: trimmed, sid: this.speakerId, speed: this.speed });
const samples: Float32Array | null =
const rawSamples: Float32Array | null =
audio && audio.samples instanceof Float32Array
? audio.samples
: audio && Array.isArray(audio.samples)
? Float32Array.from(audio.samples as number[])
: null;
// Copy to avoid "External buffers are not allowed" when sherpa-onnx
// returns a Float32Array backed by native memory.
const samples = rawSamples ? Float32Array.from(rawSamples) : null;
const sampleRate: number =
audio &&
typeof audio.sampleRate === "number" &&