useSpeechSynthesis
响应式 SpeechSynthesis。
Demo
用法
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 {
/**
* 语音合成的语言
*
* @default 'en-US'
*/
lang?: MaybeRefOrGetter<string>
/**
* 获取和设置朗读时的音调。
*
* @default 1
*/
pitch?: MaybeRefOrGetter<SpeechSynthesisUtterance["pitch"]>
/**
* 获取和设置朗读时的速度。
*
* @default 1
*/
rate?: MaybeRefOrGetter<SpeechSynthesisUtterance["rate"]>
/**
* 获取和设置用于朗读的声音。
*/
voice?: MaybeRef<SpeechSynthesisVoice>
/**
* 获取和设置朗读的音量。
*
* @default 1
*/
volume?: SpeechSynthesisUtterance["volume"]
}
/**
* 响应式语音合成。
*
* @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: Ref<boolean, boolean>
status: Ref<UseSpeechSynthesisStatus, UseSpeechSynthesisStatus>
utterance: ComputedRef<SpeechSynthesisUtterance>
error: Ref<
SpeechSynthesisErrorEvent | undefined,
SpeechSynthesisErrorEvent | undefined
>
stop: () => void
toggle: (value?: boolean) => void
speak: () => void
}
export type UseSpeechSynthesisReturn = ReturnType<typeof useSpeechSynthesis>
Source
贡献者
Anthony Fu
丶远方
sibbng
Anthony Fu
Jelf
wheat
Kirill Shestmintsev
糠帅傅
zwkkwz1
云游君