useSpeechRecognition
響應式 SpeechRecognition。
範例
用法
ts
import { useSpeechRecognition } from '@vueuse/core'
const {
isSupported,
isListening,
isFinal,
result,
start,
stop,
} = useSpeechRecognition()
選項
以下顯示選項的預設值,它們將直接傳遞至 SpeechRecognition API。
ts
useSpeechRecognition({
lang: 'en-US',
interimResults: true,
continuous: true,
})
類型宣告
顯示類型宣告
typescript
export interface UseSpeechRecognitionOptions extends ConfigurableWindow {
/**
* Controls whether continuous results are returned for each recognition, or only a single result.
*
* @default true
*/
continuous?: boolean
/**
* Controls whether interim results should be returned (true) or not (false.) Interim results are results that are not yet final
*
* @default true
*/
interimResults?: boolean
/**
* Language for SpeechRecognition
*
* @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
}
/**
* Reactive SpeechRecognition.
*
* @see https://vueuse.dev.org.tw/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: ShallowRef<boolean, boolean>
isFinal: ShallowRef<boolean, boolean>
recognition: SpeechRecognition | undefined
result: ShallowRef<string, string>
error: ShallowRef<
SpeechRecognitionErrorEvent | undefined,
SpeechRecognitionErrorEvent | undefined
>
toggle: (value?: boolean) => void
start: () => void
stop: () => void
}
export type UseSpeechRecognitionReturn = ReturnType<typeof useSpeechRecognition>
原始碼
貢獻者
更新日誌
v12.8.0
於 2025/3/5v12.6.0
於 2025/2/14v12.3.0
於 2025/1/259f75
- feat(toValue): deprecate toValue
from @vueuse/shared
in favor of Vue's nativev12.0.0-beta.1
於 2024/11/21v11.0.0-beta.2
於 2024/7/17v10.10.1
於 2024/6/11v10.8.0
於 2024/2/20a086e
- fix: stricter typesv10.0.0-beta.4
於 2023/4/134d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter
10e98
- feat(toRef)!: rename resolveRef
to toRef