4 Best Text-to-Speech Libraries for Node.js

Following are the best TTS libraries for Node.js:

say.js

say is a TTS library for node.js. It can send text from node.js to your speakers.

// automatically pick platform
const say = require('say')

// or, override the platform
const Say = require('say').Say
const say = new Say('darwin' || 'win32' || 'linux')

// Use default system voice and speed
say.speak('Hello!')

// Stop the text currently being spoken
say.stop()

// More complex example (with an OS X voice) and slow speed
say.speak("What's up, dog?", 'Alex', 0.5)

// Fire a callback once the text has completed being spoken
say.speak("What's up, dog?", 'Good News', 1.0, (err) => {
  if (err) {
    return console.error(err)
  }
  console.log('Text has been spoken.')
});

// Export spoken audio to a WAV file
say.export("I'm sorry, Dave.", 'Cellos', 0.75, 'hal.wav', (err) => {
  if (err) {
    return console.error(err)
  }

  console.log('Text has been saved to hal.wav.')
})

say.js has great documentation and is easy to use.

nodejs-text-to-speech

This is cloud Text-to-Speech API client for Node.js.

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Import other required libraries
const fs = require('fs');
const util = require('util');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();
async function quickStart() {
  // The text to synthesize
  const text = 'hello, world!';

  // Construct the request
  const request = {
    input: {text: text},
    // Select the language and SSML voice gender (optional)
    voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
    // select the type of audio encoding
    audioConfig: {audioEncoding: 'MP3'},
  };

  // Performs the text-to-speech request
  const [response] = await client.synthesizeSpeech(request);
  // Write the binary audio content to a local file
  const writeFile = util.promisify(fs.writeFile);
  await writeFile('output.mp3', response.audioContent, 'binary');
  console.log('Audio content written to file: output.mp3');
}
quickStart();

winsay

This is TTS module for Node.js on windows using Edge.js.

var winsay = require('winsay');

// no callback, fire and forget
winsay.speak("GLaDOS", "Hello, and welcome to the Aperture Science Enrichment Center");

// use default voice in System Preferences
winsay.speak(null, "Hello!");

// output some text to the console after the callback has completed
winsay.speak("Good News', 'You've won the internet!", function () {
     console.log("text to speech complete");
});
console.log("This text is printed before you win the internet.");

// syncronous speak function also available
winsay.speakSync("Red", "A wild Pikachu appears.");
console.log("This text is printed after you encounter the wild Pikachu.");

text-to-speech-nodejs

This is a sample Node.js application for the IBM Watson Text to Speech Service.

You just need to drop in the key as following then run the app.

TEXT_TO_SPEECH_IAM_APIKEY=X4rbi8vwZmKpXfowaS3GAsA7vdy17Qh7km5D6EzKLHL2
TEXT_TO_SPEECH_URL=https://gateway-wdc.watsonplatform.net/text-to-speech/api

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close