How to use OpenAI and the llm command line tool to transcribe and summarize course lectures
Table of Contents
- 1. Introduction
- 2. Software resources
- 3. Preprocessing audio files
- 4. Analyzing lecture transcripts
1. Introduction
As part of my pedagogical development, I wanted to transcribe all of my course lectures during one semester so that I could transcribe and evaluate them. I also hoped to be able to make summaries of the lectures for various purposes (as records, to distribute with the slides to colleagues, to make quizzes or activities).
This document describes how to use the command line tool “llm” for Linux. “llm” stands for Large Language Models, and it simplifies calling models like chatGPT from the Linux command line.
Specifically, this document describes how to use llm to call OpenAI’s chatGPT model, using their API, to transform transcripts of my course lectures into summaries. (I’m not sure which model it is, off the top of my head. Maybe chatGPT 3.5 turbo? I can’t recall. In any case, llm allows one to select a specific model.)
This supposes that the first step was to use OpenAI’s Whisper model to perform speech-to-text transcription on an mp3 audio file of the lecture. I wrote a bash shell script to automate calling Whisper via the OpenAI API.
2. Software resources
2.1. How to write bash commands for audio transcription using OpenAI’s API
2.2. llm command line tool
2.3. My bash script
2.4. Audacity audio editing software
3. Preprocessing audio files
3.1. Trimming audio to get rid of time outside of lecture
I usually start and end recording a few minutes before and after the lecture, and I don’t want to transcribe that.
I trimmed off the unwanted recording parts in audacity.
SHIFT-J selects from track start to the cursor-marked point, which can then be deleted or cut (C-c).
SHIFT-K selects from the cursor point to track end.
3.2. Convert from WAV to mp3
After trimming in audacity, audacity will export to mp3.
3.3. Split large mp3 file into 10 minute chunks
chatGPT will only accept files up to 25 MB, which for me ends up being a little over 10 minutes for mp3 audio. So, I just split the recording into several files 10 minutes long or less, using ffmpeg on the command line.
For example:
ffmpeg -i PSYC-410_2024-01-19.mp3 -f segment -segment_time 600 -c copy PSYC-410_2024-01-19_%02d.mp3
-segment_time option argument is in seconds
Notes that the files will be numbered beginning with “00”.
3.4. Transcribe audio using OpenAI’s Whisper model
This step requires using my bash shell script “transcription_request.sh”.
transcription_request.sh PSYC-410_2024-01-19_00.mp3
This returns a file with the same name but with “.txt” appended:
PSYC-410_2024-01-19_00.mp3.txt
In my experience, it takes just under 30 seconds for this to complete for a 10 minute mp3 file.
4. Analyzing lecture transcripts
I tried a few difference methods for summarizing the lecture transcripts. Here is a broad summary of how they worked out:
- Paragraphs summaries: Creates summaries that follow the structure and content of the lecture best
- Main points with evidence: Lists most of the main topics and gives some of the associated content
- Lecture notes: Lists topics fairly exhaustively, but skips much content
4.1. The system prompts for each of the three approaches
Just so that these are easy to compare and find together (they are repeated in the following sections as well):
- Paragraph summaries:
"Organize this transcript into paragraphs. Do not change any of the words, only insert line breaks and empty lines between paragraphs"
and then
"Summarize each one of these paragraphs separately with one sentence each"
- Main points with evidence:
"Summarize the main points in this college lecture transcription, and then, below each main point, make a bulleted list of the evidence described for each point."
- Lecture notes:
"Turn this college lecture transcript into a set of lecture notes, complete with section headings"
4.2. Organize into paragraphs and summarize each
4.2.1. Organize transcripts into paragraphs
For example:
cat PSYC-241_2024-01-18_end_00.mp3.txt | llm -s "Organize this transcript into paragraphs. Do not change any of the words, only insert line breaks and empty lines between paragraphs" > PSYC-241_2024-01-18_end_00_GPT_PARA.txt
This takes longer than any other usage of the llm command that I’ve tried, interestingly. At least one minute, maybe two or three.
4.2.1.1. System prompt
“Organize this transcript into paragraphs. Do not change any of the words, only insert line breaks and empty lines between paragraphs”
4.2.1.2. Filename suffix with extension
_GPT_PARA.txt
4.2.2. Summarize each paragraph with one line
For example:
cat PSYC-241_2024-01-18_end_00_GPT_PARA.txt | llm -s "Summarize each one of these paragraphs separately with one sentence each" > PSYC-241_2024-01-18_end_00_GPT_PARA_SUMMARY.txt
Often chatGPT will not produce a summary line for every paragraph. This can be helpful, because it appears that it skips paragraphs that don’t seem important to the gist of the lecture. But other times I have wanted all of the paragraphs to get a summary. Once I tried asking for an explicity number of paragraph summaries, and that worked:
cat PSYC-241_2024-01-18_02_GPT_PARA.txt | llm -s "Summarize each one of these eleven paragraphs separately with one sentence each" > PSYC-241_2024-01-18_02_GPT_PARA_SUMMARY.txt
4.2.2.1. System prompt
“Summarize each one of these paragraphs separately with one sentence each”
4.2.2.2. Filename suffix with extension
_GPT_PARA_SUMMARY.txt
4.3. Summarize main points with evidence for each
For example:
cat PSYC-241_2024-01-18_01.mp3.txt | llm -s "Summarize the main points in this college lecture transcription, and then, below each main point, make a bulleted list of the evidence described for each point." > PSYC-241_2024-01-18_01_GPT_POINTS.txt
This sometimes produces an outline (I.A.1. etc.), sometimes a set of lines with bullets under each line for the evidence.
4.3.1. System prompt
“Summarize the main points in this college lecture transcription, and then, below each main point, make a bulleted list of the evidence described for each point.”
4.3.2. Filename suffix with extension
_GPT_POINTS.txt
4.4. Make lecture notes with subject headings
For example:
cat PSYC-410_2024-01-19_02.mp3.txt | llm -s "Turn this college lecture transcript into a set of lecture notes, complete with section headings" > PSYC-410_2024-01-19_02_GPT_NOTES.txt
This produces a bulleted list, usually.
Sometimes it produces an outline.
4.4.1. System prompt
“Turn this college lecture transcript into a set of lecture notes, complete with section headings”
4.4.2. Filename suffix with extension
_GPT_NOTES.txt