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

soundoftext-js

v1.0.2

Published

NodeJS client for SoundOfText API

Downloads

773

Readme

soundoftext-js

A NodeJS library for the SoundOfText API.

Install

Install with npm:

npm install soundoftext-js

or yarn:

yarn add soundoftext-js

Usage

This library supports four operations: create, location, request, and status.

You will most likely want to use create, as it has the simplest interface.

sounds.create

This function requests for a sound to be created, and polls the API until the sound is finished being created, eventually returning a URL that links to an MP3 file.

This function takes an object with two properties:

  • text - the text to be spoken
  • voice - the voice (language + accent) to use.

and returns the url for an MP3 file that you could then download.

const client = require('soundoftext-js');

client.sounds.create({ text:'Hello, world!', voice: 'en-US' })
  .then(soundUrl => {
    console.log(soundUrl); // https://soundoftext.nyc3.digitaloceanspaces.com/<sound-id>.mp3
  })
  .catch(e => {
    /* Reasons that the Promise might get rejected:
     * - after 60 seconds, it automatically times out
     * - the API might fail to create the sound or reject it
     * - other miscellaneous network issues
     */
  });

sounds.request

This function requests for a sound to be created, and returns an object containing the sound id.

This function takes an object with two properties:

  • text - the text to be spoken
  • voice - the voice (language + accent) to use

and returns an object containing the sound id.

const client = require('soundoftext-js');

client.sounds.request({ text: 'Hello, world!', voice: 'en-US' })
  .then(response => {
    console.log(response);
    /* One of:
     * { success: true, id: '<sound-id>' }
     * { success: false, message: '<error-message>' }
     */
  })
  .catch(e => {
    /* Reasons that the Promise might get rejected:
     * - API rejects the request
     * - other miscellaneous network issues
     */
  });

sounds.status

This function takes a sound id and returns the current status.

This function takes an object with one property:

  • id - the id for the sound

and returns an object containing the status of the sound.

const client = require('soundoftext-js');

client.sounds.request({ text: 'Hello, world!', voice: 'en-US' })
  .then(response => {
    return client.sounds.status({ id: response.id });
  })
  .then(status => {
    console.log(status);
    /* One of:
     * { status: 'Error', message: '<error-message>' }
     * { status: 'Pending' }
     * { status: 'Done', location: '<url-for-mp3-file>' }
     */
  })
  .catch(e => {
    /* Reasons that the Promise might get rejected:
     * - API rejects the request
     * - other miscellaneous network issues
     */
  });

sounds.location

This is a convenience wrapper for sounds.status, which starts polling regularly for the status to be 'Done', before returning the url for the mp3 file. It rejects the promise if it times out (~60 seconds) or if the API returns an 'Error' status.

This function takes an object with one property:

  • id - the id for the sound

and returns the url for the MP3 file.

const client = require('soundoftext-js');

client.sounds.request({ text: 'Hello, world!', voice: 'en-US' })
  .then(response => {
    return client.sounds.location({ id: response.id });
  })
  .then(location => {
    console.log(location); // https://soundoftext.nyc3.digitaloceanspaces.com/<sound-id>.mp3
  })
  .catch(e => {
    /* Reasons that the Promise might get rejected:
     * - after 60 seconds, it automatically times out
     * - the API might fail to create the sound or reject it
     * - other miscellaneous network issues
     */
  });

FAQ

What voices does this support?

You can find a list of language codes in the documentation for Sound of Text.

You could also use another package of mine called google-tts-langauges that is another JS library that exports all the language codes.