fn

useSpeechSynthesis

v0.0.14testeddemo

Reactive wrapper around the Web Speech SpeechSynthesis API for text-to-speech.

Examples

ts
const { speak, stop, isPlaying } = useSpeechSynthesis('Hello world', { lang: 'en-US', rate: 1.2 });
speak();
ts
// Reactive text and voice
const text = ref('Initial');
const { speak, status } = useSpeechSynthesis(text, { pitch: 1.5 });
text.value = 'Updated';
speak();

Demo

Loading demo…

Signature

ts
export function useSpeechSynthesis(
  text: MaybeRefOrGetter<string>,
  options: UseSpeechSynthesisOptions ={ ... }

Parameters

ParameterTypeDescription
textMaybeRefOrGetter<string>The text to speak; rebuilds the utterance reactively
options?UseSpeechSynthesisOptionsConfiguration options

Returns

UseSpeechSynthesisReturnSupport flag, playing/status/error state, the reactive utterance, and speak/stop/toggle actions
PropertyTypeDescription
isSupportedComputedRef<boolean>Whether the SpeechSynthesis API is supported in the current environment.
isPlayingShallowRef<boolean>Whether the utterance is currently being spoken.
statusShallowRef<UseSpeechSynthesisStatus>Current lifecycle status of the utterance.
utteranceComputedRef<SpeechSynthesisUtterance>The reactive SpeechSynthesisUtterance rebuilt whenever the text or options change.
errorShallowRef<SpeechSynthesisErrorEvent | undefined>The most recent error raised while speaking, if any.
toggle(value?: boolean) => voidPause/resume speaking. Pass an explicit boolean to force a state.
speak() => voidCancel any queued speech and speak the current utterance from the start.
stop() => voidStop speaking and clear the queue.