New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

voicecapture-react

Package Overview
Dependencies
Maintainers
0
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

voicecapture-react

A library for integrating VLibras into React applications.

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
0
Created
Source

VoiceCapture Component

The VoiceCapture component is a React-based audio capture and transcription tool that leverages the browser's SpeechRecognition API. It provides an interactive UI to start, stop, and manage voice recognition, supporting multiple languages, display modes, and now includes clipboard integration to automatically copy the transcribed text.

Table of Contents

  • Installation
  • Usage
  • Props
  • Example
  • Features

Installation

Install the component:

npm install voicecapture-react

Usage

import { useState } from "react";
import VoiceCapture from 'voicecapture-react';

const MyComponent = () => {
  const [start, setStart] = useState(false);
  const handleTranscript = (transcript) => {
    console.log("Transcript:", transcript);
  };

  return (
    <VoiceCapture
      start={start}
      lang="en"
      mode="fullscreen"
      clipboard={true}
      onVoiceTranscript={handleTranscript}
      onDeactivate={() => setStart(false)}
    />
  );
};

Props

PropTypeDefaultDescription
startbooleanfalseControls whether voice recognition starts (true) or stops (false).
langstring"en"Language for transcription (e.g., "pt" for Portuguese).
modestring"fullscreen"Display mode for the component. Options: "fullscreen" or "float".
clipboardbooleanfalseIf true, automatically copies the final transcript to the clipboard after recognition.
onVoiceTranscriptfunctionundefinedCallback function to handle the final transcribed text.
onDeactivatefunctionundefinedCallback triggered when voice recognition stops.

Clipboard Integration

The clipboard prop enables automatic copying of the final transcript text to the clipboard once the voice recognition process is complete. This improves usability by allowing users to easily paste the transcribed text without any additional steps.

Example Usage with Clipboard:

<VoiceCapture
  start={start}
  lang="en"
  mode="fullscreen"
  clipboard={true}
  onVoiceTranscript={handleTranscript}
/>

Example

Below is an example using VoiceCapture with additional controls for language selection, display mode, and clipboard integration.

import { useState } from "react";
import VoiceCapture from "voicecapture-react";

function App() {
  const [start, setStart] = useState(false);
  const [transcript, setTranscript] = useState("");
  const [lang, setLang] = useState("en");
  const [mode, setMode] = useState<"fullscreen" | "float">("fullscreen");

  const handleVoiceTranscript = (text) => {
    setTranscript(text);
  };

  const openVoiceCapture = (selectedMode) => {
    setMode(selectedMode);
    setStart(true);
  };

  const handleDeactivate = () => {
    setStart(false);
  };

  return (
    <>
      <VoiceCapture
        start={start}
        lang={lang}
        mode={mode}
        clipboard={true}
        onVoiceTranscript={handleVoiceTranscript}
        onDeactivate={handleDeactivate}
      />
      <div>
        <h2>VoiceCapture Example</h2>

        <div>
          <button onClick={() => openVoiceCapture("fullscreen")}>Fullscreen Mode</button>
          <button onClick={() => openVoiceCapture("float")}>Float Mode</button>

          <label>
            Select Language:
            <select value={lang} onChange={(e) => setLang(e.target.value)}>
              <option value="en">English</option>
              <option value="pt">Portuguese</option>
              <option value="es">Spanish</option>
              <option value="fr">French</option>
            </select>
          </label>

          <label>
            Enable Clipboard:
            <input
              type="checkbox"
              checked={clipboard}
              onChange={(e) => setClipboard(e.target.checked)}
            />
          </label>
        </div>
      </div>

      {transcript && (
        <div>
          <h2>Transcript Results</h2>
          <textarea readOnly value={transcript} placeholder="Voice transcript will appear here..." />
        </div>
      )}
    </>
  );
}

export default App;

In this example:

  • Modes: Toggle between fullscreen and float display modes.
  • Languages: Select a language for speech recognition.
  • Clipboard: Option to enable or disable automatic copying of the transcript text.
  • Transcript Display: View the transcribed text once captured.

Features

  • Real-time Voice Transcription: Instantly capture and display voice input as text.
  • Clipboard Integration: Automatically copies the final transcript to the clipboard, making it easy to paste the text elsewhere.
  • Editable Transcripts: Users can modify the transcribed text through input fields or text areas.
  • Customizable Events: Easily handle transcription results and changes in voice recognition status.

Keywords

react

FAQs

Package last updated on 13 Nov 2024

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