Skip to content

useSpeechSynthesis

类别
导出体积
736 B
上次更改
last week

响应式 SpeechSynthesis

Can I use?

示例

你好,欢迎使用 VueUse!




用法

ts
import { 
useSpeechSynthesis
} from '@vueuse/core'
const {
isSupported
,
isPlaying
,
status
,
voiceInfo
,
utterance
,
error
,
stop
,
toggle
,
speak
,
} =
useSpeechSynthesis
()

选项

以下显示了选项的默认值,它们将直接传递给 SpeechSynthesis API

ts
useSpeechSynthesis
({
lang
: 'en-US',
pitch
: 1,
rate
: 1,
volume
: 1,
})

类型声明

显示类型声明
ts
export type 
UseSpeechSynthesisStatus
= "init" | "play" | "pause" | "end"
export interface UseSpeechSynthesisOptions extends ConfigurableWindow { /** * 语音合成的语言 * * @default 'en-US' */
lang
?:
MaybeRefOrGetter
<string>
/** * 获取和设置朗读时的音调。 * * @default 1 */
pitch
?:
MaybeRefOrGetter
<SpeechSynthesisUtterance["pitch"]>
/** * 获取和设置朗读时的速度。 * * @default 1 */
rate
?:
MaybeRefOrGetter
<SpeechSynthesisUtterance["rate"]>
/** * 获取和设置用于朗读的声音。 */
voice
?:
MaybeRef
<SpeechSynthesisVoice>
/** * 获取和设置朗读的音量。 * * @default 1 */
volume
?:
MaybeRefOrGetter
<SpeechSynthesisUtterance["volume"]>
/** * Callback function that is called when the boundary event is triggered. */
onBoundary
?: (
event
: SpeechSynthesisEvent) => void
} /** * 响应式语音合成。 * * @see https://vueuse.org/useSpeechSynthesis * @see https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis SpeechSynthesis */ export declare function
useSpeechSynthesis
(
text
:
MaybeRefOrGetter
<string>,
options
?: UseSpeechSynthesisOptions,
): {
isSupported
:
ComputedRef
<boolean>
isPlaying
:
ShallowRef
<boolean, boolean>
status
:
ShallowRef
<
UseSpeechSynthesisStatus
,
UseSpeechSynthesisStatus
>
utterance
:
ComputedRef
<SpeechSynthesisUtterance>
error
:
ShallowRef
<
SpeechSynthesisErrorEvent | undefined, SpeechSynthesisErrorEvent | undefined >
stop
: () => void
toggle
: (
value
?: boolean) => void
speak
: () => void
} export type
UseSpeechSynthesisReturn
=
ReturnType
<typeof
useSpeechSynthesis
>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
IlyaL
Anthony Fu
sibbng
Jelf
wheat
青椒肉丝
SerKo
Melkumyants Danila
Kirill Shestmintsev
糠帅傅
zwkkwz1
云游君

更新日志

c0dca - feat(useSpeechSynthesisOptions): add option onBoundary (#4960)
4d125 - feat: add reactivity for volume (#4837)
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
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)
ac88f - feat: add reactivity for pitch and rate (#3205)