💬 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:
Marco Beretta 2025-12-15 16:29:10 +01:00 committed by GitHub
parent 6ae839c14d
commit 02fc4647e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -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;

View file

@ -1295,6 +1295,9 @@
"com_ui_special_variables": "Special variables:",
"com_ui_special_variables_more_info": "You can select special variables from the dropdown: `{{current_date}}` (today's date and day of week), `{{current_datetime}}` (local date and time), `{{utc_iso_datetime}}` (UTC ISO datetime), and `{{current_user}}` (your account name).",
"com_ui_speech_while_submitting": "Can't submit speech while a response is being generated",
"com_ui_speech_not_supported": "Your browser does not support speech recognition",
"com_ui_speech_not_supported_use_external": "Your browser does not support speech recognition. Try switching to External STT in Settings > Speech.",
"com_ui_microphone_unavailable": "Microphone is not available",
"com_ui_sr_actions_menu": "Open actions menu for \"{{0}}\" prompt",
"com_ui_sr_global_prompt": "Global prompt group",
"com_ui_stack_trace": "Stack Trace",