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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@charivo/tts-player-web

v0.0.1

Published

Web Speech API TTS player for Charivo

Readme

@charivo/tts-player-web

Browser-native Text-to-Speech player using Web Speech API. No server or API key required!

Features

  • 🌐 Browser Native - Uses built-in Web Speech API
  • 🆓 Free Forever - No API costs or quotas
  • 🚀 Zero Config - Works out of the box
  • 🎵 Voice Options - Multiple built-in voices per language
  • Fast - No network latency

Installation

pnpm add @charivo/tts-player-web @charivo/core

Usage

Basic Setup

import { createWebTTSPlayer } from "@charivo/tts-player-web";

const player = createWebTTSPlayer();
await player.initialize();

// Speak!
await player.speak("Hello, world!");

Custom Configuration

import { WebTTSPlayer } from "@charivo/tts-player-web";

const player = new WebTTSPlayer({
  lang: "en-US",      // Language
  rate: 1.2,          // Speed (0.1 - 10)
  pitch: 1.0,         // Pitch (0 - 2)
  volume: 0.8         // Volume (0 - 1)
});

await player.initialize();
await player.speak("I speak faster now!");

With TTSManager (Recommended)

import { createWebTTSPlayer } from "@charivo/tts-player-web";
import { createTTSManager } from "@charivo/tts-core";

const player = createWebTTSPlayer({ rate: 1.1 });
const ttsManager = createTTSManager(player);

await ttsManager.initialize();
await ttsManager.speak("This is easier!");

Voice Selection

// List available voices
const voices = speechSynthesis.getVoices();
voices.forEach(voice => {
  console.log(voice.name, voice.lang);
});

// Use specific voice
const player = new WebTTSPlayer({
  lang: "en-US",
  voiceName: "Google US English" // Depends on browser
});

API Reference

Constructor

new WebTTSPlayer(options?: WebTTSOptions)

Options:

  • lang?: string - Language code (default: "en-US")
  • rate?: number - Speech rate 0.1-10 (default: 1.0)
  • pitch?: number - Pitch 0-2 (default: 1.0)
  • volume?: number - Volume 0-1 (default: 1.0)
  • voiceName?: string - Specific voice name (optional)

Methods

initialize()

Initialize the player.

await player.initialize();

speak(text, options?)

Convert text to speech.

await player.speak("Hello!");

// With custom options for this utterance only
await player.speak("Hello!", {
  rate: 1.5,
  pitch: 1.2
});

stop()

Stop current speech.

await player.stop();

destroy()

Clean up the player.

await player.destroy();

Language Support

Depends on your browser and OS. Common languages:

| Language | Code | |----------|------| | English (US) | en-US | | English (UK) | en-GB | | Spanish | es-ES | | French | fr-FR | | German | de-DE | | Italian | it-IT | | Japanese | ja-JP | | Korean | ko-KR | | Chinese (Mandarin) | zh-CN | | Portuguese | pt-BR |

Configuration Examples

Natural Voice

const player = createWebTTSPlayer({
  rate: 0.95,
  pitch: 1.05,
  volume: 0.9
});

Fast Robot

const player = createWebTTSPlayer({
  rate: 1.5,
  pitch: 1.5,
  volume: 1.0
});

Slow and Deep

const player = createWebTTSPlayer({
  rate: 0.8,
  pitch: 0.8,
  volume: 1.0
});

Browser Compatibility

| Browser | Support | Notes | |---------|---------|-------| | Chrome | ✅ Full | Best quality | | Edge | ✅ Full | Same as Chrome | | Safari | ✅ Full | Good quality | | Firefox | ⚠️ Limited | Basic voices only | | Opera | ✅ Full | Same as Chrome |

Pros & Cons

Pros ✅

  • Free - No API costs
  • Fast - No network latency
  • Private - All processing on device
  • Offline - Works without internet
  • Simple - Zero configuration

Cons ❌

  • Voice Quality - Not as natural as cloud TTS
  • Limited Voices - Depends on OS/browser
  • No Customization - Can't train custom voices
  • Browser Dependent - Quality varies by browser

When to Use

Use Web TTS when:

  • 🎯 Building a prototype or demo
  • 💰 Budget is a concern
  • 🔒 Privacy is important
  • 🚀 Need fast, offline TTS

Use Cloud TTS (OpenAI, etc.) when:

  • 🎵 Need high-quality, natural voices
  • 🎨 Want custom voice training
  • 🌍 Need consistent quality across platforms
  • 💼 Building production apps

Comparison with OpenAI TTS

| Feature | Web TTS | OpenAI TTS | |---------|---------|------------| | Cost | Free | $15 per 1M chars | | Quality | Good | Excellent | | Latency | None | ~1-2 seconds | | Offline | ✅ Yes | ❌ No | | Setup | Zero | API key needed | | Voice Options | OS-dependent | 6 voices |

Example: Mixed Approach

Use Web TTS for development, OpenAI for production:

const isDevelopment = process.env.NODE_ENV === "development";

const player = isDevelopment
  ? createWebTTSPlayer()
  : createOpenAITTSPlayer({ apiKey: process.env.OPENAI_API_KEY });

const ttsManager = createTTSManager(player);

Troubleshooting

No voices available

// Wait for voices to load
await new Promise(resolve => {
  if (speechSynthesis.getVoices().length) {
    resolve(null);
  } else {
    speechSynthesis.onvoiceschanged = () => resolve(null);
  }
});

Speech cuts off

This is a known browser bug. Call speechSynthesis.pause() and speechSynthesis.resume() periodically:

// Already handled in WebTTSPlayer implementation

Different voices on different browsers

This is expected. Voices are provided by the OS/browser.

License

MIT