first commit

This commit is contained in:
Andy
2025-08-17 08:51:53 -04:00
commit c25be210c8
17 changed files with 263 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
# Podcast TTS Generator
## Overview
The Podcast TTS Generator is a Python application that automates the process of generating text-to-speech output for podcasts. It takes prompts from text files, generates detailed outlines using the ChatGPT API, creates scripts from those outlines, and finally synthesizes speech to produce audio files.
## Project Structure
```
podcast-tts-generator
├── src
│ ├── main.py # Entry point of the application
│ ├── chatgpt_api.py # Functions to interact with the ChatGPT API
│ ├── outline_generator.py # Class to create outlines from prompts
│ ├── script_creator.py # Class to generate scripts from outlines
│ ├── tts_engine.py # Class to synthesize speech from scripts
│ └── utils.py # Utility functions for file handling
├── prompts
│ └── sample_prompt.txt # Sample text prompt for testing
├── outputs
│ ├── outlines # Directory for generated outlines
│ ├── scripts # Directory for generated scripts
│ └── audio # Directory for generated audio files
├── requirements.txt # Project dependencies
└── README.md # Project documentation
```
## Installation
1. Clone the repository:
```
git clone <repository-url>
cd podcast-tts-generator
```
2. Install the required dependencies:
```
pip install -r requirements.txt
```
## Usage
1. Place your text prompts in the `prompts` directory. You can use the provided `sample_prompt.txt` as a template.
2. Run the application:
```
python src/main.py
```
3. The generated outlines, scripts, and audio files will be saved in the respective directories under `outputs`.
## Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue for any enhancements or bug fixes.
## License
This project is licensed under the MIT License. See the LICENSE file for more details.

View File

@@ -0,0 +1,3 @@
This file contains a sample text prompt that will be used to test the functionality of the application.
Welcome to our podcast! In this episode, we will explore the fascinating world of artificial intelligence and its impact on our daily lives. We'll discuss the latest advancements, ethical considerations, and what the future holds for AI technology. Join us as we dive deep into this exciting topic!

View File

@@ -0,0 +1,17 @@
import openai
import os
# Load your OpenAI API key from an environment variable or directly
API_KEY = os.getenv("OPENAI_API_KEY")
openai.api_key = API_KEY
def generate_outline(prompt: str) -> str:
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": prompt}
]
)
outline = response.choices[0].message['content']
return outline.strip()

View File

@@ -0,0 +1,33 @@
import os
from chatgpt_api import generate_outline
from outline_generator import OutlineGenerator
from script_creator import ScriptCreator
from tts_engine import TTSEngine
from utils import read_prompt, save_output
def main():
# Define paths
prompt_file_path = 'prompts/sample_prompt.txt'
outline_output_path = 'outputs/outlines/outline.txt'
script_output_path = 'outputs/scripts/script.txt'
audio_output_path = 'outputs/audio/output.mp3'
# Read prompt from file
prompt = read_prompt(prompt_file_path)
# Generate outline
outline_generator = OutlineGenerator()
outline = outline_generator.create_outline(prompt)
save_output(outline_output_path, outline)
# Generate script from outline
script_creator = ScriptCreator()
script = script_creator.generate_script(outline)
save_output(script_output_path, script)
# Convert script to speech
tts_engine = TTSEngine()
tts_engine.synthesize_speech(script, audio_output_path)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,7 @@
class OutlineGenerator:
def __init__(self, chatgpt_api):
self.chatgpt_api = chatgpt_api
def create_outline(self, prompt: str) -> str:
outline = self.chatgpt_api.generate_outline(prompt)
return outline

View File

@@ -0,0 +1,4 @@
class ScriptCreator:
def generate_script(self, outline: str) -> str:
script = f"Welcome to our podcast! Today, we will discuss the following topics:\n\n{outline}\n\nThank you for listening!"
return script

View File

@@ -0,0 +1,16 @@
class TTSEngine:
def synthesize_speech(self, script: str, output_file: str) -> None:
import pyttsx3
# Initialize the text-to-speech engine
engine = pyttsx3.init()
# Set properties before adding anything to speak
engine.setProperty('rate', 150) # Speed percent (can go over 100)
engine.setProperty('volume', 1) # Volume 0-1
# Save the speech to a file
engine.save_to_file(script, output_file)
# Wait for the speech to finish
engine.runAndWait()

View File

@@ -0,0 +1,7 @@
def read_prompt(file_path: str) -> str:
with open(file_path, 'r') as file:
return file.read()
def save_output(file_path: str, content: str) -> None:
with open(file_path, 'w') as file:
file.write(content)