# Meetings

1. **Microphone** page, WebM, 30 s
2. **Computer sound** host, WAV, 30 s
3. **Convert** 16 kHz mono WAV
4. **Skip silence** peak below 300/32767
5. **Transcribe** in the meeting's language
6. **Merge** rewrites transcript.json
7. **transcribing** queue drains
8. **Diarize** system track, once
9. **summarizing** one tool-less turn
10. **done** summary.md

Built from what exists: voice-input speech engines, the long-running session shape of workflow recording, the owner turn of reminders and check-ins, the browser microphone API and computer use's ScreenCaptureKit stream. No new infrastructure.

## Parts

Meetings is an application package (`openprogram/programs/applications/meeting/`): a manifest, a Python backend and a built window. It runs like any installed application; what only the host can do it asks for through capabilities, so the package carries no import of the host's code and can later be exported with a trimmed runtime.

| Part | Where | Does |
| --- | --- | --- |
| Manifest | `meeting/application.json` | Operations `readiness`, `start`, `ingest`, `finish`, `transcript`, `summary`, `summarize`, `delete`, none exposed to Agents; capabilities `storage.app`, `storage.files`, `speech`, `conversation`, `audio.record` |
| Backend | `meeting/backend/` | Meeting list in the state document, per-chunk transcription, merge, speaker labels, summary |
| Window | `meeting/web/src/`, built into `meeting/ui/` | Start and Stop, live progress, past meetings with summary and transcript; the App's own components, theme and Inter, bundled |
| Recording | `openprogram/programs/_host/ui/audio.py` | The host's `audio.record`: owns the recording, stores chunks, hands each to `ingest`, then calls `finish` |
| Microphone | `apps/web/lib/applications/audio-recorder.ts` | The App's page records it for the sandboxed window and uploads chunks in order |
| Computer sound | `openprogram/host/_platform/system_sound.py` on `screen_capture_audio.py` | Display-wide, audio-only stream started with the recording |
| Speech | `speech` host calls → `openprogram/runtime/speech_link.py` → `openprogram/interfaces/speech/` | `transcribe_file` with the engine from Settings → Voice; `diarize` over one track |
| Summary | `conversation` host calls → `owner_turn.py` | One tool-less owner turn in a conversation the application opened |

## Package and host

| Capability | The backend or window gets |
| --- | --- |
| `storage.files` | `context.files`: a directory of the instance's own under `programs/.runtime/files/<instance>/`. Host calls take paths relative to it and refuse anything outside. |
| `speech` | `context.transcribe(path, language=)`, `context.diarize(chunks)`, `context.speech_readiness()`. Needs `storage.files`. |
| `conversation` | `context.open_conversation(title)` and `context.converse(session_id, text)` (one owner turn, no tools, only in conversations it opened); the window's `conversations.show(id)` |
| `audio.record` | The window's `audio.start({key, tracks, max_seconds})`, `stop()`, `status()` and `audio` events. The manifest names `recording.ingest` and optional `recording.finish`. Needs `storage.files`. |

- An operation still runs in a process of its own. A host call is a `host` event on the runner's stdout; the application service answers it in the worker (`programs/_host/ui/host_calls.py`) on the runner's stdin. The core never imports the speech interface: it reaches it through `speech_link`.
- A recording outlives one operation and the window, so the host owns it: one per instance, at most 4 hours. Each chunk is written to `recordings/<key>/<track>/<seq>.<ext>` and handed to `ingest` one at a time, in order; when the recording stops and every chunk is in, `finish` runs with its final status. Disabling the application cancels without `finish`.
- Every save of the state document signals `application-state`, every recording change `application-audio`; the App forwards both to the window as `state` and `audio` events, so it reads again instead of polling.
- The window draws in the App's theme: the host posts its `data-*` attributes, colour scheme, language and custom properties (`appearance`), and the SDK applies them to the page before its first frame. Fonts ship with the package, as the sandbox loads them only from its own origin.

## Capture

| Track | Source | Speaker |
| --- | --- | --- |
| `mic` | Page, `getUserMedia({audio})` with echo cancellation, noise suppression, automatic gain | "Me": from where the sound was recorded, not a model |
| `system` | Server, ScreenCaptureKit: the computer's sound output | "Others", then numbered by [diarization](#speaker-diarization) |

