53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
import asyncio
|
|
import edge_tts
|
|
import os
|
|
|
|
# Define the voices for each character
|
|
voices = {
|
|
"Sonia": "en-GB-RyanNeural", # Using British male voice as suggested in the script
|
|
"Author": "en-US-GuyNeural", # Using American tech bro voice as suggested for Graham
|
|
}
|
|
|
|
async def generate_audio(text, voice, output_file):
|
|
"""Generate audio using Edge TTS"""
|
|
communicate = edge_tts.Communicate(text, voice)
|
|
await communicate.save(output_file)
|
|
print(f"Generated: {output_file}")
|
|
|
|
async def main():
|
|
# Create output directory if it doesn't exist
|
|
os.makedirs("output/podcast", exist_ok=True)
|
|
|
|
# Read the podcast script
|
|
with open('scripts/podcast_script.txt', 'r', encoding='utf-8') as f:
|
|
content = f.read()
|
|
|
|
# Split the content by double newlines to separate character dialogues
|
|
parts = content.split('\n\n')
|
|
|
|
tasks = []
|
|
for i, part in enumerate(parts):
|
|
if part.strip():
|
|
# Extract character name and dialogue
|
|
if ':' in part:
|
|
char_name = part.split(':', 1)[0].strip() # Split only on the first colon
|
|
dialogue = part.split(':', 1)[1].strip()
|
|
|
|
# Determine the voice for this character
|
|
if char_name in voices:
|
|
voice = voices[char_name]
|
|
output_file = f"output/podcast/{char_name.lower()}_{i}.mp3"
|
|
|
|
# Create the async task
|
|
task = generate_audio(dialogue, voice, output_file)
|
|
tasks.append(task)
|
|
|
|
# Run all tasks concurrently
|
|
if tasks:
|
|
await asyncio.gather(*tasks)
|
|
|
|
print("All audio files generated!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |