Skip to content

useSpeechSynthesis

类别
导出体积
736 B
上次更改
1 hour ago

响应式 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
>

源码

源码演示文档

贡献者

一纸忘忧

更新日志

没有最近的更新日志