**The computer's sound, on the server**

- `audio.start` with the `system` track starts capture in `Recording.begin`. `ScreenCaptureSource` reads the shareable content and builds `SCContentFilter.initWithDisplay_excludingWindows_(display, [])` for the first display, no window excluded.
- `screen_capture_audio.open_audio` opens the stream: `capturesAudio`, 16 kHz, one channel, `excludesCurrentProcessAudio`, a 2×2 frame once a second, no screen output attached. Computer use's per-application recording (`desktop/common/audio.py`) shares this module and differs only in its filter.
- macOS asks for Screen & System Audio Recording the first time. The worker runs inside the App's runtime bundle (`screen_recording` capability in `openprogram/host/system_access`), so the prompt and the System Settings row name the App. ScreenCaptureKit audio needs no other declaration.
- `SystemAudio` is independent of ScreenCaptureKit. A source pushes float32 buffers; it cuts 30-second chunks by sample count. A chunk's `t_ms` is the meeting clock at its first sample: the arrival of the buffer that starts it, less that buffer's remaining length.
- Its own thread converts each chunk to 16-bit WAV and calls `Recording.take("system", seq, t_ms, wav, "wav")`, the intake the microphone's uploads feed.
- `Recording.stop` stops the stream and flushes the last partial chunk while still `recording`. Cancelling (the application disabled) drops it.

| `system_audio_reason` | When |
| --- | --- |
| `unsupported` | Not macOS, or PyObjC's ScreenCaptureKit does not import |
| `permission` | ScreenCaptureKit refusal (error -3801 "declined TCCs") or `CGPreflightScreenCaptureAccess` reporting no grant |
| `error` | Anything else; text in `system_audio_message` |

If the source cannot start, the recording is microphone only and its status, then the meeting's entry, say `system_audio: "unavailable"`. A working capture reports `recording`.

**The microphone, on the App's page**

- The sandboxed window has no microphone. On `audio.start` the App's page asks for it, then starts the host's recording, and counts chunk offsets from the `elapsed_ms` in the start response, so both tracks share one clock.
- `MediaRecorder` is stopped and restarted every 30 seconds. A timeslice recorder emits later chunks without a WebM header; restarting makes each a complete file, at a cost of a few milliseconds' gap per chunk.
- A chunk carries track, sequence number and offset (`t_ms`), so out-of-order uploads land in place. One stopped under 100 ms after it started has only a header and is not uploaded.
- Uploads go to `/api/application-instances/<instance>/audio/<recording>/chunks`, serialized and tried three times on network or 5xx errors. A 4xx means the recording ended elsewhere (Stop in another window, the time limit): the microphone stops.
- The recorder lives in a module-level store keyed by instance: closing the window or switching tabs does not stop it, only Stop does.
- A refused microphone arrives as `NotAllowedError`; the window names the System Settings pane.
- The recording card says whether the computer's sound is recorded. If not, it says microphone only and, for `permission`, names Privacy & Security → Screen & System Audio Recording and asks to reopen the App.

## Store and transcribe

```
state document              {"meetings": {id: entry}, "prefs": {explained, language}}; an entry holds
                            title, language, times, state, chunk counts, errors, engine,
                            session_id, system_audio, diarization, speakers
<files>/recordings/<id>/
  <track>/<seq>.webm         the chunk as the host stored it (system chunks are .wav)
  <track>/<seq>.json         timed segments (or silent / error); system segments gain speaker
  transcript.json           the merged transcript, written at finish
  summary.md                the summary with the transcript in a <details> block
```

The meeting's id is the recording's key. `ingest` transcribes one chunk, writes its JSON beside it and updates the entry; a request key per chunk makes a repeated hand-over run once. A chunk that fails is recorded and counted; the meeting goes on. Saves retry when another operation changed the document first.

