useSpeechSynthesis
响应式 SpeechSynthesis。
演示
用法
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,
})
类型声明
显示类型声明
typescript
export type UseSpeechSynthesisStatus = "init" | "play" | "pause" | "end"
export interface UseSpeechSynthesisOptions extends ConfigurableWindow {
/**
* Language for SpeechSynthesis
*
* @default 'en-US'
*/
lang?: MaybeRefOrGetter<string>
/**
* Gets and sets the pitch at which the utterance will be spoken at.
*
* @default 1
*/
pitch?: MaybeRefOrGetter<SpeechSynthesisUtterance["pitch"]>
/**
* Gets and sets the speed at which the utterance will be spoken at.
*
* @default 1
*/
rate?: MaybeRefOrGetter<SpeechSynthesisUtterance["rate"]>
/**
* Gets and sets the voice that will be used to speak the utterance.
*/
voice?: MaybeRef<SpeechSynthesisVoice>
/**
* Gets and sets the volume that the utterance will be spoken at.
*
* @default 1
*/
volume?: SpeechSynthesisUtterance["volume"]
}
/**
* Reactive SpeechSynthesis.
*
* @see https://vueuse.org.cn/useSpeechSynthesis
* @see https://mdn.org.cn/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>
源
贡献者
更新日志
v12.8.0
于 2025/3/5v12.3.0
于 2025/1/259f75
- feat(toValue): 弃用 @vueuse/shared
中的 toValue
,支持 Vue 原生v12.0.0-beta.1
于 2024/11/21v10.3.0
于 2023/7/30v10.0.0-beta.4
于 2023/4/134d757
- feat(types)!: 将 MaybeComputedRef
重命名为 MaybeRefOrGetter
10e98
- feat(toRef)!: 将 resolveRef
重命名为 toRef
v9.13.0
于 2023/2/18