Skip to content
Calm motion: animations on this site only fade, with no movement

Voice input ​

A microphone button that turns speech into text

Lets a person speak instead of type, for example into the prompt input or a field for notes. It uses the Web Speech API of the browser, so it adds no library. To record sound as a file, use the audio recorder.

Basic
  • v-model is the text. Each finished phrase is added at the end, and each one also emits result. Put the same v-model on a field to type and speak into the same text.
  • A click starts the dictation, and a second click stops it. While the browser listens, the button is filled and a ring grows with the loudness of the voice. The words that are not final yet show in gray next to the button.
  • lang sets the language of the speech, such as id-ID. The default is the language of the page. With continuous (on by default), the dictation goes on after a pause.
  • Chrome, Edge, and Safari have the Web Speech API. In other browsers, the button is disabled, and a note says that speech to text is not available. Chrome sends the sound to a server to read it.
  • If the person does not allow the microphone, a note says so and the component emits error.
  • The button is a toggle with aria-pressed. A hidden status line says "Listening…" and "Dictation stopped". Change the words with labels or a label pack: start, stop, listening, stopped, unsupported, and denied.

Usage ​

ts
import { BlessVoiceInput } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
langstring—the language of the speech, for example `id-ID`; default: the language of the page
continuousbooleantruekeep listening after a pause, until the reader stops it
disabledboolean—
labelsPartial<{ start: string; stop: string; listening: string; stopped: string; unsupported: string; denied: string; }>—
modelValuestring""the text: each finished phrase is added at the end

Events

NamePayloadDescription
update:modelValue[value: string]
error[error: string]
result[text: string]

Released under the MIT License. Character names and artwork belong to their owners.