Skip to content

VoiceStudio is the open-source, fully-local ElevenLabs alternative — voice cloning, voice design, video dubbing, dictation, transcription & audiobook creation in 646 languages.

fix(audio): sync waveform play button state

velixioa486dad2cbc5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3f827c8e2..d31eadf29 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,7 +19,7 @@ metadata and the backend fallback mirror it.
### Fixed
-- Older synthesized takes play again after a newer generation takes over audio playback (#3102)
+- Older synthesized takes play again with accurate play/pause controls after a newer generation (#3102)
- Generation-complete notifications appear above the workspace instead of covering synthesis controls (#3102)
- Generated speech no longer starts and ends with silence, and `[pause]` markers give exactly the pause you asked for (Raw preset and explicit durations untouched) (#3080)
- Engine sidecars no longer load PyTorch just to answer the Test Engine ping, and a failed test logs its reason locally (#3026) — thanks @tekay-de!
diff --git a/electron/src/renderer/src/components/waveform-player.test.ts b/electron/src/renderer/src/components/waveform-player.test.ts
new file mode 100644
index 000000000..432f28ee3
--- /dev/null
+++ b/electron/src/renderer/src/components/waveform-player.test.ts
@@ -0,0 +1,20 @@
+import { expect, it, vi } from 'vitest';
+import { subscribeMediaPaused } from './waveform-player';
+
+it('tracks the native media element play and pause state for its button', () => {
+ const media = Object.assign(new EventTarget(), { paused: true });
+ const onPaused = vi.fn();
+ const unsubscribe = subscribeMediaPaused(media as HTMLMediaElement, onPaused);
+
+ media.paused = false;
+ media.dispatchEvent(new Event('playing'));
+ media.paused = true;
+ media.dispatchEvent(new Event('pause'));
+
+ expect(onPaused.mock.calls.map(([paused]) => paused)).toEqual([true, false, true]);
+
+ unsubscribe();
+ media.paused = false;
+ media.dispatchEvent(new Event('playing'));
+ expect(onPaused).toHaveBeenCalledTimes(3);
+});
diff --git a/electron/src/renderer/src/components/waveform-player.tsx b/electron/src/renderer/src/components/waveform-player.tsx
index c39170e08..da139e2a3 100644
--- a/electron/src/renderer/src/components/waveform-player.tsx
+++ b/electron/src/renderer/src/components/waveform-player.tsx
@@ -49,6 +49,20 @@ export function waveColors(el: HTMLElement): { waveColor: string; progressColor:
return { waveColor: muted, progressColor: primary };
}
+/** Keep controls aligned with the concrete audio element even if provider state is stale. */
+export function subscribeMediaPaused(
+ media: HTMLMediaElement,
+ onPaused: (paused: boolean) => void,
+): () => void {
+ const sync = () => onPaused(media.paused);
+ const events = ['play', 'playing', 'pause', 'ended', 'emptied'] as const;
+ sync();
+ for (const event of events) media.addEventListener(event, sync);
+ return () => {
+ for (const event of events) media.removeEventListener(event, sync);
+ };
+}
+
export const WaveformPlayer = memo(function WaveformPlayer({
src,
source = 'output',
@@ -119,12 +133,18 @@ function WaveformControls({
const waveform = useRef<WaveSurfer | null>(null);
const rangeEnd = useRef<number | null>(null);
const [waveReady, setWaveReady] = useState(false);
- const paused = useMediaState('paused');
+ const providerPaused = useMediaState('paused');
+ const [mediaPaused, setMediaPaused] = useState(true);
+ const paused = media ? mediaPaused : providerPaused;
const canPlay = useMediaState('canPlay');
const duration = useMediaState('duration');
const time = useMediaState('currentTime');
const error = useMediaState('error');
const seek = usePlaybackSeek(source);
+ useEffect(() => {
+ if (!media) return;
+ return subscribeMediaPaused(media, setMediaPaused);
+ }, [media]);
useEffect(() => {
resetPlaybackClock(source);
return () => resetPlaybackClock(source);