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

tts-speak

v1.1.1

Published

A standard Text To Speech wrapper with multiple providers support. Once the sound file is generated it's play the sound from cache.

Downloads

22

Readme

tts-speak

A standard Text To Speech wrapper with multiple providers support.

Once the sound file is generated, find an installed audio player and play the sound.

Features

  • One wrapper for all tts providers (ideal for testing)
  • Multiplatform Audio Playing (use package 'speaker' for that)
  • Thanks to 'jkeylu/node-mpg123-util' for the speaker volume !
  • Cache generated audio files (and protect your ratio against limitation for online providers)
  • Multilingual

Installation

npm install --save tts-speak

TTS Providers

You can use one of those providers to generate audio files from your text :

  • tts.js : A local tts engine, that is not perfect but which support many languages
  • api.voicerss.org : An API required service with beautiful voices and a large language support
  • google : Use the well known translate_tts service from google

Example code :

// Create the wrapper with "tts.js" provider with full options
var Speak = require('tts-speak');
var speak = new Speak({
    tts: {
        engine: 'tts',                  // The engine to use for tts
        lang: 'en-us',                  // The voice to use
        amplitude: 100,                 // Amplitude from 0 to 200
        wordgap: 0,                     // Gap between each word
        pitch: 50,                      // Voice pitch
        speed: 60,                      // Speed in %
        cache: __dirname + '/cache',    // The cache directory were audio files will be stored
        loglevel: 0,                    // TTS log level (0: trace -> 5: fatal)
        delayAfter: 700                 // Mark a delay (ms) after each message
    },
    speak: {
        volume: 80,                     // Audio player volume
        loglevel: 0                     // Audio player log level
    },
    loglevel: 0                         // Wrapper log level
});

api.voicerss.org

To use this provider, you have to request an API key by registering on http://www.voicerss.org/api/demo.aspx

Example code :

// Create the wrapper with "voicerss" provider with full options
var Speak = require('tts-speak');
var speak = new Speak({
    tts: {  
        engine: {                       // The engine to use for tts
            name: 'voicerss',           
            key: 'XXXXXXXXXXXXXXX',     // The API key to use
        },
        lang: 'en-us',                  // The voice to use
        speed: 60,                      // Speed in %
        format: 'mp3',                  // Output audio format
        quality: '44khz_16bit_stereo',  // Output quality
        cache: __dirname + '/cache',    // The cache directory were audio files will be stored
        loglevel: 0,                    // TTS log level (0: trace -> 5: fatal)
        delayAfter: 0                   // Mark a delay (ms) after each message
    },
    speak: {
        volume: 80,                     // Audio player volume
        loglevel: 0                     // Audio player log level
    },
    loglevel: 0                         // Wrapper log level
});

Google

// Create the wrapper with "google" provider with full options
var Speak = require('tts-speak');
var speak = new Speak({
    tts: {
        engine: 'google',               // The engine to use for tts
        lang: 'en-us',                  // The voice to use
        cache: __dirname + '/cache',    // The cache directory were audio files will be stored
        loglevel: 0,                    // TTS log level (0: trace -> 5: fatal)
        delayAfter: 500                 // Mark a delay (ms) after each message
    },
    speak: {
        volume: 80,                     // Audio player volume
        loglevel: 0                     // Audio player log level
    },
    loglevel: 0                         // Wrapper log level
});

Usage

Once the speak instance is ready, you can generate and play tts.

speak.once('ready', function() {

    // Chaining
    speak
        .say("Hello and welcome here !")
        .wait(1000)
        .say({
            src: 'Parlez-vous français ?',
            lang: 'fr-fr',
            speed: 30
        });

    // Catch when all queue is complete
    speak.once('idle', function() {
        speak.say("Of course, with my new text to speech wrapper !");
    });

    // Will stop and clean all the queue
    setTimeout(function() {
        speak.stop();
        speak.say('Ok, abort the last queue !')
    }, 1000);

});

Chainable Methods

speak.say(obj)

obj can be a string or an object that is able to override default config.

speak.wait(ms)

ms indicates the time in milliseconds to wait before continue.

speak.stop()

Clean the queue and kill audio player if playing.

Events (on or once)

speak.on('ready', fn)

When all interfaces are ready.

speak.on('idle', fn)

When queue is complete after a job.

speak.on('play', fn)

When a sound file is played.

speak.on('pause', fn)

When a pause is marked.

speak.on('stop', fn)

When all jobs are canceled.