Skip to content

Podcasts ​

This page explains how Scholar Lens turns study material into a two-host podcast episode: the outline, the checked script, the recording, the concept map and the optional video. It is for developers and reviewers. The code is in app/podcasts/ (backend) and src/features/podcasts/ (frontend). For how to use the feature, see the Podcasts guide.

The pipeline ​

Every step runs in the job worker as its own job, so a page can close and a failed step resumes where it stopped.

flowchart LR
  N[New episode] --> P[plan_podcast<br/>passages + outline]
  P --> D([draft<br/>the student reviews])
  D --> W[write_podcast<br/>per part: write, rewrite, check]
  W --> R[record_podcast<br/>voices, timings, MP3]
  R --> A[analyse_podcast<br/>concept map + quality]
  R -. on request .-> V[render_podcast_video<br/>video service]

Figure 1. From the material to a playable episode. The dashed step runs only when someone asks for a video.

StatusMeaning
planningGathering the material and writing the outline
draftThe outline waits for the student's review
writingWriting and checking the script, one part at a time
scriptedThe script is done but no voice is set up
queued, recordingWaiting for, or running, the recording
readyPlayable. The concept map follows a minute or two later.
failedThe error is kept on the episode. Writing and recording resume from the first unfinished part.

Plan ​

plan_podcast (app/podcasts/script.py) gathers the material into numbered passages (P1, P2 and so on):

  • A Library scope: the chunks of the picked sections or book pages, in reading order. A large scope is sampled evenly, but the scope's opening (about 2,000 characters of aims and overview) and the first passage of each section are always kept.
  • Chats: the questions and answers of the picked chats, with the passages their answers cited.
  • Uploads and pasted text: split into passages of about 1,200 characters. Uploads are stored with the episode, not in the Library.

When the scope is part of a larger work, the plan also records where it sits: the earlier sections of the same chapter (with short summaries) and the next section (app/ingestion/scope.py). The writer uses this for the recap at the start and the "next episode" line at the end.

The model then writes the outline: an episode title, the material's field (for example "software project management in computing"), and the parts. Each part has a title, a core idea, 2 to 4 key points, the passages it draws on, and its share of the length. There is one part for about every 3.5 minutes, and at most 10. The opening passages always join the first part. The episode waits as a draft until the student approves or edits the outline.

Write ​

write_podcast writes the script one part at a time, in three model calls per part:

  1. Write the dialogue against the key points, from the part's passages only. The prompt sets the roles of the format (explainer, debate or interview), the difficulty, and the rules of real talk: full turns, few questions, no lines that only confirm, one example built up over a few turns, and examples from the material's field. Each line carries its key point, the passage it rests on (source) and a mood.
  2. Rewrite the part so it sounds like talk, not questions and answers read out. A rewrite that loses more than a quarter of the words is ignored.
  3. Check every factual line against the passages. A line the passages contradict or do not support is replaced by the corrected line, or dropped. The verdict is stored on the line (check).

The first part opens with the first host alone: the topic from the material's aims and overview, then today's agenda (about 35 words naming the parts in order), then the welcome. The last part ends with final thoughts and thanks. Code also removes stock lines ("Great question"), talk about the material itself ("the text says"), symbols and Markdown from every line (spoken, about_subject).

A line's citation (page, chunk) comes from the stored passage, never from the model's text.

Record ​

record_podcast (app/podcasts/audio.py) voices the parts in order and keeps each part as a WAV file, so a failed recording resumes at the first missing part. The voice providers come from Settings › Podcast voices (app/podcasts/providers.py):

KindRequestLine times
geminiOne request per part with both hosts and a style per lineFound in the audio: silences near each expected break (align)
openaiOne request per line (/audio/speech)Exact: the lines are joined with pauses here
google-cloudOne request per line (text:synthesize)Exact
localThe stack's tts service (Kokoro on the CPU or Chatterbox on a GPU)Exact

Recording uses the first provider that is on, under its daily limit and not resting. A provider whose quota ran out rests until it resets, and the next one records the whole episode again, so the voices never change between parts. An episode marked Local voices only uses only the local service, so its script never leaves the machine.

The parts are then joined, levelled for loudness and encoded as MP3 with ffmpeg (from the imageio-ffmpeg wheel). Every line keeps its start and end on the episode's timeline, which the player, the captions and the video all follow.

Analyse ​

analyse_podcast (app/podcasts/analysis.py) runs after the recording is queued, at background priority. A failure leaves the episode playable.

  • Concept map: the model picks the episode's key concepts part by part and names the lines that discuss each one. A second call links them, with the same prompt as the Study concept map. Each concept carries its line ids, so the player knows when it is discussed.
  • Quality: metrics counted in code (questions, short reactions, cut-ins, stock lines, question and answer runs, corrected lines, length against the plan) and a rubric judge that scores four points from 1 to 5.

While the job is queued or running, the episode's analysing flag is true and the page keeps asking for the episode until the map is there.

Figures from the source ​

episode_figures (app/podcasts/figures.py) picks the figures and tables the player may show. Nothing here calls a model. A figure is shown only when all of these hold:

  1. a passage of the episode names it ("Figure 4.6", "Fig. 4.6", "Table 4.1");
  2. the figure of that number was extracted from the same Library item at indexing (the figures table, see Ingestion);
  3. a line was written from that passage (its check.source);
  4. no other caption claims the same area of the page.

The player shows a figure while its lines play. Lines less than 20 seconds apart are joined into one window, a window lasts at least 8 seconds, and at most two figures show at once.

Video ​

A video is made only on request (POST /api/podcasts/{id}/video). The render_podcast_video job runs only in the stack's optional video service (python -m app.worker --only video); the main worker skips it. The service image adds Playwright and a headless Chromium to the backend's.

  1. The worker opens the UI's /render/podcast page in Chromium at 1920 × 1080 and hands it the episode, the same data the player reads.
  2. The page calls no API and needs no sign-in. The worker serves the figure images from disk and refuses every other API call.
  3. Playwright's fake clock drives the page: for each frame the worker sets the time, advances the clock by one frame (15 fps by default, VIDEO_FPS), and takes a screenshot. The map's moves run on that clock, so each frame shows the right moment however long it takes to draw.
  4. ffmpeg joins the frames (H.264) with the episode's MP3 (AAC) and adds the captions as a mov_text subtitle track in English. The captions are not drawn into the picture.

The file is video.mp4 beside the episode's MP3. A video older than the MP3 counts as missing, so recording again means making the video again. The owner gets a notice when it is ready or failed.

Data and files ​

TableHolds
podcastsThe source, the shape (length, difficulty, format, instructions, hosts), the status, the material (passages, context, field), the concept map and the quality report
podcast_segmentsThe parts: title, core idea, key points, passage ids, length, and their WAV and times once recorded
podcast_turnsThe lines: speaker, text, key point, mood, page, chunk, check verdict, start and end
voice_providersThe voice providers in order, with sealed keys, limits and resting state

An episode's audio and video live under data/uploads/podcasts/<episode id>/, and deleting the episode deletes that folder. Uploaded files live under data/uploads/podcast-uploads/<user id>/<upload id>/, with the file's text and contents.