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-cli

v5.4.0

Published

Command-line tool to convert text to speech

Downloads

55

Readme

Text-To-Speech CLI

Command-line tool to convert a text file of any size to speech using AWS Polly or Google Cloud Text-to-Speech.

Animation of the tool in action

Requirements / Installation

  • Node.js/npm v18+
  • ffmpeg
  • An Amazon Web Services (AWS) or Google Cloud Platform (GCP) account

You can then install the package globally:

$ npm install tts-cli -g

You'll also need to set up your computer:

Usage

$ tts [inputfile] outputfile [options]

Example:

# Using a text file as the input, changing the default voice, and specifying the AWS keys.
$ tts test.txt test.mp3 --voice Brian --access-key ABCDEFG --secret-key hwl500CZygitV91n

# Using Google Cloud Text-to-Speech.
$ tts test.txt test.mp3 --service gcp --language en-US

# Passing a string of text as the input.
$ echo "Hello world! How are you?" | tts test.mp3

Standard arguments:

  • inputfile is the text file you want to convert to speech. It should be encoded as UTF-8. If excluded, tts-cli will read in the text from stdin.
  • outfile is the filename to save the audio to.

Service options:

  • --access-key KEY -- AWS access key ID
  • --email EMAIL -- GCP client email address (required if private-key or private-key-file is used)
  • --private-key KEY -- GCP private key
  • --private-key-file FILE -- GCP private key file (.pem or .p12 file)
  • --project-file FILE -- GCP .json file with project info
  • --project-id ID -- GCP project ID (e.g. grape-spaceship-123)
  • --secret-key KEY -- AWS secret access key
  • --service TYPE -- Cloud service to use (aws or gcp) (default aws)
  • --throttle SIZE -- Number of simultaneous requests allowed against the API (default 5)

Audio options:

  • --effect ID -- Apply an audio effect profile. Can be specified multiple times.
  • --ffmpeg BINARY -- Path to the ffmpeg binary (defaults to the one in PATH)
  • --format FORMAT -- Target audio format (mp3, ogg, or pcm) (default mp3)
  • --gain GAIN -- Volume gain, where 0.0 is normal gain
  • --gender GENDER -- Gender of the voice (male, female, or neutral)
  • --language LANG -- Code for the desired language (default en-US for GCP, no default for AWS)
  • --lexicon NAME -- Apply a stored pronunciation lexicon. Can be specified multiple times.
  • --pitch PITCH -- Change in speaking pich, in semitones
  • --speed RATE -- Speaking rate, where 1.0 is normal speed
  • --region REGION -- AWS region to send requests to (default us-east-1)
  • --sample-rate RATE -- Audio frequency, in hertz. See the API docs for valid values.
  • --type TYPE -- Type of input text (text or ssml) (default text)
  • --voice VOICE -- Voice to use for the speech (default Joanna for AWS).

Note that not all services support all options. For example, AWS Polly does not understand the speed option. See the options documentation for more info.

What It Does

  • Splits the text into the maximum size allowed by the API (1500 characters for AWS, 5000 characters for Google Cloud).
  • Compresses the white space inside the text to minimize the cost.
  • Uses your credentials in ~/.aws/credentials (AWS) or the GOOGLE_APPLICATION_CREDENTIALS (Google Cloud) file.
  • Calls the API (in a throttled manner) to get each text part converted to audio.
  • Combines the audio together into a single file.

Troubleshooting

  • Make sure Node.js is working. Running node --version on the command line should give a version of v10.0.0 or higher.
  • Make sure ffmpeg is installed. Running ffmpeg -version on the command line should give you the version information.
  • Make sure you can connect to AWS or Google Cloud normally.
    • Going to https://polly.us-east-1.amazonaws.com/v1/speech (or whatever AWS region you're using) should give you a "Missing Authentication Token" message. You can use the AWS CLI tool to check your configuration -- installing that and running aws sts get-caller-identity should return your user info.
  • Run export DEBUG=* first (Linux or Mac) to turn on debugging output. On Windows you'll need to use set DEBUG=* (command prompt) or $env:DEBUG = "*" (PowerShell).

Contributing

Pull requests and suggestions are welcome. Create a new issue to report a bug or suggest a new feature.

Please add tests and maintain the existing styling when adding and updating the code. Run npm run lint to lint the code.

Small Print

Copyright 2017-2020 Eric Heikes.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This project is not affiliated with Amazon or Google.