Skip to content

Commit 610167f

Browse files
committed
Fix saved speed + voice
1 parent ced82d7 commit 610167f

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/contexts/TTSContext.tsx

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
9393
// Audio cache using LRUCache with a maximum size of 50 entries
9494
const audioCacheRef = useRef(new LRUCache<string, AudioBuffer>({ max: 50 }));
9595

96+
// Update local state when config changes
97+
useEffect(() => {
98+
setSpeed(voiceSpeed);
99+
setVoice(configVoice);
100+
}, [voiceSpeed, configVoice]);
101+
96102
const setText = useCallback((text: string) => {
97103
setCurrentText(text);
98104
console.log('Setting page text:', text);
@@ -352,12 +358,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
352358
setIsProcessing(false);
353359
//setIsPlaying(false); // Stop playback on error
354360

355-
if (error instanceof Error &&
356-
(error.message.includes('Unable to decode audio data') ||
357-
error.message.includes('EncodingError'))) {
358-
console.log('Skipping problematic sentence:', sentence);
359-
advance(); // Skip problematic sentence
360-
}
361+
advance(); // Skip problematic sentence
361362
}
362363
}, [isPlaying, processSentence, advance]);
363364

@@ -434,12 +435,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
434435
audioCacheRef.current.clear();
435436

436437
if (isPlaying) {
437-
const currentIdx = currentIndex;
438-
stop();
439-
setCurrentIndex(currentIdx);
438+
setIsPlaying(false);
439+
abortAudio();
440440
setIsPlaying(true);
441441
}
442-
}, [isPlaying, currentIndex, stop, updateConfigKey]);
442+
}, [isPlaying, abortAudio, updateConfigKey]);
443443

444444
const setVoiceAndRestart = useCallback((newVoice: string) => {
445445
setVoice(newVoice);
@@ -448,12 +448,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
448448
audioCacheRef.current.clear();
449449

450450
if (isPlaying) {
451-
const currentIdx = currentIndex;
452-
stop();
453-
setCurrentIndex(currentIdx);
451+
setIsPlaying(false);
452+
abortAudio();
454453
setIsPlaying(true);
455454
}
456-
}, [isPlaying, currentIndex, stop, updateConfigKey]);
455+
}, [isPlaying, abortAudio, updateConfigKey]);
457456

458457
const value = {
459458
isPlaying,

0 commit comments

Comments
 (0)