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 speechoutput_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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quick_tts-0.1.1.tar.gz.
File metadata
- Download URL: quick_tts-0.1.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92a5709bd68d6d30d30e9be0831e53a03aa331e0f000f727a441f79bbf4bc148
|
|
| MD5 |
92a891e25dd3f6af46d7eaf8513b8bc0
|
|
| BLAKE2b-256 |
88e9a8d6b28aa1e0c99bcb183a11a2d97a7ea2f557c9de5c195ac24232276652
|
File details
Details for the file quick_tts-0.1.1-py3-none-any.whl.
File metadata
- Download URL: quick_tts-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b734e0ab7d7a72cfdcf5c17edc22a509c04ee57b7dbf8a5de5122e4c9a515ce6
|
|
| MD5 |
a4b74ef13ccc521a82d136c199315a19
|
|
| BLAKE2b-256 |
4fc5fa4d32b229c1fb56ce9f99358adf5d8fe2e9f90bf7cdaf11375db7c2718a
|