Skip to content

VueSpeechRecorder

A speech-to-text recorder component that renders a microphone button and live transcript display. Uses the browser's Web Speech API regardless of the TTS provider configured in app.use().

Import

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

Usage

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

function onFinal(text: string, confidence: number) {
  console.log(`"${text}" — ${(confidence * 100).toFixed(0)}% confident`)
}
</script>

<template>
  <VueSpeechRecorder
    lang="en-US"
    :continuous="false"
    @transcript="(t, c) => console.log('interim', t)"
    @final-transcript="onFinal"
    @error="(e) => console.error(e)"
  />
</template>

Props

PropTypeDefaultDescription
langstringBrowser UI languageBCP-47 language tag, e.g. 'en-US', 'es-MX'
continuousbooleanfalseKeep recording after each phrase is recognized

Emits

EventPayloadDescription
transcript[text: string, confidence: number]Fired for each interim result while the user is still speaking
final-transcript[text: string, confidence: number]Fired when the engine finalizes a recognized phrase
errorSpeechErrorFired on any recognition error

Slots

SlotScopeDescription
#mic-icon{ isListening: boolean }Replace the default microphone icon. Receives current state.
#transcript{ transcript: string, finalTranscript: string }Replace the transcript display area
vue
<!-- Custom mic icon that changes with state -->
<VueSpeechRecorder>
  <template #mic-icon="{ isListening }">
    {{ isListening ? '🔴' : '🎙️' }}
  </template>
</VueSpeechRecorder>

Continuous Mode

In continuous mode the component keeps listening and fires final-transcript for each recognized phrase. The microphone stays active until the user clicks the button to stop, or until stop() is called programmatically.

vue
<VueSpeechRecorder
  :continuous="true"
  @final-transcript="(t) => messages.push(t)"
/>

Theming

Uses the same CSS custom properties as VueSpeechPlayer:

css
--vts-primary: #6366f1;      /* button background */
--vts-recording-color: #ef4444; /* pulse animation when active */
--vts-bg: #ffffff;
--vts-border: #e5e7eb;
--vts-radius: 8px;

Browser Support

BrowserSupport
Chrome
Edge
Safari✅ (requires user gesture)
FirefoxSpeechRecognition not supported

The component automatically hides itself (renders nothing) when isSupported is false.

Released under the MIT License.