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
whisper-1turns the sound into text: the faster of the two transcription models. The other one,whisper-1-hd, is slower; on some recordings it hears better, on others worse.- Gemma 4 26B (
gemma-4-26b), the default model, turns the text into notes: fast, and good at following a fixed layout.
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.
- “Phishing: An attack where passwords are guessed or stolen using a fake login page.” The teacher said: “Passwords can also be guessed, or stolen with a fake login page: that is phishing.” The transcript lost the comma, and guessing became a kind of phishing. It happened in every one of our runs.
- “Pasty”. The teacher said “passkey” twice.
whisper-1wrote “pasty” the first time and “passkey” the second, and the notes took the right one.whisper-1-hdwrote “pasty” both times, and the notes had “Pasty (hardware security key)” among the key points. “Pasty” is a real word, so it got no (?).
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
- The notes are only as good as the transcript: a noisy room, a teacher far from the phone, two people talking at once all make it worse. Sit near the front, and put the phone on the desk, not in your bag.
- “Use only what the lesson says” is a request, not a guarantee. If a note has something the teacher did not say, the model added it: cross it out.
- The review questions come from the lesson, not from the exam. They tell you what you understood, not what you will be asked.
- The notes use credits, like any chat request: your balance and your usage are in your dashboard, at my.ai.itsincom.org.
Exercise
- Record ten minutes of a real lesson, with the teacher's OK, and make the notes. What did the model leave out that you would have written?
- For a lesson in Italian, write
language="it"and add “Write the notes in Italian.” at the end ofNOTES. When we tried it the notes came in Italian, under the English headings thatNOTESasks for: translate the headings too. - Add a fifth heading to
NOTES, after the answers:## Glossaryand, on the next line, “Every technical term of the lesson, with a one-line definition.” Change “four headings” to “five headings”. Does the glossary keep the (?)? - Turn the review questions into cards for Anki: Flashcards from your notes.