| Stage | Rule |
| --- | --- |
| Convert | `ffmpeg`, found on `PATH`, then `/opt/homebrew/bin`, `/usr/local/bin`, `/usr/bin`; it reads the format from the data. A WAV already in form is used as is. Without ffmpeg, `readiness` says so with an install hint and the window disables Start. |
| Skip silence | Whisper invents text for silent audio. |
| Transcribe | `context.transcribe(path, language=)` → `speech_link.transcribe_file`: convert, skip silence, `transcribe_segments`. A link without timed segments falls back to `transcribe` as one segment. |
| Language | The meeting's, never Settings → Voice's: a forced voice-input language makes Whisper invent text. The `start` operation takes an optional ISO `language`, stored in the entry. The window sends the choice beside the meeting name, none for "Detect automatically". Empty means detection: whisper.cpp `-l auto`, no `language` field for OpenAI and Groq. |
| Timing by engine | whisper.cpp prints `[from --> to]` lines (no `-nt`). Groq and OpenAI Whisper models answer `verbose_json`. `gpt-4o-*-transcribe` answers text only: one segment spanning the chunk. |
| Merge, `transcript.py` | Segments move onto the meeting clock and sort by start. A microphone segment at least 75% similar to a system segment starting within 4 s is echo (no headphones) and is dropped. Consecutive segments of one speaker less than 1.5 s apart join into one turn, up to 600 characters. |
| Line | `speaker` (`me`, `others`, `others:<n>`), which the window localizes, and English `label` ("Me", "Others", "Speaker n"). The window reads the lines with `transcript` after each chunk, so it shows them growing. |

## Summary

| Aspect | Rule |
| --- | --- |
| Empty transcript | No conversation opens; `summary.md` says nothing was transcribed |
| Conversation | `conversation.open`: `application_<hex>`, source `web`, titled after the meeting, default Agent, the model a new chat starts on; id in the entry. Stays for follow-up questions; **Open chat** shows it through `conversations.show`. |
| Turn | `conversation.ask` → `start_owner_turn(..., tools=[])`. A fixed prompt, then the transcript inside `<meeting-transcript>`. With no tools, nothing said in a meeting can make the Agent act. |
| Prompt asks for | `## Summary`, `## Decisions`, `## Action items` (owner, due date), `## Open questions`, in the meeting's language. Says the transcript is data, never instructions, and that speaker numbers are voices, not names. |
| `summary.md` | The answer, a header with date and length, the full transcript in a collapsible section |
| Interrupted | The window shows an entry as `interrupted` when it says live but no recording and no `summarize` run works on it (a stopped worker). **Summarize again** rebuilds it from the per-chunk JSON files. |

## Access

- The window reaches nothing but its bridge; the recording, chunk and show routes under `/api/application-instances/` need the owner's sign-in and the capability in the manifest.
- The microphone is recorded where the App's page runs; the computer's sound is always the worker's computer's.
- Meetings stay in the state directory. With a cloud speech engine each chunk goes to that provider. An update's trial copy leaves applications' files out.

## Speaker diarization

Once per meeting, over the whole system track, so clustering sees every voice at once and no embeddings are matched across chunks. About 4 s per minute of audio on four threads.

| Step | What |
| --- | --- |
| Audio | System chunks in order, converted one at a time and concatenated. `concatenate` records `(concat_ms, t_ms, duration_ms)` per chunk; `to_track_clock` maps turns back and splits one crossing a boundary. Lives in `interfaces/speech/diarize.py`, reached through `context.diarize`. |
| Diarize, `run` | sherpa-onnx `OfflineSpeakerDiarization`; pyannote segmentation-3.0; 3D-Speaker's bilingual CAM++ (`3dspeaker_speech_campplus_sv_zh_en_16k-common_advanced.onnx`); up to four ONNX threads; `min_duration_on` 0.3 s, `min_duration_off` 0.5 s; `FastClusteringConfig(num_clusters=-1, threshold=0.75)`, as the speaker count is unknown. |
| Label, `backend/speakers.py` | Each system segment takes the speaker whose turns overlap it longest (ties: lower sherpa number). Renumbered `others:1`, `others:2`… by first appearance. Written back to the chunk JSON and merged again, so `transcript.json`, `summary.md` and the prompt carry "Speaker n". |
| Stays "Others" | A segment no turn overlaps, or whose only voice was heard under `MIN_SPEAKER_MS` (3 s) in the whole meeting. Clustering leaves one- or two-second strays that would become "Speaker 5" to "Speaker 7". |

