TTSContext major refactor

This commit is contained in:
Richard Roberson 2025-01-24 03:05:34 -07:00
parent 1c58891a59
commit 072d11a60b

View file

@ -271,6 +271,8 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
const cleanedSentence = preprocessSentenceForAudio(sentence); const cleanedSentence = preprocessSentenceForAudio(sentence);
currentRequestRef.current = new AbortController(); currentRequestRef.current = new AbortController();
console.log('Requesting audio for sentence:', cleanedSentence);
const audioBuffer = await getAudio(cleanedSentence); const audioBuffer = await getAudio(cleanedSentence);
if (!currentRequestRef.current) throw new Error('Request cancelled'); if (!currentRequestRef.current) throw new Error('Request cancelled');
@ -285,7 +287,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
} }
}; };
const playSentence = async (sentence: string) => { const playSentenceWithHowl = async (sentence: string) => {
try { try {
const audioUrl = await processSentence(sentence); const audioUrl = await processSentence(sentence);
setIsProcessing(false); setIsProcessing(false);
@ -308,7 +310,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
URL.revokeObjectURL(audioUrl); URL.revokeObjectURL(audioUrl);
setActiveHowl(null); setActiveHowl(null);
if (isPlaying && !isPausingRef.current) { if (isPlaying && !isPausingRef.current) {
advance(); //advance();
} }
isPausingRef.current = false; isPausingRef.current = false;
}, },
@ -317,7 +319,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
setIsProcessing(false); setIsProcessing(false);
setActiveHowl(null); setActiveHowl(null);
URL.revokeObjectURL(audioUrl); URL.revokeObjectURL(audioUrl);
advance(); //advance();
}, },
}); });
@ -365,7 +367,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
useEffect(() => { useEffect(() => {
const playAudio = async () => { const playAudio = async () => {
if (isPlaying && sentences[currentIndex] && !isProcessing) { if (isPlaying && sentences[currentIndex] && !isProcessing) {
await playSentence(sentences[currentIndex]); await playSentenceWithHowl(sentences[currentIndex]);
} }
}; };