TTSContext major refactor
This commit is contained in:
parent
1c58891a59
commit
072d11a60b
1 changed files with 6 additions and 4 deletions
|
|
@ -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]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue