Skip to main content

ospeak

PyPI Changelog Tests License

CLI tool for running text through the OpenAI Text to speech API and speaking or saving the result

See ospeak: a CLI tool for speaking text in the terminal via OpenAI for background on this project.

Installation

Install this tool using pipx:

pipx install ospeak

Note, on MacOS there's a broken dependency with Python 3.12 so instead run:

pipx install --python /path/to/python3.11 ospeak

This tool also depends on ffmpeg. You can install that on macOS using Homebrew like this:

brew install ffmpeg

Note that ospeak has dependencies that are currently incompatible with LLM (see this issue) so the two tools need to be installed in different virtual environments, hence the recommendation to use pipx.

Usage

To get your computer to say something, run:

ospeak "Hello there"

You will need an OpenAI API key. You can set that as an environment variable:

export OPENAI_API_KEY="..."

Or you can pass it using --token:

ospeak --token "..." "Hello there"

You can pipe content into the tool:

echo "Hello there" | ospeak

Use -v/--voice VOICE to select a voice. The default is alloy. The other options are:

  • echo
  • fable
  • onyx
  • nova
  • shimmer

You can pass -v all to hear all of the voices, each with the name of the voice spoken first.

ospeak "This is my voice" -v all

The -m/--model option can be used to select a different model. The default is tts-1. Use -m tts-1-hd for a higher quality model that takes slightly longer to generate audio:

ospeak "This is higher quality" -m tts-1-hd

To adjust the speed, pass -x/--speed with a value between 0.25 and 4 (the default is 1.0):

ospeak "This is my fast voice" -x 2

To write the audio to a file, pass -o/--output with a filename ending in either .mp3 or .wav:

ospeak "This is my voice" -o voice.mp3

This will not speak out loud. If you want it to also speak, add the -s/--speak option:

ospeak "This is my voice" -o voice.mp3 -s

ospeak --help

Usage: ospeak [OPTIONS] [TEXT]

  CLI tool for running text through OpenAI Text to speech

  Set the OPENAI_API_KEY environment variable to your OpenAI API key to avoid
  using the --token option every time.

  Example usage:

      ospeak "Everyone deserves a pelican" --voice alloy -x 1.5

Options:
  --version                       Show the version and exit.
  -v, --voice [alloy|echo|fable|onyx|nova|shimmer|all]
                                  Voice to use
  -m, --model TEXT                Model to use - defaults to tts-1
  -o, --output FILE               Save audio to this file on disk
  -x, --speed FLOAT RANGE         Speed of the voice  [0.25<=x<=4.0]
  -s, --speak                     Speak the text even when saving to a file
  --token TEXT                    OpenAI API key
  --help                          Show this message and exit.

Development

To contribute to this tool, first checkout the code. Then create a new virtual environment:

cd ospeak
python -m venv venv
source venv/bin/activate

Now install the dependencies and test dependencies:

pip install -e '.[test]'

To run the tests:

pytest

Release files for ospeak 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ospeak 0.3
File Size Uploaded
ospeak-0.3.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ospeak 0.3
File Interpreter ABI Platform
ospeak-0.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.0 kB

Release files / ospeak-0.3.tar.gz

Download URL ospeak-0.3.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ba3a44038d3701d632105bb0755b681297405fe0b84d1f402d2ab85488028b3f
BLAKE2b-256 checksum
How to use checksums
ada84b0b0c962bfe35076171790012826fda8ce4e78ee480bc5cc9babc1111a9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / ospeak-0.3-py3-none-any.whl

Download URL ospeak-0.3-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
084c16a797950381972860a7506dffe97735f7267398c30f350f50717a905aa6
BLAKE2b-256 checksum
How to use checksums
53908ca55938e59ebde58c0038c248898e0f1f068727ca2c40aa9d6d938267e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

This release

0.3 This release

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page