From dc8d30ad9003d59e513ad21dd19ea08a52ff0963 Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Tue, 13 Aug 2024 12:08:55 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A7=20fix(TTS):=20Improve=20State=20of?= =?UTF-8?q?=20audio=20playback,=20hook=20patterns,=20and=20fix=20undefined?= =?UTF-8?q?=20MediaSource=20(#3632)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Chat/Input/StreamAudio.tsx | 12 ++- .../components/Chat/Messages/MessageAudio.tsx | 13 ++- client/src/hooks/Input/useTextToSpeech.ts | 91 ++++++++++--------- .../src/hooks/Input/useTextToSpeechBrowser.ts | 9 +- client/src/hooks/Input/useTextToSpeechEdge.ts | 30 +++--- .../hooks/Input/useTextToSpeechExternal.ts | 25 +++-- 6 files changed, 108 insertions(+), 72 deletions(-) diff --git a/client/src/components/Chat/Input/StreamAudio.tsx b/client/src/components/Chat/Input/StreamAudio.tsx index 0513be1be2..9f1d5f8e40 100644 --- a/client/src/components/Chat/Input/StreamAudio.tsx +++ b/client/src/components/Chat/Input/StreamAudio.tsx @@ -5,9 +5,9 @@ import { useQueryClient } from '@tanstack/react-query'; import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil'; import type { TMessage } from 'librechat-data-provider'; import { useCustomAudioRef, MediaSourceAppender, usePauseGlobalAudio } from '~/hooks/Audio'; +import { getLatestText, logger } from '~/utils'; import { useAuthContext } from '~/hooks'; import { globalAudioId } from '~/common'; -import { getLatestText } from '~/utils'; import store from '~/store'; function timeoutPromise(ms: number, message?: string) { @@ -51,7 +51,7 @@ export default function StreamAudio({ index = 0 }) { const latestText = getLatestText(latestMessage); const shouldFetch = !!( - token && + token != null && automaticPlayback && isSubmitting && latestMessage && @@ -60,7 +60,7 @@ export default function StreamAudio({ index = 0 }) { latestMessage.messageId && !latestMessage.messageId.includes('_') && !isFetching && - activeRunId && + activeRunId != null && activeRunId !== audioRunId ); @@ -109,7 +109,8 @@ export default function StreamAudio({ index = 0 }) { const reader = response.body.getReader(); const type = 'audio/mpeg'; - const browserSupportsType = MediaSource.isTypeSupported(type); + const browserSupportsType = + typeof MediaSource !== 'undefined' && MediaSource.isTypeSupported(type); let mediaSource: MediaSourceAppender | undefined; if (browserSupportsType) { mediaSource = new MediaSourceAppender(type); @@ -210,6 +211,7 @@ export default function StreamAudio({ index = 0 }) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [paramId]); + logger.log('StreamAudio.tsx - globalAudioURL:', globalAudioURL); return (