mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-19 01:40:15 +01:00
🔧 fix: Consolidate Text Parsing and TTS Edge Initialization (#6582)
* 🔧 fix: Update useTextToSpeechExternal to include loading state and improve text parsing logic
* fix: update msedge-tts and prevent excessive initialization attempts
* fix: Refactor text parsing logic in mongoMeili model to use parseTextParts function
This commit is contained in:
parent
a6f062e468
commit
b9ebdd4aa5
6 changed files with 57 additions and 29 deletions
|
|
@ -26,6 +26,7 @@ function useTextToSpeechEdge({
|
|||
const sourceBufferRef = useRef<SourceBuffer | null>(null);
|
||||
const pendingBuffers = useRef<Uint8Array[]>([]);
|
||||
const { showToast } = useToastContext();
|
||||
const initAttempts = useRef(0);
|
||||
|
||||
const isBrowserSupported = useMemo(
|
||||
() => typeof MediaSource !== 'undefined' && MediaSource.isTypeSupported('audio/mpeg'),
|
||||
|
|
@ -57,14 +58,20 @@ function useTextToSpeechEdge({
|
|||
|
||||
const initializeTTS = useCallback(() => {
|
||||
if (!ttsRef.current) {
|
||||
ttsRef.current = new MsEdgeTTS();
|
||||
ttsRef.current = new MsEdgeTTS({
|
||||
enableLogger: true,
|
||||
});
|
||||
}
|
||||
const availableVoice: VoiceOption | undefined = voices.find((v) => v.value === voiceName);
|
||||
|
||||
if (availableVoice) {
|
||||
if (initAttempts.current > 3) {
|
||||
return;
|
||||
}
|
||||
ttsRef.current
|
||||
.setMetadata(availableVoice.value, OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3)
|
||||
.setMetadata(availableVoice.value, OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3, {})
|
||||
.catch((error) => {
|
||||
initAttempts.current += 1;
|
||||
console.error('Error initializing TTS:', error);
|
||||
showToast({
|
||||
message: localize('com_nav_tts_init_error', { 0: (error as Error).message }),
|
||||
|
|
@ -73,8 +80,9 @@ function useTextToSpeechEdge({
|
|||
});
|
||||
} else if (voices.length > 0) {
|
||||
ttsRef.current
|
||||
.setMetadata(voices[0].value, OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3)
|
||||
.setMetadata(voices[0].value, OUTPUT_FORMAT.AUDIO_24KHZ_48KBITRATE_MONO_MP3, {})
|
||||
.catch((error) => {
|
||||
initAttempts.current += 1;
|
||||
console.error('Error initializing TTS:', error);
|
||||
showToast({
|
||||
message: localize('com_nav_tts_init_error', { 0: (error as Error).message }),
|
||||
|
|
@ -147,7 +155,8 @@ function useTextToSpeechEdge({
|
|||
setIsSpeaking(true);
|
||||
pendingBuffers.current = [];
|
||||
|
||||
const readable = ttsRef.current.toStream(text);
|
||||
const result = await ttsRef.current.toStream(text);
|
||||
const readable = result.audioStream;
|
||||
|
||||
readable.on('data', (chunk: Buffer) => {
|
||||
pendingBuffers.current.push(new Uint8Array(chunk));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue