react-voice-search-widget
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 β€’ Public β€’ Published

πŸ”Š 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!


🌐 Related Projects

Package Sidebar

Install

npm i react-voice-search-widget

Weekly Downloads

3

Version

1.0.1

License

MIT

Unpacked Size

509 kB

Total Files

7

Last publish

Collaborators

  • aarathi01