diff --git a/apps/web/src/hooks/use-microphone-dictation.ts b/apps/web/src/hooks/use-microphone-dictation.ts index 04e7fcf..dc374ac 100644 --- a/apps/web/src/hooks/use-microphone-dictation.ts +++ b/apps/web/src/hooks/use-microphone-dictation.ts @@ -1,11 +1,7 @@ import { useCallback, useEffect, useRef, useState } from 'react' import { splitDictation } from '@/lib/natural-input/dictation' -import { - canDictate, - getSpeechRecognition, - type SpeechRecognitionLike, -} from '@/lib/speech-recognition' +import { getSpeechRecognition, type SpeechRecognitionLike } from '@/lib/speech-recognition' export const DICTATION_MESSAGES = { denied: 'No tenemos permiso para usar el micrófono. Habilítalo en los ajustes del navegador.', @@ -55,7 +51,7 @@ type UseMicrophoneDictationOptions = { * capture. Unmounting aborts the recognition. */ export function useMicrophoneDictation({ onPhrases, onError }: UseMicrophoneDictationOptions) { - const [supported] = useState(() => canDictate()) + const [supported] = useState(() => getSpeechRecognition() !== null) const [status, setStatus] = useState('idle') // What has been heard so far, shown while listening. const [heard, setHeard] = useState('') @@ -72,7 +68,7 @@ export function useMicrophoneDictation({ onPhrases, onError }: UseMicrophoneDict const start = useCallback(() => { if (endRef.current) return - const SpeechRecognition = canDictate() ? getSpeechRecognition() : null + const SpeechRecognition = getSpeechRecognition() if (!SpeechRecognition) { callbacksRef.current.onError(DICTATION_MESSAGES.unsupported) return diff --git a/apps/web/src/lib/speech-recognition.ts b/apps/web/src/lib/speech-recognition.ts index b60ee15..f50b103 100644 --- a/apps/web/src/lib/speech-recognition.ts +++ b/apps/web/src/lib/speech-recognition.ts @@ -34,9 +34,11 @@ export function isIosStandalone(): boolean { } /** - * Whether this browser can dictate on its own. An iOS home-screen app exposes - * `webkitSpeechRecognition` but it does not work there, so it counts as unsupported - * (the keyboard's own dictation still works). + * Whether this browser can dictate a phrase without asking for the microphone first + * (the input's microphone). An iOS home-screen app exposes `webkitSpeechRecognition` + * but that flow does not work there, so it counts as unsupported (the keyboard's own + * dictation still works). Dictating several items does work there, because it asks + * for the microphone with `getUserMedia` first, so it checks `getSpeechRecognition()`. */ export function canDictate(): boolean { if (typeof window === 'undefined' || isIosStandalone()) return false