mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-02 22:30:18 +01:00
feat: download audio file support
This commit is contained in:
parent
302b28fc9b
commit
d839e4661c
6 changed files with 113 additions and 59 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue