fix(web): let the list dictation run in the iOS home-screen app
The floating button's commit made the multi-item dictation go through canDictate(), which treats an iOS home-screen app as unsupported. That rule belongs to the input's microphone, which dictates without asking for the microphone first; the multi-item flow asks with getUserMedia and works there, so both the empty list's card and the FAB said the browser could not dictate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +1,7 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
import { splitDictation } from '@/lib/natural-input/dictation'
|
import { splitDictation } from '@/lib/natural-input/dictation'
|
||||||
import {
|
import { getSpeechRecognition, type SpeechRecognitionLike } from '@/lib/speech-recognition'
|
||||||
canDictate,
|
|
||||||
getSpeechRecognition,
|
|
||||||
type SpeechRecognitionLike,
|
|
||||||
} from '@/lib/speech-recognition'
|
|
||||||
|
|
||||||
export const DICTATION_MESSAGES = {
|
export const DICTATION_MESSAGES = {
|
||||||
denied: 'No tenemos permiso para usar el micrófono. Habilítalo en los ajustes del navegador.',
|
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.
|
* capture. Unmounting aborts the recognition.
|
||||||
*/
|
*/
|
||||||
export function useMicrophoneDictation({ onPhrases, onError }: UseMicrophoneDictationOptions) {
|
export function useMicrophoneDictation({ onPhrases, onError }: UseMicrophoneDictationOptions) {
|
||||||
const [supported] = useState(() => canDictate())
|
const [supported] = useState(() => getSpeechRecognition() !== null)
|
||||||
const [status, setStatus] = useState<DictationStatus>('idle')
|
const [status, setStatus] = useState<DictationStatus>('idle')
|
||||||
// What has been heard so far, shown while listening.
|
// What has been heard so far, shown while listening.
|
||||||
const [heard, setHeard] = useState('')
|
const [heard, setHeard] = useState('')
|
||||||
@@ -72,7 +68,7 @@ export function useMicrophoneDictation({ onPhrases, onError }: UseMicrophoneDict
|
|||||||
const start = useCallback(() => {
|
const start = useCallback(() => {
|
||||||
if (endRef.current) return
|
if (endRef.current) return
|
||||||
|
|
||||||
const SpeechRecognition = canDictate() ? getSpeechRecognition() : null
|
const SpeechRecognition = getSpeechRecognition()
|
||||||
if (!SpeechRecognition) {
|
if (!SpeechRecognition) {
|
||||||
callbacksRef.current.onError(DICTATION_MESSAGES.unsupported)
|
callbacksRef.current.onError(DICTATION_MESSAGES.unsupported)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -34,9 +34,11 @@ export function isIosStandalone(): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether this browser can dictate on its own. An iOS home-screen app exposes
|
* Whether this browser can dictate a phrase without asking for the microphone first
|
||||||
* `webkitSpeechRecognition` but it does not work there, so it counts as unsupported
|
* (the input's microphone). An iOS home-screen app exposes `webkitSpeechRecognition`
|
||||||
* (the keyboard's own dictation still works).
|
* 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 {
|
export function canDictate(): boolean {
|
||||||
if (typeof window === 'undefined' || isIosStandalone()) return false
|
if (typeof window === 'undefined' || isIosStandalone()) return false
|
||||||
|
|||||||
Reference in New Issue
Block a user