Skip to content
Fondazione ITS INCOM

Examples · General

A recorded lesson turned into notes

Transcribe the recording of a lesson, then let a model write a summary, the key points and five review questions with their answers. Where the notes can go wrong, and how to handle an hour-long lesson.

Intermediate · 45 min

What you need

A key and the openai library, as in Your first API call in Python, and the recording of a lesson: a voice memo from your phone is fine.

Record a lesson only if the teacher agrees, and keep the recording for yourself: your classmates' voices are in it too.

No recording at hand? Save a page of your notes as lesson.txt and let a voice of the school read it. Save this as make_lesson.py:

import os

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ai.itsincom.org/v1",
    api_key=os.environ["API_KEY"],
)

with open("lesson.txt", encoding="utf-8") as f:
    text = f.read()

speech = client.audio.speech.create(model="tts-1", voice="amy", input=text, response_format="mp3")
speech.write_to_file("lesson.mp3")
print("lesson.mp3 is ready")

amy reads English; for Italian, paola or riccardo. Up to 5,000 characters, about five minutes of speech: more in Text to speech in Python.

The models

The program

Save it as notes.py:

import os
import sys

from openai import OpenAI

client = OpenAI(
    base_url="https://api.ai.itsincom.org/v1",
    api_key=os.environ["API_KEY"],
)

# 1. From sound to text. sys.argv[1:] is every file named after notes.py:
#    one recording, or the parts of a long lesson in order.
transcript = ""
for path in sys.argv[1:]:
    with open(path, "rb") as f:
        part = client.audio.transcriptions.create(model="whisper-1", file=f, language="en")
    transcript += part.text + "\n"
    print(f"{path}: {len(part.text.split())} words")

# Keep the transcript: when a note looks odd, check what was really said.
with open("transcript.txt", "w", encoding="utf-8") as f:
    f.write(transcript)

# 2. From text to notes. The system message says what to write and in which shape.
NOTES = """You turn the transcript of a lesson into study notes in Markdown, under these four headings:
## Summary
One paragraph, five sentences at most.
## Key points
5 to 8 bullet points, with the definitions and the examples given in the lesson.
## Review questions
Five numbered questions that check understanding, not memory.
## Answers
A short answer to each question, with the same numbers.

Use only what the lesson says: do not add facts from outside it.
A transcript can mishear technical terms: if a word makes no sense, keep it and write (?) after it."""

answer = client.chat.completions.create(
    model="gemma-4-26b",
    temperature=0.3,  # low: notes should stick to the lesson, not be creative
    messages=[
        {"role": "system", "content": NOTES},
        {"role": "user", "content": transcript},
    ],
)

notes = answer.choices[0].message.content
with open("notes.md", "w", encoding="utf-8") as f:
    f.write(notes)
print(notes)

Run it on your recording:

python3 notes.py lesson.mp3

What you should see

Our test lesson was two minutes on two-factor authentication, read by amy. About ten seconds later (shortened here):

lesson.mp3: 308 words
## Summary
This lesson explains how authentication verifies a user's identity through three different factors: something you know, something you have, and something you are. It highlights the dangers of relying solely on passwords, such as credential stuffing and phishing. …

## Key points
* **Credential stuffing**: An attack where stolen passwords from a website breach are tried on many other websites, made possible because people reuse passwords.
* **Phishing**: An attack where passwords are guessed or stolen using a fake login page.
* **Passkey (or hardware security key)**: The strongest form of authentication that is phishing-resistant because the key checks the website's address and refuses to answer a fake website.
…

## Review questions
1. Why does using two different passwords fail to meet the requirement for two-factor authentication?
…

## Answers
1. Because both passwords fall under the same category of "something you know," meaning one breach could reveal both.
…

The notes are also in notes.md, the transcript in transcript.txt. Markdown opens well in VS Code, Obsidian or Notion. Every run writes the notes a little differently.

Where the notes go wrong

Read the notes against the lesson, and you find mistakes that nobody marked.

The (?) is for words that make no sense, and it works only sometimes. We also tried a lesson in Italian on backups, read by paola. Where she said «copie», copies, whisper-1 wrote «coppie», pairs, and «cloud» became «crowd»; whisper-1-hd turned «ransomware» into «ram su muore». In the notes, Gemma put the right words back most of the time, from the context, and once it wrote «crowd (?)». Good for your notes, but it also means that they can differ from the transcript without telling you.

A wrong word that sounds right goes straight into your notes. Read them once against your memory of the lesson, or the slides, before you study from them. When a term keeps coming out wrong, transcribe again with the other model: neither is right every time.

An hour-long lesson

An hour of recording is often over the 25 MB a request takes, and a request that takes more than five minutes to transcribe is stopped. Cut the lesson into parts of five minutes, small and mono, with ffmpeg, then give the program all the parts:

ffmpeg -i lesson.m4a -vn -ac 1 -ar 16000 -b:a 48k -f segment -segment_time 300 part-%02d.mp3
python3 notes.py part-*.mp3

The parts are called part-00.mp3, part-01.mp3…, so part-*.mp3 gives them in the right order. A part of five minutes is about 1.8 MB. The notes are made from the whole transcript at once: we tried a transcript of 9,000 words, about an hour of speech, and it fit in one request to Gemma.

Read the transcript where the parts end. When we cut an 11-minute recording into parts of five minutes, whisper-1 left out a whole sentence ten seconds before the end of the second part, in every run: “breached, the stolen passwords are tried on many other websites”. whisper-1-hd kept it.

Good to know

Exercise

All examples