Skip to content

useSpeechRecognition

类别
导出体积
714 B
上次更改
6 months ago

响应式 SpeechRecognition

Can I use?

示例

你的浏览器不支持语音识别 API, 查看更多详情

用法

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,
})

类型声明

显示类型声明
ts
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
:
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
>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
IlyaL
Anthony Fu
Jelf
SerKo
IlyaL
Byron
青椒肉丝
Neil Richter
Mark Noonan
vaakian X
wheat
Joe Maylor
Shinigami
Alex Kozack
EGGSY
Antério Vieira

更新日志

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
4f104 - fix: improve start and stop method behavior (#4565)
890ab - fix: execute 'start' when not ended (#4119)
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
9eda8 - feat: support maxAlternatives option (#4067)
7c36f - fix: send correct transcript result (#3891)
a086e - fix: stricter types