From 45f405485c99bf97a9ba7bb14ded64650d57ddfb Mon Sep 17 00:00:00 2001 From: Remi <73385395+itsrubberduck@users.noreply.github.com> Date: Sat, 20 Sep 2025 12:13:49 +0200 Subject: [PATCH] Fix learn TTS speed control --- shared/utils/pizzicatoLite.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/shared/utils/pizzicatoLite.ts b/shared/utils/pizzicatoLite.ts index d3bffc6..3faa7ff 100644 --- a/shared/utils/pizzicatoLite.ts +++ b/shared/utils/pizzicatoLite.ts @@ -53,6 +53,7 @@ class PizzicatoSound { private sourceNode: AudioBufferSourceNode | null = null private effects: EffectNode[] = [] private isPlaying = false + private playbackRate = 1 constructor(context: AudioContext, buffer: AudioBuffer) { this.context = context @@ -79,6 +80,18 @@ class PizzicatoSound { this.outputNode.gain.value = clamp(value, 0, 2) } + setPlaybackRate(value: number) { + const clamped = clamp(value, 0.25, 4) + this.playbackRate = clamped + if (this.sourceNode) { + try { + this.sourceNode.playbackRate.value = clamped + } catch { + // ignore rate assignment errors + } + } + } + async play(): Promise { if (this.isPlaying) { this.stop() @@ -86,6 +99,7 @@ class PizzicatoSound { const source = this.context.createBufferSource() source.buffer = this.buffer + source.playbackRate.value = this.playbackRate const connectedNodes: AudioNode[] = []