Skip to content

useSpeechSynthesis

Category
Export Size
736 B
Last Changed
2 weeks ago

Reactive SpeechSynthesis.

Can I use?

Demo

Hello, everyone! Good morning!




Usage

ts
import { 
useSpeechSynthesis
} from '@vueuse/core'
const {
isSupported
,
isPlaying
,
status
,
voiceInfo
,
utterance
,
error
,
stop
,
toggle
,
speak
,
} =
useSpeechSynthesis
()

Options

The following shows the default values of the options, they will be directly passed to SpeechSynthesis API.

ts
useSpeechSynthesis
({
lang
: 'en-US',
pitch
: 1,
rate
: 1,
volume
: 1,
})

Type Declarations

Show Type Declarations
ts
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
?:
MaybeRefOrGetter
<SpeechSynthesisUtterance["volume"]>
/** * Callback function that is called when the boundary event is triggered. */
onBoundary
?: (
event
: SpeechSynthesisEvent) => void
} /** * Reactive SpeechSynthesis. * * @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
:
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
>

Source

SourceDemoDocs

Contributors

Anthony Fu
IlyaL
Anthony Fu
sibbng
Jelf
wheat
青椒肉丝
SerKo
Melkumyants Danila
Kirill Shestmintsev
糠帅傅
zwkkwz1
云游君

Changelog

v13.7.0 on
c0dca - feat(useSpeechSynthesisOptions): add option onBoundary (#4960)
v13.5.0 on
4d125 - feat: add reactivity for volume (#4837)
v12.8.0 on
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
v12.3.0 on
59f75 - feat(toValue): deprecate toValue from @vueuse/shared in favor of Vue's native
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.3.0 on
ac88f - feat: add reactivity for pitch and rate (#3205)
v10.0.0-beta.4 on
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef

Released under the MIT License.

Join the Biggest FREE AI-Driven Development Event for Vue Developers
Save My Seat