useSpeechRecognition
响应式 SpeechRecognition。
Demo
用法
ts
import { useSpeechRecognition } from '@vueuse/core'
const {
isSupported,
isListening,
isFinal,
result,
start,
stop,
} = useSpeechRecognition()
选项
以下显示了选项的默认值,它们将直接传递给 SpeechRecognition API。
ts
useSpeechRecognition({
lang: 'zh-CN',
interimResults: true,
continuous: true,
})
类型声明
显示类型声明
typescript
export interface UseSpeechRecognitionOptions extends ConfigurableWindow {
/**
* 控制是否对每次识别返回连续的结果,还是仅返回单个结果。
*
* @default true
*/
continuous?: boolean
/**
* 控制是否返回临时结果(true)或不返回临时结果(false)。
* 临时结果是尚未最终确定的结果。
*
* @default true
*/
interimResults?: boolean
/**
* 语音识别的语言
*
* @default 'en-US'
*/
lang?: MaybeRefOrGetter<string>
/**
* A number representing the maximum returned alternatives for each result.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition/maxAlternatives
* @default 1
*/
maxAlternatives?: number
}
/**
* 响应式语音识别。
*
* @see https://vueuse.org/useSpeechRecognition
* @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition SpeechRecognition
* @param options
*/
export declare function useSpeechRecognition(
options?: UseSpeechRecognitionOptions,
): {
isSupported: ComputedRef<boolean>
isListening: Ref<boolean, boolean>
isFinal: Ref<boolean, boolean>
recognition: SpeechRecognition | undefined
result: Ref<string, string>
error: Ref<
SpeechRecognitionErrorEvent | undefined,
SpeechRecognitionErrorEvent | undefined
>
toggle: (value?: boolean) => void
start: () => void
stop: () => void
}
export type UseSpeechRecognitionReturn = ReturnType<typeof useSpeechRecognition>
Source
贡献者
Anthony Fu
丶远方
Jelf
Anthony Fu
青椒肉丝
Neil Richter
Mark Noonan
vaakian X
wheat
Joe Maylor
Shinigami
Alex Kozack
EGGSY
Antério Vieira
变更日志
v11.0.0-beta.2
on 7/17/2024v10.10.1
on 6/11/2024v10.8.0
on 2/20/2024a086e
- fix: stricter typesv10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
10e98
- feat(toRef)!: rename resolveRef
to toRef