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

@duyquangnvx/edge-tts

v3.0.3

Published

A TypeScript library for Microsoft Edge Text-to-Speech (TTS) with streaming support and browser playback capabilities.

Readme

Edge TTS

A TypeScript library for Microsoft Edge Text-to-Speech (TTS) with streaming support and browser playback capabilities.

Installation

npm install @duyquangnvx/edge-tts

Usage

Node.js Usage

import { Communicate } from '@duyquangnvx/edge-tts';

const communicate = new Communicate("Hello, world!", {
  voice: 'en-US-AriaNeural',
  rate: '+0%',
  volume: '+0%',
  pitch: '+0Hz'
});

for await (const chunk of communicate.stream()) {
  if (chunk.type === 'audio') {
    // Handle audio data
    console.log('Audio chunk received:', chunk.data.length, 'bytes');
  } else if (chunk.type === 'WordBoundary') {
    // Handle word boundary information
    console.log('Word boundary:', chunk.text, 'at offset:', chunk.offset);
  }
}

Browser Usage with Playback

For browser environments with audio playback support:

import { EdgePlayback } from '@duyquangnvx/edge-tts/browser';

const playback = new EdgePlayback({
  autoPlay: true,
  onProgress: (progress) => {
    console.log('Progress:', progress.currentTime, 'Current word:', progress.text);
  },
  onStateChange: (state) => {
    console.log('State changed:', state);
  },
  onError: (error) => {
    console.error('Playback error:', error);
  }
});

// Start speaking
await playback.speak("Hello, this is a streaming text-to-speech example!", {
  voice: 'en-US-AriaNeural',
  rate: '+0%',
  volume: '+0%',
  pitch: '+0Hz'
});

// Control playback
playback.pause();
playback.play();
playback.setVolume(0.8);
playback.stop();

// Cleanup when done
playback.dispose();

Browser Bundle Import

You can also import the entire browser bundle:

import { Communicate, EdgePlayback } from '@duyquangnvx/edge-tts/browser';

API Reference

Core Classes

Communicate

Main class for TTS communication with Edge services.

new Communicate(text: string, config?: TTSConfig)

Methods:

  • stream(): Returns an async iterator for streaming TTS chunks
  • close(): Closes the communication

EdgePlayback

Browser-specific class for audio playback with controls.

new EdgePlayback(options?: PlaybackOptions)

Methods:

  • speak(text: string, config?: TTSConfig): Start streaming and playing text
  • play(): Resume playback
  • pause(): Pause playback
  • stop(): Stop playback and reset
  • setVolume(volume: number): Set volume (0.0 to 1.0)
  • getVolume(): Get current volume
  • getState(): Get current playback state
  • getProgress(): Get current progress information
  • dispose(): Cleanup resources

Configuration

TTSConfig

interface TTSConfig {
  voice?: string;
  rate?: string;
  volume?: string;
  pitch?: string;
  // ... other Edge TTS options
}

PlaybackOptions

interface PlaybackOptions {
  autoPlay?: boolean;        // Auto-start playback (default: true)
  bufferSize?: number;       // Audio buffer size (default: 5)
  onProgress?: (progress: PlaybackProgress) => void;
  onStateChange?: (state: PlaybackState) => void;
  onError?: (error: Error) => void;
}

Examples

See the src/examples/ directory for complete usage examples:

  • basic-usage.ts: Basic TTS streaming
  • voice-management.ts: Voice selection and management
  • advanced-usage.ts: Advanced features and configurations

Run examples:

npm run example:basic
npm run example:voices
npm run example:advanced
npm run examples

Browser Support

The browser bundle requires:

  • Web Audio API support
  • Modern browser with ES2020+ support
  • HTTPS context (for Web Audio API)

Development

# Install dependencies
npm install

# Build
npm run build

# Development with watch
npm run dev

# Type checking
npm run typecheck

# Clean build artifacts
npm run clean

License

ISC