Typix LogoTypix
Components

SpeechToTextButton

Browser speech-recognition toggle with idle / listening / unsupported visual states.

SpeechToTextButton is a single-button UI on top of the browser SpeechRecognition API. It pairs with extension-speech-to-text, which routes recognized text into the editor.

Install

npx typix ui add speech-to-text

The CLI also installs @typix-editor/extension-speech-to-text if needed.

Import

import {
  SpeechToTextButton,
  useSpeechToText,
} from "@/components/typix/main/speech-to-text";

Props

PropTypeDefaultDescription
classNamestringExtra class on the button.
listeningContentReactNodepulsing mic iconShown while listening.
idleContentReactNodemic iconShown when idle.
unsupportedContentReactNodemic-off iconShown when the browser doesn't support speech recognition.
hideWhenUnsupportedbooleanfalseHide the button entirely when unsupported.
onListeningChange(isListening: boolean) => voidCallback when listening state flips.

Hook

useSpeechToText returns the underlying state + actions:

const {
  isListening,
  isSupported,
  error,
  lastTranscript,
  start,
  stop,
  toggle,
} = useSpeechToText({
  onListeningChange: (on) => console.log("listening:", on),
});

Usage

import { SpeechToTextButton } from "@/components/typix/main/speech-to-text";

<SpeechToTextButton hideWhenUnsupported />

On this page