Skip to content

VueSpeechPlayer

A full-featured text-to-speech player component. Renders a voice selector, rate/pitch/volume sliders, and play/pause/stop controls. Fully accessible via keyboard and ARIA attributes.

Import

ts
import { VueSpeechPlayer } from 'vue-text-to-speech'

Usage

vue
<script setup lang="ts">
import { VueSpeechPlayer } from 'vue-text-to-speech'
</script>

<template>
  <VueSpeechPlayer
    text="Hello, this is vue-text-to-speech!"
    :auto-speak="false"
    @start="onStart"
    @end="onEnd"
    @error="onError"
  />
</template>

Props

PropTypeDefaultDescription
textstringRequired. The text to speak
autoSpeakbooleanfalseStart speaking automatically when the component mounts
showVoiceSelectbooleantrueShow the voice selector row
showRatebooleantrueShow the Rate slider
showPitchbooleantrueShow the Pitch slider
showVolumebooleantrueShow the Volume slider

Emits

EventPayloadDescription
startFired when speech begins
endFired when speech completes
pauseFired when speech is paused
resumeFired when speech is resumed
errorSpeechErrorFired on any synthesis error

Slots

SlotDescription
#play-iconReplace the default play icon (SVG or component)
#pause-iconReplace the default pause icon
#stop-iconReplace the default stop icon
#controlsReplace the entire controls area (advanced)
vue
<!-- Custom icons example -->
<VueSpeechPlayer text="Hello world">
  <template #play-icon>▶</template>
  <template #pause-icon>⏸</template>
  <template #stop-icon>⏹</template>
</VueSpeechPlayer>

Theming

Override CSS custom properties on the component or any ancestor:

css
:root {
  --vts-primary: #6366f1;
  --vts-primary-hover: #4f46e5;
  --vts-bg: #ffffff;
  --vts-border: #e5e7eb;
  --vts-text: #111827;
  --vts-text-muted: #6b7280;
  --vts-radius: 8px;
  --vts-font: inherit;
}
vue
<!-- Scoped override on a single instance -->
<VueSpeechPlayer
  text="Hello"
  style="--vts-primary: #10b981; --vts-radius: 4px"
/>

Auto-Speak

When autoSpeak is true the component calls speak() inside onMounted. This fires immediately after the component enters the DOM — ensure the page has received a user interaction first, or browsers may block audio playback.

Accessibility

  • All buttons have aria-label attributes
  • Range sliders have accessible labels
  • Focus management follows WCAG 2.1 SC 2.1.1

Released under the MIT License.