mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-10 12:38:52 +01:00
💬 feat: Improve speech recognition UX for unsupported browsers (#10964)
Show helpful error message when browser doesn't support speech recognition, suggesting external STT option only when it's configured on the server.
This commit is contained in:
parent
6ae839c14d
commit
02fc4647e1
2 changed files with 12 additions and 2 deletions
|
|
@ -2,16 +2,21 @@ import { useEffect, useRef, useMemo } from 'react';
|
|||
import { useRecoilState } from 'recoil';
|
||||
import { useToastContext } from '@librechat/client';
|
||||
import SpeechRecognition, { useSpeechRecognition } from 'react-speech-recognition';
|
||||
import { useGetCustomConfigSpeechQuery } from 'librechat-data-provider/react-query';
|
||||
import useGetAudioSettings from './useGetAudioSettings';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import store from '~/store';
|
||||
|
||||
const useSpeechToTextBrowser = (
|
||||
setText: (text: string) => void,
|
||||
onTranscriptionComplete: (text: string) => void,
|
||||
) => {
|
||||
const localize = useLocalize();
|
||||
const { showToast } = useToastContext();
|
||||
const { speechToTextEndpoint } = useGetAudioSettings();
|
||||
const isBrowserSTTEnabled = speechToTextEndpoint === 'browser';
|
||||
const { data: speechConfig } = useGetCustomConfigSpeechQuery({ enabled: true });
|
||||
const sttExternal = Boolean(speechConfig?.sttExternal);
|
||||
|
||||
const lastTranscript = useRef<string | null>(null);
|
||||
const lastInterim = useRef<string | null>(null);
|
||||
|
|
@ -71,7 +76,9 @@ const useSpeechToTextBrowser = (
|
|||
const toggleListening = () => {
|
||||
if (!browserSupportsSpeechRecognition) {
|
||||
showToast({
|
||||
message: 'Browser does not support SpeechRecognition',
|
||||
message: sttExternal
|
||||
? localize('com_ui_speech_not_supported_use_external')
|
||||
: localize('com_ui_speech_not_supported'),
|
||||
status: 'error',
|
||||
});
|
||||
return;
|
||||
|
|
@ -79,7 +86,7 @@ const useSpeechToTextBrowser = (
|
|||
|
||||
if (!isMicrophoneAvailable) {
|
||||
showToast({
|
||||
message: 'Microphone is not available',
|
||||
message: localize('com_ui_microphone_unavailable'),
|
||||
status: 'error',
|
||||
});
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue