voice-rss

3.0.0 • Public • Published

An API wrapper for the Voice RSS Text-To-Speech API

npm npm bundle size npm

The Voice RSS Text-To-Speech API creates a high quality audio stream with a very simple implementation. This npm module is a wrapper for this API to make it easy to implement in your Node or JavaScript projects.

Table of contents:

Quickstart

Before you begin

  1. Setup an API key

Installing the client library

// npm
npm install voice-rss --save-dev
 
// yarn
yarn add voice-rss --dev

Initiate the client library

// Imports the Voice RSS client library: es6 import (alternative 1)
import VoiceRSSWebApi from './voice-rss-api';
 
// Imports the Voice RSS client library: require (alternative 2)
const VoiceRSSWebApi = require('./voice-rss-api');
 
// Instantiates the client
const VoiceRSS = new VoiceRSSWebApi();
VoiceRSS.setApiKey('API_KEY');
 
// Instantiates the client with an api key
const VoiceRSS = new VoiceRSSWebApi('API_KEY');

Using the client library

Here are three examples of how to use the client library

// callback implementation
// the second argument is the options
// see "Default options" section below for available options and for setting options all at once
// see "Setting options" section below to set options one by one
VoiceRSS.getAudio('Hello World', {}, (err, audio) => {
    if (err) console.error(err);
    else new Audio(audio).play();
});
 
// promise implementation
// you can pass the options as the second argument, as in the callback implementation
VoiceRSS.getAudio('Hello World')
    .then(audio => new Audio(audio).play())
    .catch(error => console.log(error));
 
// async/await implementation
// you can pass the options as the second argument, as in the callback implementation
(async () => {
    const audio = await VoiceRSS.getAudio('Hello World');
    
    // play the audio
    new Audio(audio).play();
    
    // OR console log the audio (base64 encoding)
    console.log(audio);
})();
Setting options
VoiceRSS.setApiKey('API_KEY');
VoiceRSS.setLanguage('en-us');
VoiceRSS.setSpeechRate(0);
VoiceRSS.setAudioCodec('auto');
VoiceRSS.setAudioFormat('44khz_16bit_stereo');
VoiceRSS.setSSML(false);
VoiceRSS.setB64(false);
Getting options
VoiceRSS.getApiKey();
VoiceRSS.getLanguage();
VoiceRSS.getSpeechRate();
VoiceRSS.getAudioCodec();
VoiceRSS.getAudioFormat();
VoiceRSS.getSSML();
VoiceRSS.getB64();
Default options
const options = {
    hl: 'en-us',
    r: 0,
    c: 'mp3',
    f: '44khz_16bit_stereo',
    ssml: false,
    b64: false,
};
Available options

All of the available options can be found in the official documentation

Versioning

This library follows Semantic Versioning.

Contributing

Contributions welcome! See the Contributing Guide.

License

MIT

See LICENSE

To Do

  • 100% test coverage
  • Implement typescript
  • Minimize bundle size

Package Sidebar

Install

npm i voice-rss

Weekly Downloads

2

Version

3.0.0

License

MIT

Unpacked Size

276 kB

Total Files

22

Last publish

Collaborators

  • allurewebsolutions