Ask parec for sound as it arrives, not two seconds of it at a time

Left alone, parec buffers about two seconds and then hands the lot over at
once. Measured against the chunk the level meter reads:

    parec, as it was          longest gap  2005 ms
    parec --latency-msec=64   longest gap    86 ms
    pw-record                 longest gap   129 ms

On a machine that has parec, which is every PulseAudio one and every PipeWire
one with the compatibility service, the waveform stood still and then jumped,
looking like a microphone that was not picking anything up. The recording
itself was fine, but the tail of one can be lost that way too: stop() ends the
process, and whatever is still held back goes with it.

The number asked for is the meter's own chunk, which is the unit the rest of
this file is measured in.
This commit is contained in:
yusufipk
2026-08-01 20:52:43 +07:00
parent 3ead6eb1b5
commit 5c429ab077
2 changed files with 19 additions and 0 deletions
+12
View File
@@ -243,6 +243,18 @@ class RecordingCommand(DikteTest):
self.assertIn(str(audio.CHANNELS), joined)
self.assertIn("s16", joined)
def test_parec_is_asked_for_the_level_meter_s_own_chunk(self):
"""Left alone it buffers about two seconds, which the waveform shows as
a still bar that jumps once a second, and which can cost the tail of a
recording when the process is asked to stop."""
with only_these_tools("parec"):
self.assertIn(f"--latency-msec={audio.CHUNK_LATENCY_MS}",
audio.recording_command())
def test_the_latency_asked_for_is_the_chunk_the_meter_reads(self):
self.assertEqual(audio.CHUNK_LATENCY_MS,
round(audio.CHUNK_FRAMES / audio.RATE * 1000))
def test_a_chosen_microphone_reaches_either_one(self):
with only_these_tools("parec"):
self.assertIn("--device=alsa_input.usb", audio.recording_command(