Skip to content

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)!
    )

  1. Generate a Course on any topic that doesn't run afoul of the AI service provider's content policy.
  2. Lectures form the core content of a course. More lectures means longer courses.
  3. If the AI service provider supports it, you can specify which voice to use for the lecture audio.
  4. This is where the course audio file (MP3), its cover image (PNG), and log file(s) are saved. All are optional.
  5. Coures generators use an AI service provider's API to generate course content. OpenAI is the first supported provider.
  6. The course outline defines the structure of the course and includes the titles and subtopics of its lectures.
  7. Based on the course outline, this method populates the text of each lecture in the course.
  8. To have AI generate album art for the audio file, call generate_image() before you generate the audio file (next line).
  9. 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.
  10. 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?

  1. Durations vary, but okcourse can generate a 1.5-hour audio course with 20 lectures in about 2.5 minutes.

Screenshot of Plex web player displaying an audio lecture titled 'Interstellar Space Travel: Propulsion Systems from Factual to Fantastical' by Fable @ OpenAI, showing a retro-styled cover illustration of a futuristic spacecraft and technical diagrams with a playback position of 32:18 out of 49:29.

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.