feat: download audio file support

This commit is contained in:
Marco Beretta 2024-06-18 16:24:37 +02:00
parent 302b28fc9b
commit d839e4661c
No known key found for this signature in database
GPG key ID: 487C4BA02481F779
6 changed files with 113 additions and 59 deletions

View file

@ -9,7 +9,6 @@ export default function useCustomAudioRef({
useEffect(() => {
const handleEnded = () => {
setIsPlaying(false);
console.log('message audio ended');
if (audioRef.current) {
URL.revokeObjectURL(audioRef.current.src);
}
@ -17,12 +16,10 @@ export default function useCustomAudioRef({
const handleStart = () => {
setIsPlaying(true);
console.log('message audio started');
};
const handlePause = () => {
setIsPlaying(false);
console.log('message audio paused');
};
const audioElement = audioRef.current;

View file

@ -52,7 +52,7 @@ const useTextToSpeech = (message: TMessage, isLast: boolean, index = 0) => {
}
};
const toggleSpeech = () => {
const toggleSpeech = (download: boolean) => {
if (isSpeaking) {
console.log('canceling message audio speech');
cancelSpeech();
@ -61,7 +61,7 @@ const useTextToSpeech = (message: TMessage, isLast: boolean, index = 0) => {
const messageContent = message?.content ?? message?.text ?? '';
const parsedMessage =
typeof messageContent === 'string' ? messageContent : parseTextParts(messageContent);
generateSpeech(parsedMessage, false);
generateSpeech(parsedMessage, download);
}
};

View file

@ -59,7 +59,6 @@ function useTextToSpeechExternal(messageId: string, isLast: boolean, index = 0)
});
newAudio.onended = () => {
console.log('Cached message audio ended');
URL.revokeObjectURL(blobUrl);
setIsSpeaking(false);
};
@ -100,7 +99,9 @@ function useTextToSpeechExternal(messageId: string, isLast: boolean, index = 0)
const blobUrl = URL.createObjectURL(audioBlob);
if (downloadFile) {
downloadAudio(blobUrl);
return;
}
autoPlayAudio(blobUrl);
} catch (error) {
showToast({