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

speakertts

v1.0.3

Published

SpeakerTTS is a text-to-speech (TTS) module that converts written text into speech using built-in functions on your computer. It provides an easy and convenient way to generate high-quality speech from text input. The module is made similar to say.js, but

Downloads

47

Readme

SpeakerTTS is a text-to-speech (TTS) module that converts written text into speech using built-in functions on your computer. It provides an easy and convenient way to generate high-quality speech from text input. The module is made similar to say.js, but with small improvements and more convenient documentation.

Installation

You can install speakertts using npm with the following command:

npm install speakertts

Usage

To use speakertts, you can require the package like this:

const speaker = require('speakertts');

Alternatively, if you want to use a specific platform, you can create a new instance of the speaker class with the desired platform as a parameter:

const Speaker = require('speakertts').Speaker;
const speaker = new Speaker('darwin' || 'win32' || 'linux');

Functions

1. speak()

To speak text, use the speak method:

speaker.speak(text(String), voice(String), speed(Number), encoding(String), callback(Function))
  • text - Text you want to hear
  • voice (optional) - Voice that will read read the text
  • speed (optional) - Reading speed. 1 = 100%, 0.5 = 50%, 2 = 200%, etc. Default value is 1
  • encoding (optional) - Just encoding
  • callback (optional) - Callback to handle error and add final event

Full example

const speaker = require('speakertts');

speaker.speak('Hello, world', 'Microsoft David Desktop', 1, 'ASCII', (error) => {
  if (error) {
    return console.error('Error speaking!', error)
  }

  console.log('text to speech complete')
})

2. stop()

To stop speech, use the stop method:

speaker.stop(callback(Function))
  • callback (optional) - Callback to handle error and add final event

Full example

const speaker = require('speakertts');

speaker.speak('Long and uninteresting speech', 'Microsoft David Desktop', 1, 'ASCII', (error) => {
  if (error) {
    return console.error('Error speaking!', error)
  }

  console.log('text to speech complete')
})

setTimeout(() => {
    speaker.stop((error) => {
    if (error) {
        console.error('Stop playback error:', error);
    } else {
        console.log('Playback stopped');
    }
    });
}, 5000);

3. export()

To stop text, use the stop method:

speaker.export(text(String), voice(String), speed(Number), encoding(String), filename(String), callback(Function))
  • text - Text you want to hear
  • voice (optional) - Voice that will read read the text
  • speed (optional) - Reading speed. 1 = 100%, 0.5 = 50%, 2 = 200%, etc. Default value is 1
  • encoding (optional) - Just encoding
  • filename - Path on your device to which the file will be exported
  • callback (optional) - Callback to handle error and add final event

Full example

const speaker = require('speakertts')
const path = require('path')

speaker.export("Hello, world", 'Microsoft David Desktop', 0.75, path.join(__dirname, 'say-hello.wav'), (err) => {
  if (err) {
    return console.error(err)
  }

  console.log('Text has been saved to say-hello.wav.')
})

4. getInstalledVoices()

To get list of installed voices, use the getInstalledVoices method:

speaker.getInstalledVoices(callback(Function))
  • callback (optional) - Callback to handle error and add final event

Full example

const speaker = require('speakertts')
const path = require('path')

speaker.getInstalledVoices((error, voices) => {
    if (error) {
        console.error('Error:', error);
    } else {
        console.log('Installed voices:', voices);
    }
});

Encodings

Currently only the following encodings are available:

  • ASCII
  • UTF-8

Feature Matrix

Unfortunately, not every feature is supported on every platform. Pull requests are welcome!

Platform | Speak | Export | Stop | Speed | Voice | Encoding | List ---------|-------|--------|------|-------|-------|-----|------| macOS | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: Linux | :white_check_mark: | :no_entry_sign: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :no_entry_sign: | :no_entry_sign: Windows | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark:

macOS Notes

Voices in macOS are associated with different localities. To a list of voices and their localities run the following command:

say -v "?"

As an example, the default voice is Alex and the voice used by Siri is Samantha.

Windows Notes

To install voice use SAPI format

Linux Notes

Linux support requires Festival. As far as I can tell there is no sane way to get a list of available voices. The only voice that seems to work is voice_kal_diphone, which seems to be the default anyway.

The .export() method is not available.

Try the following command to install Festival with a default voice:

sudo apt-get install festival festvox-kallpc16k

Requirements

  • Mac OS X (comes with say)
  • Linux with Festival installed
  • Windows (comes with SAPI.SpVoice)