npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

voicecapture-react

v0.2.0

Published

A library for integrating VLibras into React applications.

Downloads

770

Readme

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

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

| Prop | Type | Default | Description | |---------------------|-----------|--------------|----------------------------------------------------------------------------------------------| | start | boolean | false | Controls whether voice recognition starts (true) or stops (false). | | lang | string | "en" | Language for transcription (e.g., "pt" for Portuguese). | | mode | string | "fullscreen" | Display mode for the component. Options: "fullscreen" or "float". | | clipboard | boolean | false | If true, automatically copies the final transcript to the clipboard after recognition. | | onVoiceTranscript | function| undefined | Callback function to handle the final transcribed text. | | onDeactivate | function| undefined | Callback 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.