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:
@@ -95,12 +95,15 @@ export class SherpaOnnxTTS implements TextToSpeechProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const audio = this.tts.generate({ text: trimmed, sid: this.speakerId, speed: this.speed });
|
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 && audio.samples instanceof Float32Array
|
||||||
? audio.samples
|
? audio.samples
|
||||||
: audio && Array.isArray(audio.samples)
|
: audio && Array.isArray(audio.samples)
|
||||||
? Float32Array.from(audio.samples as number[])
|
? Float32Array.from(audio.samples as number[])
|
||||||
: null;
|
: 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 =
|
const sampleRate: number =
|
||||||
audio &&
|
audio &&
|
||||||
typeof audio.sampleRate === "number" &&
|
typeof audio.sampleRate === "number" &&
|
||||||
|
|||||||
Reference in New Issue
Block a user