You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-transcribe

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-transcribe

React component for speech-to-text transcription with silence detection

0.1.0
latest
Source
npmnpm
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

React Transcribe

A React component for speech-to-text transcription with silence detection using the browser's Web Speech API.

Installation

npm install react-transcribe
# or
yarn add react-transcribe

Features

  • Real-time speech transcription
  • Silence detection with automatic pausing
  • Countdown timer for maximum silence duration
  • Customizable UI through render props pattern
  • Callback-based communication

Usage

import { SpeechToText } from 'react-transcribe';
import { useState } from 'react';

const MyComponent = () => {
  const [transcript, setTranscript] = useState('');

  // Handle speech updates
  const handleSpeech = (info) => {
    setTranscript(info.transcript);
    console.log('Interim:', info.interimTranscript);
  };

  // Handle listening state changes
  const handleSpeechToggle = (info) => {
    console.log('Listening:', info.isListening);
  };

  return (
    <SpeechToText 
      onSpeech={handleSpeech}
      onSpeechToggle={handleSpeechToggle}
      silenceDuration={1000}
      maxSilenceDuration={60000}
      countdownThreshold={10000}
      language="en-US"
    >
      {({ 
        listening, 
        isActivelySpeaking, 
        silenceCountdown, 
        transcript, 
        interimTranscript,
        toggleListening 
      }) => (
        <div>
          <button onClick={toggleListening}>
            {listening ? 'Stop Listening' : 'Start Listening'}
          </button>
          
          <div>
            {listening
              ? isActivelySpeaking
                ? 'Active Speech Detected'
                : silenceCountdown
                  ? `No Speech Detected (${silenceCountdown}s)`
                  : 'Waiting for Speech'
              : 'Paused'
            }
          </div>
          
          <div>
            <h3>Transcript:</h3>
            <p>{transcript}</p>
          </div>
        </div>
      )}
    </SpeechToText>
  );
};

Props

PropTypeDescriptionDefault
onSpeechFunctionCallback triggered when speech is detected-
onSpeechToggleFunctionCallback triggered when recognition is toggled-
childrenReactNode or FunctionEither React elements or a render function that receives component state-
silenceDurationnumberDuration of silence (ms) before pausing active speaking state1000
maxSilenceDurationnumberMaximum allowed silence duration (ms) before stopping60000
countdownThresholdnumberWhen to start showing countdown (ms)10000
languagestringSpeech recognition language'en-US'

Callback Information

onSpeech callback

Receives an object with:

{
  transcript: string;       // The complete transcription 
  interimTranscript: string; // In-progress transcription
  resetTranscript: () => string | null; // Function to reset transcript and return previous value
}

onSpeechToggle callback

Receives an object with:

{
  isListening: boolean;     // Whether speech recognition is active
  type: 'device';           // The type of toggling (always 'device' for now)
}

State Object (available in render props)

PropertyTypeDescription
listeningbooleanWhether speech recognition is active
isActivelySpeakingbooleanWhether user is actively speaking (resets after silence)
silenceCountdownnumberCountdown before auto-stopping (null when not counting down)
transcriptstringCurrent transcript text
interimTranscriptstringInterim (in-progress) transcript text
browserSupportsSpeechRecognitionbooleanWhether browser supports speech recognition
resetTranscriptfunctionReset the transcript
startListeningfunctionStart speech recognition
stopListeningfunctionStop speech recognition
toggleListeningfunctionToggle speech recognition on/off

Browser Support

This component uses the Web Speech API, which is supported in most modern browsers. Check browser compatibility for details.

License

MIT

Keywords

react

FAQs

Package last updated on 04 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts