fn
useSpeechSynthesis
v0.0.14testeddemoReactive 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
| Parameter | Type | Description |
|---|---|---|
text | MaybeRefOrGetter<string> | The text to speak; rebuilds the utterance reactively |
options? | UseSpeechSynthesisOptions | Configuration options |
Returns
UseSpeechSynthesisReturnSupport flag, playing/status/error state, the reactive utterance, and speak/stop/toggle actions| Property | Type | Description |
|---|---|---|
isSupported | ComputedRef<boolean> | Whether the SpeechSynthesis API is supported in the current environment. |
isPlaying | ShallowRef<boolean> | Whether the utterance is currently being spoken. |
status | ShallowRef<UseSpeechSynthesisStatus> | Current lifecycle status of the utterance. |
utterance | ComputedRef<SpeechSynthesisUtterance> | The reactive SpeechSynthesisUtterance rebuilt whenever the text or options change. |
error | ShallowRef<SpeechSynthesisErrorEvent | undefined> | The most recent error raised while speaking, if any. |
toggle | (value?: boolean) => void | Pause/resume speaking. Pass an explicit boolean to force a state. |
speak | () => void | Cancel any queued speech and speak the current utterance from the start. |
stop | () => void | Stop speaking and clear the queue. |