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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webbro-software/voice-js

v1.0.7

Published

Web Speech Api

Downloads

514

Readme

voice-js

voice-js is a JavaScript library for converting text to speech and speech to text, with customizable options for language, volume, rate, and pitch. It also provides a utility to fetch available voices for enhanced text-to-speech experiences.

Installation

npm install @webbro-software/voice-js

Features

  • Text-to-Speech: Convert text to spoken audio with customizable settings.
  • Speech-to-Text: Convert spoken words to text using the Web Speech API.
  • Voice Management: Retrieve available voices for text-to-speech, with error handling for unsupported environments.

Usage

Importing the Library

import {
  speechToText,
  textToSpeech,
  getVoices,
} from "@webbro-software/voice-js";

1. Text-to-Speech

The textToSpeech function converts provided text into spoken audio, with options for language, volume, rate, pitch, and voice.

Example:

textToSpeech("Hello, world!", "en-US", 1, 1, 1, 5);

Parameters:

  • text (string): Text to be spoken.
  • lang (string): Language code for the voice (default: "en-US").
  • volume (number): Volume of the speech (range: 0 to 1, default: 1).
  • rate (number): Speed of the speech (range: 0.1 to 10, default: 1).
  • pitch (number): Pitch of the speech (range: 0 to 2, default: 1).
  • voice (number): Index of the voice to use from the available voices list (default: 5).

Note: Voice availability and the exact number of voices vary across browsers.

2. Speech-to-Text

The speechToText function listens to spoken input and returns it as a text string.

Example:

const recognition = speechToText();

recognition
  .getTranscript()
  .then((transcript) => console.log("Recognized Text:", transcript))
  .catch((error) => console.error("Error:", error));

// To stop listening
recognition.stopSpeech();

Methods:

  • getTranscript(): Starts listening and returns a promise with the recognized text. Includes error handling for issues such as unsupported environments or recognition failures.
  • stopSpeech(): Stops the current speech recognition session manually.

3. Get Available Voices

The getVoices function retrieves all available voices for text-to-speech, useful for selecting specific voices.

Example:

getVoices();

Usage:

The getVoices function logs the list of available voices to the console when window.speechSynthesis.onvoiceschanged fires, which occurs when new voices are loaded. This allows you to inspect and select voices for textToSpeech.

Error Handling

  • speechToText: Throws errors if the Web Speech API isn’t supported. Provides meaningful error messages if recognition fails, such as "Speech recognition error: network" or "Speech recognition ended without capturing results."
  • textToSpeech and getVoices: Both functions check for browser compatibility and handle unsupported environments gracefully.

Browser Compatibility

This library uses the Web Speech API, supported by most modern browsers. For speech recognition, ensure microphone access is enabled in the browser.

License

MIT License. See LICENSE for more details.