Typix LogoTypix
Extensions

Speech to Text

Voice dictation input for the editor

The Speech to Text extension enables voice-to-text dictation using the Web Speech API.

Demo

Typix
Loading preview…
import {  createEditorConfig,  defaultExtensionNodes,  defaultTheme,  EditorContent,  EditorRoot,} from "@typix-editor/react";import { SpeechToTextExtension } from "@typix-editor/extension-speech-to-text";import { Toolbar } from "./Toolbar";const config = createEditorConfig({  extensionNodes: defaultExtensionNodes,  theme: defaultTheme,});export default function SpeechToTextExample() {  return (    <EditorRoot config={config}>      <div className="editor-container">        <Toolbar />        <EditorContent placeholder="Click the mic button and speak..." />      </div>      <SpeechToTextExtension />    </EditorRoot>  );}

Installation

pnpm add @typix-editor/extension-speech-to-text
npm install @typix-editor/extension-speech-to-text
yarn add @typix-editor/extension-speech-to-text

Setup

import { SpeechToTextExtension } from '@typix-editor/extension-speech-to-text';

function MyEditor() {
  return (
    <EditorRoot>
      <EditorContent />
      <SpeechToTextExtension />
    </EditorRoot>
  );
}

With the useSpeechToText hook

import { useSpeechToText, isSpeechRecognitionSupported } from '@typix-editor/extension-speech-to-text';

function VoiceButton() {
  const { isListening, start, stop } = useSpeechToText();

  if (!isSpeechRecognitionSupported()) {
    return null;
  }

  return (
    <button onClick={isListening ? stop : start}>
      {isListening ? 'Stop' : 'Dictate'}
    </button>
  );
}

Exports

ExportTypeDescription
SpeechToTextExtensionComponentThe speech-to-text plugin
SpeechToTextExtensionPropsTypeProps type
useSpeechToTextHookControl speech recognition
isSpeechRecognitionSupportedFunctionCheck browser support
SPEECH_TO_TEXT_COMMANDLexical CommandCommand for speech results

Browser support

The Web Speech API is required. Check support before rendering:

if (isSpeechRecognitionSupported()) {
  // Safe to use speech-to-text
}

The Web Speech API is not supported in all browsers. It works best in Chrome and Edge.

On this page