From 2201dac391e1d3af084acf8ca90a23b2e73f6f39 Mon Sep 17 00:00:00 2001 From: Richard Roberson Date: Sun, 26 Jan 2025 13:55:14 -0700 Subject: [PATCH] Text to click fix --- src/contexts/TTSContext.tsx | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/contexts/TTSContext.tsx b/src/contexts/TTSContext.tsx index abbb940..9c89cfd 100644 --- a/src/contexts/TTSContext.tsx +++ b/src/contexts/TTSContext.tsx @@ -416,11 +416,8 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { const stopAndPlayFromIndex = useCallback((index: number) => { abortAudio(); - // Set the states in the next tick to ensure clean state - setTimeout(() => { - setCurrentIndex(index); - setIsPlaying(true); - }, 50); + setCurrentIndex(index); + setIsPlaying(true); }, [abortAudio]); const setCurrentIndexWithoutPlay = useCallback((index: number) => { @@ -437,11 +434,8 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { if (isPlaying) { const currentIdx = currentIndex; stop(); - // Small delay to ensure audio is fully stopped - setTimeout(() => { - setCurrentIndex(currentIdx); - setIsPlaying(true); - }, 50); + setCurrentIndex(currentIdx); + setIsPlaying(true); } }, [isPlaying, currentIndex, stop]); @@ -453,11 +447,8 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { if (isPlaying) { const currentIdx = currentIndex; stop(); - // Small delay to ensure audio is fully stopped - setTimeout(() => { - setCurrentIndex(currentIdx); - setIsPlaying(true); - }, 50); + setCurrentIndex(currentIdx); + setIsPlaying(true); } }, [isPlaying, currentIndex, stop]);