From 610167f0587afb381fabacc7fbecf6d9ae53f7c4 Mon Sep 17 00:00:00 2001 From: Richard Roberson Date: Mon, 27 Jan 2025 00:15:54 -0700 Subject: [PATCH] Fix saved speed + voice --- src/contexts/TTSContext.tsx | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/contexts/TTSContext.tsx b/src/contexts/TTSContext.tsx index aeb03bf..36ad4c9 100644 --- a/src/contexts/TTSContext.tsx +++ b/src/contexts/TTSContext.tsx @@ -93,6 +93,12 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { // Audio cache using LRUCache with a maximum size of 50 entries const audioCacheRef = useRef(new LRUCache({ max: 50 })); + // Update local state when config changes + useEffect(() => { + setSpeed(voiceSpeed); + setVoice(configVoice); + }, [voiceSpeed, configVoice]); + const setText = useCallback((text: string) => { setCurrentText(text); console.log('Setting page text:', text); @@ -352,12 +358,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { setIsProcessing(false); //setIsPlaying(false); // Stop playback on error - if (error instanceof Error && - (error.message.includes('Unable to decode audio data') || - error.message.includes('EncodingError'))) { - console.log('Skipping problematic sentence:', sentence); - advance(); // Skip problematic sentence - } + advance(); // Skip problematic sentence } }, [isPlaying, processSentence, advance]); @@ -434,12 +435,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { audioCacheRef.current.clear(); if (isPlaying) { - const currentIdx = currentIndex; - stop(); - setCurrentIndex(currentIdx); + setIsPlaying(false); + abortAudio(); setIsPlaying(true); } - }, [isPlaying, currentIndex, stop, updateConfigKey]); + }, [isPlaying, abortAudio, updateConfigKey]); const setVoiceAndRestart = useCallback((newVoice: string) => { setVoice(newVoice); @@ -448,12 +448,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) { audioCacheRef.current.clear(); if (isPlaying) { - const currentIdx = currentIndex; - stop(); - setCurrentIndex(currentIdx); + setIsPlaying(false); + abortAudio(); setIsPlaying(true); } - }, [isPlaying, currentIndex, stop, updateConfigKey]); + }, [isPlaying, abortAudio, updateConfigKey]); const value = { isPlaying,