Fix saved speed + voice
This commit is contained in:
parent
ced82d7bf5
commit
610167f058
1 changed files with 13 additions and 14 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue