Let a recording be held while something else happens

A phone call in the middle of a dictation left two choices: send what
was said so far off to be transcribed, or throw it away. Both end the
sentence you were in the middle of. Now the recording can be held: the
microphone stays ours, what was said before the pause stays in the
buffer, and what is said during it is dropped.

The capture program keeps running and keeps handing blocks over, which
are read and thrown away rather than left in the pipe. Stopping it
instead would mean asking the sound server for the device again on the
way back, and that is the one moment another application can take it: a
recording would be lost to the phone call it was paused for.

The clock stops with it. Paused time is time the recording does not
have, so the indicator and the length limit both go by what was
actually captured, and a five minute limit is not spent waiting.

The indicator says so as well, since a pulsing dot, moving bars and a
counting clock otherwise all say the words are still going in: the
ribbon freezes where the pause found it and turns amber behind two
bars. The tray menu holds and resumes it, `dikte pause` does, and so
does a global shortcut, which starts empty because holding a recording
is not something a keyboard has a habit for.

Dictation and a command to the agent both, whichever is recording. A
meeting is left out: it writes to a file as it goes and keeps two
streams aligned itself, and neither of those wants a hole in it.
This commit is contained in:
2026-08-16 13:06:36 +03:00
parent 6397f6c403
commit 0e767454f3
15 changed files with 286 additions and 21 deletions
+25
View File
@@ -72,12 +72,31 @@ class Recorder(QObject):
self._rms = []
self._cancelled = False
self._stopping = False
self._paused = False
self._lock = threading.Lock()
@property
def active(self):
return self._thread is not None and self._thread.is_alive()
@property
def paused(self):
return self._paused
def pause(self, value=True):
"""Stop taking sound in without letting go of the microphone.
The capture program keeps running and keeps handing blocks over; they
are dropped as they arrive rather than kept. Stopping it instead would
mean asking the sound server for the device again on the way back, and
that is the one moment another application can take it: a recording
would be lost to the phone call it was paused for.
What was said while it was paused is gone, which is the point. The two
halves meet as one splice, with none of the room in between.
"""
self._paused = bool(value)
def start(self, target="", max_seconds=300):
if self.active:
return
@@ -102,6 +121,7 @@ class Recorder(QObject):
self._rms = []
self._cancelled = False
self._stopping = False
self._paused = False
self._max_bytes = int(max_seconds * RATE * SAMPLE_WIDTH * CHANNELS)
self._thread = threading.Thread(target=self._pump, daemon=True)
self._thread.start()
@@ -114,6 +134,11 @@ class Recorder(QObject):
chunk = stdout.read(CHUNK_BYTES)
if not chunk:
break
if self._paused:
# Read and thrown away rather than left in the pipe: a pipe
# nobody empties fills up, and the capture program blocks on
# a full one instead of waiting quietly for the resume.
continue
peak, rms = chunk_levels(chunk)
with self._lock:
self._buffer.extend(chunk)