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.dev.org.tw/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>
原始碼
貢獻者
更新日誌
v12.8.0
於 3/5/2025v12.3.0
於 1/2/202559f75
- feat(toValue): 棄用 @vueuse/shared 中的 toValue,改用 Vue 原生語法v12.0.0-beta.1
於 11/21/2024v10.3.0
於 7/30/2023v10.0.0-beta.4
於 4/13/20234d757
- feat(types)!: 將 MaybeComputedRef 重新命名為 MaybeRefOrGetter10e98
- feat(toRef)!: 將 resolveRef 重新命名為 toRefv9.13.0
於 2/18/2023