Generate high-quality TTS audio for podcasts and dialogues.
Project description
Podcast TTS
podcast_tts is a Python library for generating podcasts and dialogues using text-to-speech (TTS). It supports multiple speakers, background music, and precise audio mixing for professional-quality results.
Features
- Multi-Speaker Support: Generate dialogues with distinct speaker profiles.
- Premade Voices: Use premade speaker profiles (male1, male2, female2) included with the library or create custom profiles.
- Dynamic Speaker Generation: Automatically generates new speaker profiles if the specified speaker does not exist, saving the profiles in the
voicessubfolder for future use. - Consistent Role Assignment: Ensures consistency by assigning and reusing speaker profiles based on the speaker name.
- Channel-Specific Playback: Allows audio to be played on the left, right, or both channels for spatial separation.
- Text Normalization: Automatically normalize text, handle contractions, and format special cases.
- Background Music Integration: Add background music with fade-in/out and volume control.
- MP3 and URL Support: Use local MP3/WAV files or download music from a URL with caching.
- Output Formats: Save generated audio as WAV or MP3 files.
Installation
pip install podcast_tts
Usage
Generating Audio for a Single Speaker
import asyncio
from podcast_tts import PodcastTTS
async def main():
tts = PodcastTTS(speed=5)
await tts.generate_wav(
text="Hello! Welcome to our podcast.",
speaker="male1",
filename="output_audio.wav",
channel="both"
)
if __name__ == "__main__":
asyncio.run(main())
Example: Generating a Podcast with Music
The generate_podcast method combines dialogue and background music for a seamless podcast production.
import asyncio
from podcast_tts import PodcastTTS
async def main():
tts = PodcastTTS(speed=5)
# Define speakers and text
texts = [
{"male1": ["Welcome to the podcast!", "both"]},
{"female2": ["Today, we discuss AI advancements.", "left"]},
{"male2": ["Don't miss our exciting updates.", "right"]},
]
# Define background music (local file or URL)
music_config = ["https://example.com/background_music.mp3", 10, 3, 0.3]
# Generate the podcast
output_file = await tts.generate_podcast(
texts=texts,
music=music_config,
filename="podcast_with_music.mp3",
pause_duration=0.5,
normalize=True
)
print(f"Podcast saved to: {output_file}")
if __name__ == "__main__":
asyncio.run(main())
Music Configuration:
- [file/url, full_volume_duration, fade_duration, target_volume]
- file/url: Path to a local MP3/WAV file or a URL to download.
- full_volume_duration: Time (seconds) at full volume before dialogue starts and after ends.
- fade_duration: Time (seconds) for fade-in/out effects.
- target_volume: Volume level (0.0 to 1.0) during dialogue playback.
Premade Voices
PodcastTTS includes the following premade speaker profiles:
- male1
- male2
- female2
These profiles are included in the package's default_voices directory and can be used without additional setup.
Dynamic Speaker Generation
When a speaker profile is specified but does not exist, the library will automatically generate a new speaker profile and save it in the voices subfolder. This ensures consistent voice roles across different turns in a dialogue. For example:
texts = [
{"Narrator": ["Welcome to this exciting episode.", "left"]},
{"Expert": ["Today, we'll explore AI's impact on healthcare.", "right"]},
]
# If "Narrator" or "Expert" profiles do not exist, they will be generated dynamically.
The profiles are saved in the script's voices directory and reused automatically if the same speaker is used in the future for consistency.
Loading Existing Speaker Profiles
You can load any speaker profile by specifying its filename (without the .txt extension). Profiles are stored in the voices subfolder, so you don't need to specify the path explicitly.
# Assuming a speaker profile "Host.txt" exists in the voices subfolder
await tts.generate_wav("This is a test for an existing speaker.", "Host", "existing_speaker.wav")
Additional Notes
- The library uses ChatTTS for high-quality TTS generation.
- Text is automatically cleaned and split into manageable chunks, making it easy to generate audio for long scripts or conversations.
- The generated audio files are saved in WAV format, with support for channel-specific playback.
Contributing
Contributions are welcome! Feel free to submit issues or pull requests on the GitHub repository.
License
This project is licensed under the MIT License. See the LICENSE file for details.
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 podcast_tts-0.0.1.tar.gz.
File metadata
- Download URL: podcast_tts-0.0.1.tar.gz
- Upload date:
- Size: 12.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b1eeb73fdb9ed1fced40fbdc30c888b9598234d80c950047262a7febb8bbf18
|
|
| MD5 |
f2b2f7dda0fbd2f5b38f7ec65e823b36
|
|
| BLAKE2b-256 |
209648782f48c9b500e8ca9f722403ee5c6842113f1c7eb374e6b90956ea516b
|
File details
Details for the file podcast_tts-0.0.1-py3-none-any.whl.
File metadata
- Download URL: podcast_tts-0.0.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe173e603c121535a93337c730a57951d462a936902165a0c95205803d46873b
|
|
| MD5 |
f685c5ec9619b4707ac45ac911d25820
|
|
| BLAKE2b-256 |
1726a66c4d4820e141acb0e192ae0136d57fa0a4bcf28bd00dcf89c7b4a38063
|