An open API service indexing awesome lists of open source software.

https://github.com/avimehenwal/web-speech-api

Project to demonstrate usage of web APIs to deal with voice data
https://github.com/avimehenwal/web-speech-api

voice web

Last synced: about 2 months ago
JSON representation

Project to demonstrate usage of web APIs to deal with voice data

Awesome Lists containing this project

README

          

# πŸŽ™ Speech API Lab

A **Text-to-Speech** and **Speech Recognition** demo built with **React 18 + Vite**, using the browser-native [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API). No backend, no external AI service β€” everything runs locally in your browser.

---

## 🌐 Live Demo

**[https://avimehenwal.github.io/web-speech-api/](https://avimehenwal.github.io/web-speech-api/)**

> Automatically deployed from the `main` branch via GitHub Actions.

[![Deploy to GitHub Pages](https://github.com/avimehenwal/web-speech-api/actions/workflows/gh-pages.yml/badge.svg)](https://github.com/avimehenwal/web-speech-api/actions/workflows/gh-pages.yml)

---

## Screenshots


Text-to-Speech Demo

Speech Recognition Demo



Text-to-Speech demo screen



Speech Recognition demo screen

## ✨ Features

| Feature | Details |
| --------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **Text-to-Speech** | Voice picker, rate / pitch / volume sliders, play / pause / resume / stop, live word-boundary highlighting |
| **Speech Recognition** | Continuous or single-shot mode, 12 language options, interim + final transcript, confidence score |
| **React hooks** | `useTTS` and `useSpeechRecognition` β€” clean, reusable, easy to extend |
| **No build-time API calls** | 100% client-side Web Speech API |

---

## πŸ–₯ Browser support

| Feature | Chrome | Edge | Safari | Firefox |
| ---------------------------------------- | ------ | ---- | ------ | ------- |
| Text-to-Speech (`SpeechSynthesis`) | βœ… | βœ… | βœ… | βœ… |
| Speech Recognition (`SpeechRecognition`) | βœ… | βœ… | βœ… | ❌ |

> **Tip:** For the best experience, use **Chrome** or **Edge** β€” they support both APIs and expose the most voices.

---

## πŸš€ Running locally

### Prerequisites

- [Node.js](https://nodejs.org/) **v18 or newer** (run `node -v` to check)
- **npm** (comes with Node) or **pnpm** / **yarn**

### Steps

```bash
# 1. Enter the project folder
cd speech-api-lab

# 2. Install dependencies (~30 seconds)
npm install

# 3. Start the dev server
npm run dev
```

Then open **http://localhost:5173** in your browser.

> The page auto-reloads whenever you edit a source file.

### Other commands

```bash
npm run build # Production build β†’ ./dist/
npm run preview # Serve the production build locally
```

---

## πŸ“ Project structure

```
speech-api-lab/
β”œβ”€β”€ index.html # HTML entry point
β”œβ”€β”€ vite.config.js # Vite configuration
β”œβ”€β”€ package.json
└── src/
β”œβ”€β”€ main.jsx # React root mount
β”œβ”€β”€ App.jsx # App shell, tab navigation
β”œβ”€β”€ index.css # Global CSS variables & animations
β”œβ”€β”€ hooks/
β”‚ β”œβ”€β”€ useTTS.js # ← All Text-to-Speech logic
β”‚ └── useSpeechRecognition.js # ← All Speech Recognition logic
└── components/
β”œβ”€β”€ UI.jsx # Shared primitives (Slider, Btn, StatusBar…)
β”œβ”€β”€ TTSPanel.jsx # Text-to-Speech tab
β”œβ”€β”€ SRPanel.jsx # Speech Recognition tab
└── CodeSnippet.jsx # Collapsible code viewer
```

---

## πŸ”§ Extending the app

### Add a new TTS feature (e.g. highlight full sentences)

Edit **`src/hooks/useTTS.js`** β€” the `onboundary` handler fires for both `"word"` and `"sentence"` boundary events:

```js
utt.onboundary = (e) => {
if (e.name === 'sentence') setCurrentSentence(text.substr(e.charIndex, e.charLength))
}
```

### Add more Speech Recognition languages

Edit the `LANGUAGES` array in **`src/components/SRPanel.jsx`**:

```js
{ code: 'ru-RU', label: 'Russian' },
{ code: 'nl-NL', label: 'Dutch' },
```

### Pipe SR transcript into TTS

In **`src/App.jsx`**, lift the transcript state up and pass it as the initial text prop to ``.

---

## πŸ“¦ Dependencies

| Package | Purpose |
| ---------------------- | ---------------------- |
| `react` + `react-dom` | UI framework |
| `vite` | Dev server & bundler |
| `@vitejs/plugin-react` | JSX transform for Vite |

Zero runtime dependencies beyond React itself.