I used to record conversations with a recorder app on my phone. Afterwards I uploaded the
file, downloaded it to my laptop and ran it through whisper. The step I kept getting wrong
was the first one. I forgot to press record, and usually in the conversations I later
wanted a transcript of most.

So I made my Mac record all the time. It keeps the last three hours in five-minute chunks
and overwrites anything older. Nothing becomes text until I ask for a stretch of it, like
the last two minutes, and then whisper transcribes that stretch on the laptop. It is a
60-line shell script, a 112-line Swift menu-bar app, ffmpeg and whisper.cpp, and the code
is at [github.com/snehankekre/ear](https://github.com/snehankekre/ear).

![A terminal. ear.sh on starts the recorder. say speaks "Can you pick me up from the airport on Friday at six forty? My flight is G A four zero eight." through the laptop speaker. ear.sh peek 1 prints "Can you pick me up from the airport on Friday at 6:40? My flight is GA408."](/posts/a-microphone-that-keeps-the-last-three-hours/ear-peek.gif)

The microphone is on the whole time, so the people around me know about it, and macOS
shows an orange dot in the menu bar while it records.

Tools that record everything already exist. [Screenpipe](https://github.com/screenpipe/screenpipe)
records the screen and audio around the clock and transcribes all of it into a local SQLite
database. Rewind did the same on the Mac until Meta bought its parent company, Limitless,
and [recording stopped on 19 December 2025](https://9to5mac.com/2025/12/05/rewind-limitless-meta-acquisition/).
Both keep a searchable transcript of everything. Ear keeps three hours of audio and no text
until I ask for a stretch, so a conversation nobody asked about is gone three hours later.
It has no index and no search either, so it can't tell me what we decided last Tuesday.

## The buffer

```sh
ffmpeg -nostdin -f avfoundation -i ":default" -ac 1 -ar 16000 \
  -c:a libopus -b:a 16k \
  -f segment -segment_time 300 -segment_wrap 36 -reset_timestamps 1 \
  -segment_format_options flush_packets=1:page_duration=200000 \
  "$DIR/chunk%02d.opus"
```

`-i ":default"` records from whatever macOS has set as the input device. The audio is
saved as 16 kHz mono Opus at 16 kbps. whisper.cpp only takes 16 kHz audio, so recording at
a higher rate would only use more disk.

The segment muxer starts a new file every 300 seconds, `chunk00.opus`, `chunk01.opus` and
so on, and `-segment_wrap 36` sends the counter back to 00 after 35. The 37th chunk
overwrites the first, and 36 chunks of five minutes make three hours. ffmpeg does the
deleting, so the script has no cleanup step.

`-segment_format_options` passes two options to the Ogg writer for each chunk.
`flush_packets=1` writes each packet to disk as it arrives, and `page_duration=200000` cuts
Ogg pages at 200 ms instead of the default second. Without them the chunk being recorded
stayed at 0 bytes for its first stretch, and that chunk holds the most recent audio. With
them a peek run straight after someone stops talking misses about the last half second.

The script starts ffmpeg with `nohup` and writes its PID to a file. `ear.sh off` kills it
and deletes every chunk.

## Transcribing

To get the last N minutes, the script picks the newest chunks, joins them, trims the
result and hands it to whisper.

```sh
ls -tr "$DIR"/chunk*.opus | tail -n $((min / 5 + 2)) \
  | sed "s|^|file '|; s|\$|'|" > "$tmp/list"
ffmpeg -f concat -safe 0 -i "$tmp/list" -ar 16000 -ac 1 "$tmp/all.wav"
ffmpeg -sseof -$((min * 60)) -i "$tmp/all.wav" "$tmp/cut.wav"
whisper-cli -m ggml-large-v3-turbo.bin --vad -vm ggml-silero-v5.1.2.bin \
  -l auto -otxt -of "$out-transcript" -f "$tmp/cut.wav"
```

`ls -tr` sorts the chunks by modification time. Once the counter wraps, `chunk00.opus` is
the newest file, and sorting by name would put it first. The script takes enough chunks to
cover N minutes plus one on each side, joins them with the concat demuxer, and `-sseof`
keeps the last N minutes of the joined file. whisper.cpp then runs the large-v3-turbo
model with the Silero voice-activity model, which skips silence. Without voice detection
whisper tends to invent text for long quiet stretches, and most of an always-on recording
is quiet.

`ear.sh 60 trip-planning` saves the audio and the transcript under a name. `ear.sh peek 2`
prints a transcript of the last two minutes and saves nothing. I use peek when someone has
just asked me something and I want their exact words.

The first long grab was a 25-minute phone call on speaker. It spanned six chunks, whisper
took 26 seconds, and I couldn't find the chunk boundaries anywhere in the transcript.

The transcript has no speaker labels, so with three people talking I find the line I want
by what it says. whisper also picks one language from the first 30 seconds of a clip, and
in a conversation that switches languages the second one can come out garbled.

## Menu-bar icon

The Swift app puts an ear in the menu bar. It is filled while recording, faded when off,
and turns into a waveform while whisper runs. Its menu shows the output of `ear.sh status`,
items to grab the last 5, 15, 30 or 60 minutes, on and off, and a link to the folder. The
code is an `NSStatusItem`, a 10-second timer that checks the PID with `kill(pid, 0)`, and
`Process` calls to the shell script.

![The ear icon in the macOS menu bar with its menu open. The first line reads "ear: on since Sat Dec 5 19:42:47 2026, 11 chunk(s) of 5 min buffered", followed by Grab last 5, 15, 30 and 60 min, Turn off (deletes buffer), Open meetings folder, and Quit icon (recording keeps running).](/posts/a-microphone-that-keeps-the-last-three-hours/menu.png)

It has to be an `.app` bundle with `NSMicrophoneUsageDescription` in its `Info.plist`,
built with `swiftc` and signed ad hoc. macOS gives microphone access to the app that
started the process. ffmpeg started from my terminal used the terminal's permission, and
ffmpeg started from the menu bar needed the app to have its own. To check it, I ran
`say "checking the ear app microphone"` next to the laptop, and that chunk peaked at
-6.1 dB.

## The orange dot

I wanted to replace the orange microphone indicator with my ear. Control Center draws it
and System Integrity Protection covers it, so the only way is to turn SIP off, and I
didn't. After a few seconds the indicator shrinks from an orange microphone to a small
orange dot next to the Control Center icon, and the dot stays as long as ffmpeg has the
microphone open.

## Cost

I measured on an M3 Max, first with the recorder running for 109 seconds.

| What | Measured |
|---|---|
| CPU | 6.07 s over 109 s, about 5.6% of one core (16 cores in the machine) |
| Memory | 29 MB resident |
| Disk | 165,153 bytes in 109 s, about 5.4 MB an hour, so the full buffer is around 16 MB |
| Transcribing 38 s | 1.45 s, 2.0 GB resident at peak |
| Transcribing 25 min | 26 s |

The disk rate is below the 7.2 MB an hour that 16 kbps works out to. libopus runs variable
bitrate by default, and my guess is that a quiet room costs less. The large-v3-turbo model
file is 1.6 GB and only loads when I ask for a transcript.

## Not tested yet

The recorder hasn't run for three hours yet, so I haven't seen the first overwrite. I
haven't tested sleep either. If ffmpeg keeps running through it, the script will join the
audio on both sides of the gap as if no time passed. I also don't know whether the
recorder survives quitting the terminal that started it. If it dies, the menu-bar ear
fades and I turn it back on.