A Python package for Topcast
Project description
Topcast: Turn Text into Podcasts with TTS and Language Models
Topcast is a Python package that allows you to transform text into a podcast using Text-to-Speech (TTS) and language models. With Topcast, you can provide a text, and the package will create a podcast with an introduction, interview, conclusion, sound effects, and more. Topcast supports various TTS providers and language models.
##Example Implementation
from topcast.chatgpt_themes import Introduction, Interview, Conclusion, Summary
from topcast.tts_providers import ElevenLabs, GCP
import os
from topcast import generate, set_elevenlab_api_key, set_google_credentials, set_openai_api_key
from dotenv import load_dotenv
load_dotenv()
set_elevenlab_api_key(os.environ["ELEVENLAB_API_KEY"])
set_openai_api_key(os.environ["OPENAI_API_KEY"])
set_google_credentials('gcp-keyfile.json')
timeline = [
{
"audio_layers": [
{
"audio": 'sounds/jingle.wav',
"is_main": True,
}
],
},
{
"audio_layers": [
{
"audio": {
"content": "Portugal (Portuguese pronunciation: [puɾtuˈɣal]), officially the Portuguese Republic (Portuguese: República Portuguesa [ʁɛˈpuβlikɐ puɾtuˈɣezɐ]),[note 4] is a country located on the Iberian Peninsula, in southwestern Europe, and whose territory also includes the Atlantic archipelagos of the Azores and Madeira. It features the westernmost point in continental Europe, and its Iberian portion is bordered to the west and south by the Atlantic Ocean and to the north and east by Spain, the sole country to have a land border with Portugal. Its two archipelagos form two autonomous regions with their own regional governments. Lisbon is the capital and largest city by population.",
"theme": Introduction,
"tts_provider": ElevenLabs
},
"is_main": True,
}
],
"crossfade": 2400,
},
]
podcast = generate(timeline)
podcast.export("podcast_3.wav", format="wav")
##Installation Install the package using pip:
pip install topcast
##Usage
- Import the necessary modules and set the API keys:
from topcast.chatgpt_themes import Introduction, Interview, Conclusion, Summary
from topcast.tts_providers import ElevenLabs, GCP
import os
from topcast import generate, set_elevenlab_api_key, set_google_credentials, set_openai_api_key
from dotenv import load_dotenv
load_dotenv()
set_elevenlab_api_key(os.environ["ELEVENLAB_API_KEY"])
set_openai_api_key(os.environ["OPENAI_API_KEY"])
set_google_credentials('gcp-keyfile.json')
- Create a timeline with the desired podcast structure:
timeline = [
{
"audio_layers": [
{
"audio": 'sounds/jingle.wav',
"is_main": True,
}
],
},
{
"audio_layers": [
{
"audio": {
"content": "Portugal...",
"theme": Introduction,
"tts_provider": ElevenLabs
},
"is_main": True,
}
],
"crossfade": 2400,
},
]
- Generate and export the podcast:
podcast = generate(timeline)
podcast.export("podcast_output.wav", format="wav")
This will create a podcast using the given timeline and save it as a WAV file named podcast_output.wav. ##Customization You can customize your podcast by modifying the timeline list. Each element in the list represents a segment of the podcast. You can add more segments with different themes, TTS providers, and audio layers.
For example, if you want to add an interview segment, you can include it like this:
{
"audio_layers": [
{
"audio": {
"content": "Interview text...",
"theme": Interview,
"tts_provider": GCP
},
"is_main": True,
}
],
"crossfade": 2400,
}
You can also add sound effects or background music by adding additional audio layers:
{
"audio_layers": [
{
"audio": 'sounds/background_music.wav',
"is_main": False,
"volume": 0.3,
},
{
"audio": {
"content": "Text content...",
"theme": Conclusion,
"tts_provider": ElevenLabs
},
"is_main": True,
}
],
"crossfade": 2400,
}
This will add background music with a volume of 0.3 to the conclusion segment.
Remember to adjust the crossfade value for smoother transitions between segments.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.