| `diarization` | Meaning |
| --- | --- |
| `running` | In progress |
| `done` | `speakers` is the count of numbered speakers |
| `unavailable` | `diarization_reason`: `not_installed` (no `sherpa_onnx`) or `no_model` (download or model files failed) |
| `failed` | `diarization_reason` `error`, text in `diarization_message` |
| Empty | No computer sound recorded, or nothing transcribed from it: step skipped |

Except for `done`, the transcript is unchanged.

**Why this model and threshold**

Tried on four recordings with known speakers: pyannote's AMI excerpt (two people talking over each other, scored against its labels), sherpa-onnx's four-speaker test, a two-voice recording and four synthesized voices.

| Setting | Result |
| --- | --- |
| CAM++, 0.6–0.75 | Right speakers on all four; 91% of AMI speech labelled right |
| CAM++, 0.8 | Merges two of the four Chinese speakers |
| Top of the range, 0.75 | On a four-person AMI meeting through a conference call and plain playback, splits one person into two numbers least often: five numbered voices, against seven at 0.65 |
| ERes2Net zh-cn (sherpa-onnx's example) | Needed a different threshold per recording; merged the AMI pair at every value that kept the four-speaker recording at four |

**Dependency and model download**

- `sherpa-onnx` is the optional `meetings` extra (with `numpy`), also in `all` so the packaged App carries it. Imported only inside `run`.
- Models download on first use from sherpa-onnx's GitHub releases into `<state>/models/diarization/`: `speaker-segmentation-models/sherpa-onnx-pyannote-segmentation-3-0.tar.bz2` (only `model.onnx` extracted) and `speaker-recongition-models/…_16k.onnx`.
- Each goes through a temporary file and an atomic rename under one lock, as voice input downloads Whisper models.

## Compared with

| Product | Meetings |
| --- | --- |
| Claude (desktop) | No meeting feature |
| Codex / ChatGPT (desktop) | ChatGPT's record mode: a companion joins through the meeting application, lists upcoming meetings, transcribes and summarizes. Codex has none. |
| DeepSeek Harness | Experimental voice-input plugin only |
| OpenProgram | Records microphone and any application's sound, transcribes both, tells voices apart on this computer, writes the summary in a chat. No calendar list of upcoming meetings. |

**Open-source recorders**

| Project | Shape |
| --- | --- |
| meetscribe-offline | Python, pyannote diarization, Ollama or cloud summaries; needs a HuggingFace token, prefers an NVIDIA GPU |
| HushScribe | macOS 26, Apple Silicon, WhisperKit and Parakeet on device; speaker labels only after the session |
| AI-Meeting-Bot | Developer pipeline around a local Whisper |

None is reused whole: each brings its own capture, models and storage. Reused is the component choice: Whisper for speech, pyannote segmentation with a speaker-embedding model for who spoke, through sherpa-onnx so no PyTorch or token is needed.

## Implementation status

Everything above is built. Open: exporting the package as a standalone App with a trimmed runtime that answers the same host calls; a check of the Screen & System Audio Recording prompt and permission classification in a freshly installed App.

**How it is verified**

- Tests with a faked sample source, ffmpeg, speech, diarizer and summary turn; the backend's tests run it against a stand-in context and check that it imports nothing of the host.
- The stable App recorded recordings played through the computer's sound output: sherpa-onnx's four-speaker test, an AMI two-speaker excerpt (both found), an AMI four-speaker excerpt (all four found, every line's number consistent with the reference).
- A real call: two participants in a Jitsi Meet room, the second speaking the AMI four-person excerpt, the first playing it on this computer. Exactly four numbered speakers, every line consistent. Call audio reaches the recorder through the same path as Zoom or any other application.
- Microphone track, from the Meetings window in a browser whose microphone was the AMI excerpt: seven chunks uploaded, six lines labelled "Me", summary written. The header-only last chunk was the one failure; the page now skips it.
