Hello, tech enthusiasts! ๐
Your colleague sends you a five-minute voice note. You are in a meeting and cannot listen. Later, you need to find what they said about the invoice deadline, and you have to play it all again.
What if every voice note became text? You could read it in 20 seconds, search it, and copy it into a report.
Today we will do that with Whisper, a free speech-to-text model. The best part: it runs on your own computer. Your audio never leaves your machine. For business calls and private messages, that is a big win.
What you need
- Python 3.9 or newer (https://www.python.org)
- ffmpeg, a free tool for audio files (https://ffmpeg.org)
- An audio file, for example
voice_note.oggormeeting.mp3 - A normal laptop is enough. A graphics card makes it faster, but it is not required.
Step 1: Install ffmpeg
ffmpeg is like a universal translator for audio and video formats. Install it:
# Ubuntu / Debian
sudo apt install ffmpeg
# Mac with Homebrew
brew install ffmpeg
# Windows with winget
winget install ffmpeg
Check that it works with ffmpeg -version.
Step 2: Install faster-whisper
There are two popular versions of Whisper for Python. The original is openai-whisper. We will use faster-whisper. It gives the same quality, but it runs faster and uses less memory on a normal computer.
It is good practice to use a virtual environment, a private box for this project’s libraries:
python -m venv whisper-env
# Windows: whisper-env\Scripts\activate
source whisper-env/bin/activate
pip install faster-whisper
Step 3: Transcribe your first file
Create a file named transcribe.py:
from faster_whisper import WhisperModel
# "small" is a good balance of speed and accuracy on a laptop
model = WhisperModel("small", device="cpu", compute_type="int8")
segments, info = model.transcribe("voice_note.ogg")
print(f"Detected language: {info.language}")
for segment in segments:
print(segment.text.strip())
Run it:
python transcribe.py
The first time, it downloads the model, so you need internet once. After that, everything works offline.
A model is the “brain” that knows how to turn sound into words. compute_type="int8" makes the model lighter so it runs well on a normal processor.
Step 4: Choose the right model size
Whisper comes in several sizes. Bigger is more accurate, but slower:
tinyandbase: very fast, fine for clear English speech.small: a good default for most voice notes.medium: better for noisy audio and for languages like Arabic.large-v3: the most accurate, but slow without a graphics card.
Start with small. If the text has too many mistakes, try medium.
Step 5: Set the language
Whisper guesses the language from the first 30 seconds. Usually it is right. But for short notes or mixed languages, it can guess wrong. You can tell it directly with a language code:
segments, info = model.transcribe("voice_note.ogg", language="ar") # Arabic
# English is "en", French is "fr", and so on
Step 6: Save the text to a file
Printing is nice, but a text file is more useful. This version saves each line with its time, so you can jump to the right place in the audio:
from pathlib import Path
from faster_whisper import WhisperModel
model = WhisperModel("small", device="cpu", compute_type="int8")
def transcribe_to_file(audio_path, language=None):
segments, info = model.transcribe(audio_path, language=language)
out_path = Path(audio_path).with_suffix(".txt")
with open(out_path, "w", encoding="utf-8") as f:
for s in segments:
# Time as minutes:seconds, then the text
start = f"{int(s.start // 60):02d}:{int(s.start % 60):02d}"
f.write(f"[{start}] {s.text.strip()}\n")
print(f"Saved {out_path}")
# Transcribe every audio file in a "VoiceNotes" folder
for audio in Path("VoiceNotes").glob("*.*"):
if audio.suffix.lower() in {".ogg", ".mp3", ".m4a", ".wav", ".opus"}:
transcribe_to_file(str(audio))
Now VoiceNotes/voice_note.ogg gets a partner file, VoiceNotes/voice_note.txt.
Prefer the original version? The openai-whisper package has a simple command line tool that does the same thing:
pip install openai-whisper
whisper voice_note.ogg --model small --language ar --output_format txt
Common problems
- Very slow โ Use a smaller model, or keep
compute_type="int8". Long recordings simply take time on a laptop. - Text in the wrong language, or translated โ Set
language=yourself. - Errors about CUDA or the GPU โ Keep
device="cpu". The GPU needs extra NVIDIA libraries. - “No such file or directory: ffmpeg” (openai-whisper) โ ffmpeg is not installed or not on your PATH. Repeat Step 1, then open a new terminal.
Wrap-up
With about 20 lines of Python, you have a private, free transcription tool. No upload, no monthly fee, and no limit on minutes.
Next idea: combine this with a search script. Transcribe all your voice notes once, then search the text files for a word like “deadline” to find the right message in seconds. ๐๏ธ