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.dokyumento.jp/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>
ソース
貢献者
変更履歴
v12.0.0-beta.1
2024/11/21v10.3.0
2023/07/30v10.0.0-beta.4
2023/04/134d757
- feat(types)!: MaybeComputedRef
を MaybeRefOrGetter
に名前変更10e98
- feat(toRef)!: resolveRef
を toRef
に名前変更v9.13.0
2023/02/18