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

49
.gitignore vendored Normal file
View File

@ -0,0 +1,49 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Virtual environments
.venv/
venv/
ENV/
env.bak/
venv.bak/
# Jupyter Notebook checkpoints
.ipynb_checkpoints
# VS Code settings
.vscode/
# Output folders
outputs/
# OS files
.DS_Store
Thumbs.db
# API keys and environment variables
.env
.env.*

0
README.md Normal file
View File

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)

View File

@ -0,0 +1 @@
Explain the Physical Layer (Layer 1) of the OSI Model in detail. Include its purpose, examples of technologies that operate at this layer, the common challenges or misunderstandings, what devices might be used at this layer and lastly, what tools, if any would be used to troubleshoot this layer

4
requirements.txt Normal file
View File

@ -0,0 +1,4 @@
openai>=1.0.0
gTTS==2.2.3
pydub==0.25.1
numpy>=1.23,<2.0

15
src/chatgpt_api.py Normal file
View File

@ -0,0 +1,15 @@
import openai
import os
def generate_outline(prompt: str) -> str:
openai.api_key = os.getenv('OPENAI_API_KEY')
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant that creates detailed podcast outlines."},
{"role": "user", "content": f"Create a detailed outline for a podcast episode based on this prompt: {prompt}"}
],
max_tokens=500
)
outline = response.choices[0].message['content'].strip()
return outline

34
src/main.py Normal file
View File

@ -0,0 +1,34 @@
import os
from src.chatgpt_api import generate_outline
from src.script_creator import generate_script
from src.tts_engine import text_to_speech
PROMPT_PATH = 'prompts/sample_prompt.txt'
OUTLINE_PATH = 'outputs/outlines/outline.txt'
SCRIPT_PATH = 'outputs/scripts/script.txt'
AUDIO_PATH = 'outputs/audio/podcast.mp3'
def main():
# Step 1: Read prompt
with open(PROMPT_PATH, 'r', encoding='utf-8') as f:
prompt = f.read()
# Step 2: Generate outline
outline = generate_outline(prompt)
os.makedirs(os.path.dirname(OUTLINE_PATH), exist_ok=True)
with open(OUTLINE_PATH, 'w', encoding='utf-8') as f:
f.write(outline)
# Step 3: Generate script
script = generate_script(outline)
os.makedirs(os.path.dirname(SCRIPT_PATH), exist_ok=True)
with open(SCRIPT_PATH, 'w', encoding='utf-8') as f:
f.write(script)
# Step 4: Generate audio
os.makedirs(os.path.dirname(AUDIO_PATH), exist_ok=True)
text_to_speech(script, AUDIO_PATH)
print(f'Podcast audio saved to {AUDIO_PATH}')
if __name__ == '__main__':
main()

15
src/script_creator.py Normal file
View File

@ -0,0 +1,15 @@
import openai
import os
def generate_script(outline: str) -> str:
openai.api_key = os.getenv('OPENAI_API_KEY')
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant that writes podcast scripts based on outlines."},
{"role": "user", "content": f"Write a detailed podcast script based on this outline: {outline}"}
],
max_tokens=1500
)
script = response.choices[0].message['content'].strip()
return script

5
src/tts_engine.py Normal file
View File

@ -0,0 +1,5 @@
from gtts import gTTS
def text_to_speech(text: str, output_path: str):
tts = gTTS(text)
tts.save(output_path)

1
src/utils.py Normal file
View File

@ -0,0 +1 @@
# Utility functions can be added here as needed