跳到主要内容

useSpeechRecognition

分类
导出大小
714 B
上次更改
8 个月前

响应式的 语音识别

我能用吗?

演示

您的浏览器不支持 SpeechRecognition API,查看更多详情

用法

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

类型声明

显示类型声明
ts
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://mdn.org.cn/en-US/docs/Web/API/SpeechRecognition/maxAlternatives * @default 1 */
maxAlternatives
?: number
} /** * Reactive SpeechRecognition. * * @see https://vueuse.org.cn/useSpeechRecognition * @see https://mdn.org.cn/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

更新日志

v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.6.0
4f104 - 修复:改进 start 和 stop 方法行为 (#4565)
v12.3.0
890ab - 修复:未结束时执行 'start' (#4119)
59f75 - feat(toValue): 废弃 @vueuse/shared 中的 toValue,转而使用 Vue 的原生函数
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
9eda8 - 特性:支持 maxAlternatives 选项 (#4067)
7c36f - 修复:发送正确的转录结果 (#3891)
v10.8.0
a086e - fix: 更严格的类型

根据 MIT 许可证发布。