Introduction
The okcourse
Python library uses AI to generate audiobook-style courses in MP3 format with lectures on any topic.
Given a course topic of your choosing, the okcourse
library handles all the prompting and API interaction required to:
- Generate a course outline and lecture text with an LLM
- Create cover image for the course by using an image model
- Produce an audio file from the lecture text using a text-to-speech (TTS) model
Here's that workflow in code:
# Generate a course with a few custom settings
course = Course(title="From AGI to ASI: Paperclips, Gray Goo, and You") # (1)!
course.settings.num_lectures = 8 # (2)!
course.settings.tts_voice = "nova" # (3)!
course.settings.output_directory = Path("~/my_ok_courses") # (4)!
generator = OpenAIAsyncGenerator(course) # (5)!
course = await generator.generate_outline(course) # (6)!
course = await generator.generate_lectures(course) # (7)!
course = await generator.generate_image(course) # (8)!
course = await generator.generate_audio(course) # (9)!
print(
course.generation_info.model_dump_json(indent=2) # (10)!
)
- Generate a
Course
on any topic that doesn't run afoul of the AI service provider's content policy. - Lectures form the core content of a course. More lectures means longer courses.
- If the AI service provider supports it, you can specify which voice to use for the lecture audio.
- This is where the course audio file (MP3), its cover image (PNG), and log file(s) are saved. All are optional.
- Coures generators use an AI service provider's API to generate course content. OpenAI is the first supported provider.
- The course outline defines the structure of the course and includes the titles and subtopics of its lectures.
- Based on the course outline, this method populates the text of each lecture in the course.
- To have AI generate album art for the audio file, call
generate_image()
before you generate the audio file (next line). - This is the final step in the course generation process. It creates an MP3 file of the course's lectures read aloud by an AI-generated voice.
- The
Course
and many of its attributes are Pydantic models, making them easier to serialize, deserialize, and work with in general.
Course audio in MP3
Feed nearly any catchy title to okcourse
and you can fire up the course audio in your favorite media player in minutes. (1)
Curious about propulsion systems for interstellar space travel?
- Durations vary, but
okcourse
can generate a 1.5-hour audio course with 20 lectures in about 2.5 minutes.
OK for entertainment
The courses generated by the AI models and assembled by this library aren't exactly The Great Courses. They're fine for familiarizing yourself with a topic or for pure entertainment, but as with any AI-generated content, you should question and verify rather than assume unbiased accuracy.
Thanks
Inspirations for okcourse
were The Great Courses and cool projects like podgenai and tts-joinery.