Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

speak-ez

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

speak-ez

Browser Text-to-Speech (TTS using WebSpeech API) made easy

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

SpeakEZ

SpeakEZ is a lightweight TypeScript library that simplifies the use of the Web Speech API for text-to-speech functionality in web applications. It provides an easy-to-use interface for configuring speech parameters, selecting voices, and handling speech synthesis with improved sentence splitting for better results.

Features

  • Simple and intuitive API for text-to-speech synthesis.
  • Configurable speech parameters: volume, rate, pitch, and voice selection.
  • Automatic sentence splitting for improved speech quality.
  • Promise-based interface for easy integration with modern JavaScript/TypeScript applications.

Installation

You can install SpeakEZ via npm:

npm install speak-ez

Usage

Here's a basic example of how to use SpeakEZ in your project:

import SpeakEZ from 'speak-ez';

const speakWords = async (text: string) => {
	// Create an instance of SpeakEZ
	const ez = new SpeakEZ();

	// Check for browser support
	if (!ez.isSupportedBrowser) {
		console.error('Speech Synthesis is not supported in this browser.');
		return;
	}

	// Speak the provided text
	ez.speak(text);
};

speakWords('Hello world!');

API

new SpeakEZ()

Creates a new instance of SpeakEZ with optional configuration.

init(config?)

Initializes the SpeakEZ instance with the provided configuration and fetches available voices. This is not strictly necessary unless you want to set a custom voice. Individual properties can be set directly on the instance.

config Object Properties

  • lang: Language code for selecting the default voice (e.g., 'en-US').
  • volume: Volume level (0.0 to 1.0).
  • rate: Speech rate (0.1 to 10).
  • pitch: Speech pitch (0.0 to 2.0).
  • voice: Selected voice for speech synthesis (string or SpeechSynthesisVoice).
  • shouldSplitSentences: Boolean indicating whether to split text into sentences for better speech synthesis
  • voiceLoadTimeoutInMilliseconds: Timeout in milliseconds to wait for voices to load (default: 1000).

speak(text, options?)

Speaks the provided text with optional event listeners.

text

The text to be spoken.

options Object Properties

  • listeners: An object containing event listeners for speech synthesis events (start, end, error, pause, resume, mark, boundary).
  • interrupt: Boolean indicating whether to interrupt ongoing speech (default: false).

pause()

Pauses the current speech synthesis.

resume()

Resumes the paused speech synthesis.

cancel()

Cancels the current speech synthesis.

Properties

  • isSupportedBrowser: Boolean indicating if the browser supports Speech Synthesis.
  • voices: Array of available speech synthesis voices.
  • volume: Volume level (0.0 to 1.0).
  • rate: Speech rate (0.1 to 10).
  • pitch: Speech pitch (0.0 to 2.0).
  • shouldSplitSentences: Boolean indicating whether to split text into sentences for better speech synthesis
  • voice: Selected voice for speech synthesis.
  • speaking: Boolean indicating if speech synthesis is currently in progress.
  • pending: Boolean indicating if speech synthesis is pending.
  • paused: Boolean indicating if speech synthesis is paused.

License

SpeakEZ is licensed under the MIT License. See the LICENSE file for more information.

Keywords

web speech api

FAQs

Package last updated on 13 Dec 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