Fix saved speed + voice

This commit is contained in:
Richard Roberson 2025-01-27 00:15:54 -07:00
parent ced82d7bf5
commit 610167f058

View file

@ -93,6 +93,12 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
// Audio cache using LRUCache with a maximum size of 50 entries // Audio cache using LRUCache with a maximum size of 50 entries
const audioCacheRef = useRef(new LRUCache<string, AudioBuffer>({ max: 50 })); const audioCacheRef = useRef(new LRUCache<string, AudioBuffer>({ max: 50 }));
// Update local state when config changes
useEffect(() => {
setSpeed(voiceSpeed);
setVoice(configVoice);
}, [voiceSpeed, configVoice]);
const setText = useCallback((text: string) => { const setText = useCallback((text: string) => {
setCurrentText(text); setCurrentText(text);
console.log('Setting page text:', text); console.log('Setting page text:', text);
@ -352,12 +358,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
setIsProcessing(false); setIsProcessing(false);
//setIsPlaying(false); // Stop playback on error //setIsPlaying(false); // Stop playback on error
if (error instanceof Error && advance(); // Skip problematic sentence
(error.message.includes('Unable to decode audio data') ||
error.message.includes('EncodingError'))) {
console.log('Skipping problematic sentence:', sentence);
advance(); // Skip problematic sentence
}
} }
}, [isPlaying, processSentence, advance]); }, [isPlaying, processSentence, advance]);
@ -434,12 +435,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
audioCacheRef.current.clear(); audioCacheRef.current.clear();
if (isPlaying) { if (isPlaying) {
const currentIdx = currentIndex; setIsPlaying(false);
stop(); abortAudio();
setCurrentIndex(currentIdx);
setIsPlaying(true); setIsPlaying(true);
} }
}, [isPlaying, currentIndex, stop, updateConfigKey]); }, [isPlaying, abortAudio, updateConfigKey]);
const setVoiceAndRestart = useCallback((newVoice: string) => { const setVoiceAndRestart = useCallback((newVoice: string) => {
setVoice(newVoice); setVoice(newVoice);
@ -448,12 +448,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
audioCacheRef.current.clear(); audioCacheRef.current.clear();
if (isPlaying) { if (isPlaying) {
const currentIdx = currentIndex; setIsPlaying(false);
stop(); abortAudio();
setCurrentIndex(currentIdx);
setIsPlaying(true); setIsPlaying(true);
} }
}, [isPlaying, currentIndex, stop, updateConfigKey]); }, [isPlaying, abortAudio, updateConfigKey]);
const value = { const value = {
isPlaying, isPlaying,