use-speech-recognition
Transcribe speech with the Web Speech API.
| Package | @vizejs/composable/use-speech-recognition |
| Own the source | vize lib pull composable:use-speech-recognition |
| Runtime exports | useSpeechRecognition |
| Gzip budget | 2304 B |
Minimal setup
Use a Vue 3.5+ project with Vue SFC compilation configured (see Vite+ integration).
vp install @vizejs/composable
Import the entry directly. Call lifecycle-bound utilities inside <script setup> so cleanup follows the component scope; consult the runtime contract for this entry's SSR and hydration behavior.
import { useSpeechRecognition } from "@vizejs/composable/use-speech-recognition";
Try it
Dictate a search query
Turn speech into text with live interim results.
What to observe: Start dictation listens where the API exists; interim words appear while speaking and the final text after a pause.
continuous keeps listening across pauses. Recognition may send audio to a server, depending on the browser. Every example renders a neutral message until it mounts, so server and client markup match, and then explains what to do when the browser lacks the API.
Compare the initial and interacted states


Copy the example
Save this complete SFC in your Vue project. Its public imports and source are the same ones executed in the preview.
<script setup lang="ts">
import { useMounted } from "@vizejs/composable/use-mounted";
import { useSpeechRecognition } from "@vizejs/composable/use-speech-recognition";
const mounted = useMounted();
const { supported, listening, result, interimResult, toggle } = useSpeechRecognition({
lang: "en-US",
interimResults: true,
});
</script>
<template>
<div class="composable-example">
<p>Dictate a search query instead of typing it.</p>
<button type="button" :disabled="!mounted || !supported" @click="() => toggle()">
{{ listening ? "Stop listening" : "Start dictation" }}
</button>
<p>Heard: {{ result || interimResult || "…" }}</p>
<output aria-live="polite">{{
!mounted
? "Checking browser support…"
: supported
? listening
? "Listening."
: "Ready to listen."
: "Speech recognition is not available in this browser."
}}</output>
</div>
</template>
Runtime contract
| Utility | Category | Stability | SSR | Hydration | Cleanup | Targets | Host globals | Uses |
|---|---|---|---|---|---|---|---|---|
useSpeechRecognition |
media | experimental | deterministic-fallback | caller-managed | reactive-scope | web, desktop | window |
— |
API
useSpeechRecognition
Transcribe speech with the Web Speech API. result accumulates the final transcript of the current session and interimResult the text still being recognized. Options are applied each time listening starts, so a reactive lang takes effect on the next start. Errors are normalized to a closed SpeechRecognitionErrorCode union and exposed through error rather than thrown. The recognizer is aborted and its listeners removed when the owning reactive scope stops. Server rendering: no recognizer is created; supported and listening are false and the transcripts are empty.
function useSpeechRecognition( options: UseSpeechRecognitionOptions = {}, ): SpeechRecognitionControls
const speech = useSpeechRecognition({ lang: "ja-JP" });
speech.start();
watch(speech.result, (text) => console.log(text));
Types
SpeechRecognitionAlternativeLike
One recognition hypothesis.
| Member | Type | Description |
|---|---|---|
transcript |
string |
Recognized text. |
confidence |
number |
Confidence between 0 and 1. |
SpeechRecognitionResultLike
One recognition result: an array-like list of alternatives.
| Member | Type | Description |
|---|---|---|
length |
number |
Number of alternatives. |
isFinal |
boolean |
Whether the result is final (no longer interim). |
SpeechRecognitionResultListLike
Array-like list of every result of the current session.
| Member | Type | Description |
|---|---|---|
length |
number |
Number of results. |
SpeechRecognitionLike
Minimal SpeechRecognition instance consumed by useSpeechRecognition.
| Member | Type | Description |
|---|---|---|
lang |
string |
BCP 47 language tag. |
continuous |
boolean |
Keep listening after the first final result. |
interimResults |
boolean |
Report interim (non-final) results. |
maxAlternatives |
number |
Maximum alternatives per result. |
start |
() => void |
Start listening. Throws InvalidStateError when already started. |
stop |
() => void |
Stop listening and deliver a final result. |
abort |
() => void |
Stop listening without delivering a result. |
SpeechRecognitionFailure
Recognition failure reported by useSpeechRecognition.
| Member | Type | Description |
|---|---|---|
code |
SpeechRecognitionErrorCode |
Normalized error code. |
message |
string |
Implementation-provided message, possibly empty. |
UseSpeechRecognitionOptions
Options for useSpeechRecognition.
| Member | Type | Description |
|---|---|---|
lang? |
MaybeRefOrGetter<string> |
Recognition language, applied when listening starts. |
continuous? |
boolean |
Keep listening after the first final result. |
interimResults? |
boolean |
Report interim results through interimResult. |
maxAlternatives? |
number |
Maximum alternatives per result. |
host? |
MaybeRef<SpeechRecognitionHost | null | undefined> |
Recognizer constructor for alternate runtimes and tests. A ref (not a getter) because the host itself is a constructor function. |
SpeechRecognitionControls
Reactive state and actions returned by useSpeechRecognition.
| Member | Type | Description |
|---|---|---|
supported |
ComputedRef<boolean> |
Whether a speech recognizer is available. |
listening |
Readonly<Ref<boolean>> |
Whether the recognizer is listening. |
result |
Readonly<Ref<string>> |
Concatenated final transcript of the current session. |
interimResult |
Readonly<Ref<string>> |
Concatenated interim transcript not yet final. |
alternatives |
Readonly<ShallowRef<readonly SpeechRecognitionAlternativeLike[]>> |
Alternatives of the most recent result. |
error |
Readonly<ShallowRef<SpeechRecognitionFailure | undefined>> |
Most recent recognition failure, cleared when listening starts. |
start |
() => boolean |
Start listening with the current options, clearing previous results. |
stop |
() => void |
Stop listening and keep the final result. |
abort |
() => void |
Stop listening immediately without a final result. |
toggle |
(value?: boolean) => void |
Start or stop listening. |