Skip to main content

Convert text to speech using OpenAI's Text-to-Speech API

Project description

quick-tts

Convert text to speech using OpenAI's Text-to-Speech API. A simple, effective Python package that works as both a library and command-line tool.

Installation

pip install quick-tts

Usage

As a Library

from quick_tts import text_to_speech

# Basic usage
text_to_speech("Hello, world!", "hello.mp3")

# With custom options
text_to_speech(
    text="Good morning!",
    output_file="morning.wav",
    model="tts-1-hd",
    voice="nova"
)

As a Command-Line Tool

# Basic usage
quick-tts "Hello, world!" -o hello.mp3

# Read from file
quick-tts -f input.txt -o output.mp3

# Custom voice and model
quick-tts "Welcome!" --voice nova --model tts-1-hd -o welcome.mp3

# See all options
quick-tts --help

Configuration

Set your OpenAI API key as an environment variable:

export OPENAI_API_KEY=sk-your-api-key-here

Or pass it directly:

text_to_speech("Hello!", "hello.mp3", api_key="sk-your-api-key")

API Reference

text_to_speech(text, output_file="speech.mp3", model="tts-1-hd", voice="alloy", api_key=None)

Convert text to speech using OpenAI's API.

Parameters:

  • text (str): The text to convert to speech
  • output_file (str|Path): Path to save the audio file (default: "speech.mp3")
  • model (str): OpenAI TTS model ("tts-1" or "tts-1-hd", default: "tts-1-hd")
  • voice (str): Voice to use ("alloy", "echo", "fable", "onyx", "nova", "shimmer", default: "alloy")
  • api_key (str, optional): OpenAI API key (uses OPENAI_API_KEY env var if not provided)

Returns:

  • str: Absolute path to the generated audio file

Supported Voices

  • alloy - Balanced, versatile voice
  • echo - Clear, professional tone
  • fable - Warm, storytelling quality
  • onyx - Deep, authoritative voice
  • nova - Bright, engaging tone
  • shimmer - Soft, pleasant voice

Models

  • tts-1 - Standard quality, faster generation
  • tts-1-hd - High definition quality, more detailed audio

Requirements

  • Python 3.8+
  • OpenAI API key
  • openai>=1.86.0

License

MIT License - see LICENSE file for details.

Contributing

Issues and pull requests welcome at GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quick_tts-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quick_tts-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file quick_tts-0.1.0.tar.gz.

File metadata

  • Download URL: quick_tts-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for quick_tts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e58129acca42d236018eababfc530483c59ef5aee3de8c0f29dcb08c825093cb
MD5 6a9d9e65b0100a6ec2faa92929adc1da
BLAKE2b-256 22272ac6ca6866e425b064b532af03cd731058b4758f68adb970111f13919ca5

See more details on using hashes here.

File details

Details for the file quick_tts-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: quick_tts-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for quick_tts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 932477046c29aaa1ae0cee22ef140ae068ed0cffef0f693d6735b36910d214ee
MD5 2956e76e34fdce5d1078958b568f009b
BLAKE2b-256 1aa9d27ec2aaa6c174310fdb8fb7f6a46e7f8599b18b00b47685d9a7f51a5e92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page