πŸš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more β†’
Socket
Book a DemoInstallSign in
Socket

react-voice-search-widget

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-voice-search-widget

A plug-and-play React voice search widget using speech-to-text.

1.0.1
latest
Source
npm
Version published
Weekly downloads
4
-33.33%
Maintainers
1
Weekly downloads
Β 
Created
Source

πŸ”Š react-voice-search-widget

A plug-and-play React component that lets users search either by typing or using voice input (speech-to-text). Built for reusability, flexibility, and quick integration into any modern React application.

✨ Features

  • 🎀 Voice Input Support
    Capture audio from the microphone and transcribe it using a backend speech-to-text service (e.g., Vosk).

  • ⌨️ Text Input Support
    Supports both voice and manual text input in the same field.

  • πŸ” Real-Time Search
    Automatically queries a backend search API as you speak or type (with debounce).

  • 🎯 Keyword Highlighting
    Matched words are highlighted in the search results and transcript text.

  • βš›οΈ Modular and Reusable
    Packaged as a standalone React component that can be embedded in any React app.

  • πŸ’¬ Error Handling
    Includes fallback for unsupported browsers and clear messages when audio isn't captured or no results are found.

πŸ“¦ Installation

Install the component via NPM:

npm install react-voice-search-widget
# or
yarn add react-voice-search-widget

πŸš€ Usage

import React from 'react';
import VoiceInput from 'react-voice-search-widget';

function App() {
  return (
    <div style={{ maxWidth: 800, margin: '0 auto', padding: '1rem' }}>
      <VoiceInput />
    </div>
  );
}

export default App;

🧱 Component Overview

VoiceInput.tsx

The main component that handles:

  • Microphone access
  • Recording and sending audio to the backend
  • Typing + voice input management
  • Displaying real-time search results

SearchResults.tsx

Displays the result list and highlights matched keywords.

UnsupportedBrowserFallback.tsx

Renders a fallback message if the browser doesn't support MediaRecorder or microphone access.

πŸ› οΈ Backend API Expectations

Your backend should expose two endpoints:

/api/transcribe (POST)

  • Accepts an audio file (multipart/form-data) and returns a JSON { text: "transcribed text" }.

/search?q=query (GET)

  • Accepts a search query and returns results in the following format:
{
  "results": [
    {
      "id": "1",
      "name": "<highlighted text>",
      "category": "<highlighted category>",
      "matchedWords": ["keyword1", "keyword2"]
    }
  ]
}

πŸ”— Example backend repo: speech-to-text (GitHub)

πŸ§ͺ Development & Build

To work locally and customize:

# Start dev server
npm run dev

# Lint the code
npm run lint

# Build for production
npm run build

🧩 Project Structure

react-voice-search-widget/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€components/
β”‚   β”‚    β”œβ”€β”€ VoiceInput.tsx
β”‚   β”‚    β”œβ”€β”€ SearchResults.tsx
β”‚   β”‚    β”œβ”€β”€ UnsupportedBrowserFallback.tsx
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── types.ts
β”‚   └── assets/
β”‚   β”‚    └── microphone-icon.webp
β”‚   β”œβ”€β”€ App.tsx
β”‚   β”œβ”€β”€ main.tsx
β”‚   β”œβ”€β”€ style.css
β”œβ”€β”€ dist/              # Compiled output
β”œβ”€β”€ package.json
β”œβ”€β”€ tsconfig.json
β”œβ”€β”€ vite.config.ts
└── README.md

🎨 Styling

Tailwind CSS is used for styling. If your host app uses Tailwind, styles will integrate seamlessly. Otherwise, you may want to adjust or override styles accordingly.

πŸ“Œ Customization (Coming Soon)

Planned for future versions:

  • Props to override API endpoints
  • Custom result renderers
  • Adjustable debounce delay
  • Theming via CSS variables

πŸ“ƒ License

MIT License

πŸ™‹β€β™€οΈ Maintainer

@aarathi01
Contributions and feedback are welcome!

Keywords

react

FAQs

Package last updated on 25 May 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