Skip to content

Silence auto-stop: consider both system audio and mic#13

Merged
paberr merged 5 commits intomainfrom
pb/silence-auto-timeout
Mar 8, 2026
Merged

Silence auto-stop: consider both system audio and mic#13
paberr merged 5 commits intomainfrom
pb/silence-auto-timeout

Conversation

@paberr
Copy link
Owner

@paberr paberr commented Mar 8, 2026

Summary

  • Adds silence timeout feature that auto-stops recording after sustained silence (default 5 min, configurable via --silence-timeout or silence_timeout config)
  • When --mic is used, monitors both system audio and mic levels — only triggers timeout when both sources are silent
  • Mic uses a higher noise threshold (1e-2 vs 1e-4) to filter ambient room noise; muted mic counts as silence
  • Sounddevice backend also supports silence timeout
  • README and config docs updated

Test plan

  • swift/build.sh compiles
  • uv run pytest — 221 tests pass
  • Manual: ownscribe --mic --silence-timeout 10 — speaking into mic with no system audio does NOT trigger timeout
  • Manual: stop talking + no system audio → timeout triggers after 10s
  • Manual: mute mic ('m' key) while no system audio → timeout still triggers

Add silence timeout feature that auto-stops recording after sustained
silence. The Swift helper monitors audio levels from both system audio
and mic (when --mic is used), only triggering timeout when both sources
are silent. Mic uses a higher noise threshold (1e-2) to filter ambient
room noise. Muted mic counts as silence.

Also adds sounddevice backend support for silence timeout, README docs,
and config option (silence_timeout = 300 default).
Copilot AI review requested due to automatic review settings March 8, 2026 17:03
@paberr paberr self-assigned this Mar 8, 2026
@paberr paberr added the enhancement New feature or request label Mar 8, 2026
@paberr paberr linked an issue Mar 8, 2026 that may be closed by this pull request
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an auto-stop-on-silence feature to the recording pipeline, including support for combined system-audio + mic recording where the timeout only triggers once both sources have been quiet long enough.

Changes:

  • Adds silence level tracking + a periodic silence-timeout check to the Swift CoreAudio helper (system + mic aware).
  • Plumbs silence_timeout through Python config/CLI into both CoreAudio and SoundDevice backends, and updates pipeline UX messaging/looping.
  • Documents the new feature and configuration defaults in README/config template.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
swift/Sources/AudioCapture.swift Tracks “last loud” for mic + system audio and adds a silence-timeout timer; wires shutdown path + new CLI arg parsing.
src/ownscribe/pipeline.py Passes silence_timeout into recorders; updates recording hints/loop to end when recorder stops.
src/ownscribe/config.py Introduces audio.silence_timeout config default (300s) and documents it in the config template.
src/ownscribe/cli.py Adds --silence-timeout CLI flag and maps it into config.
src/ownscribe/audio/sounddevice_recorder.py Implements silence timeout tracking for the sounddevice backend and exposes is_recording.
src/ownscribe/audio/coreaudio.py Passes --silence-timeout to Swift helper; tracks/filters [SILENCE_TIMEOUT]; exposes is_recording.
src/ownscribe/audio/base.py Adds a common is_recording property on the recorder interface.
README.md Documents silence auto-stop and adds config/usage examples; adds a table of contents.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

- Fix data race: init lastLoudTime before startCapture() in Swift
- Cancel silence timer in stop() to prevent firing during shutdown
- Add --silence-timeout to Swift helper usage text
- Use silence_timed_out property for stop message instead of stop_event
- Raise sd.CallbackStop in sounddevice backend on silence timeout
- Add silence_timed_out property to SoundDeviceRecorder
- Fix lint: split long --silence-timeout CLI option line
- Add tests: config default, CLI flag, recorder passthrough
@paberr
Copy link
Owner Author

paberr commented Mar 8, 2026

@copilot review

Copy link

Copilot AI commented Mar 8, 2026

@paberr I've opened a new pull request, #14, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

…ix test label

- Call recorder.stop() before checking silence_timed_out so CoreAudio
  stderr is parsed before the flag is read
- Replace Date() with DispatchTime.now().uptimeNanoseconds in Swift
  silence timing to avoid wall-clock jumps from NTP sync or sleep/wake
- Fix test_silence_timeout_passed_to_sounddevice to use "sounddevice"
  backend for clarity
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

paberr added 2 commits March 8, 2026 18:09
…tion, code cleanup

- Make is_recording abstract on AudioRecorder base class
- Filter SILENCE_WARNING lines from Swift stderr, print clean Python-side message
- Check stream.active in SoundDeviceRecorder.is_recording
- Validate --silence-timeout as non-negative (click.IntRange in Python, explicit check in Swift)
- Fix time formatting to show "Xm Ys" instead of truncating to whole minutes
- Extract computePeakLevel() helper and named threshold constants in Swift
- Add comments explaining silence timer logic
The Swift helper writes SILENCE_WARNING to stderr during capture,
and piped stderr passes it through in real time. Filtering it in
stop() and replacing with a Python message would delay it until
after recording finishes, defeating its purpose.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@paberr paberr merged commit e0f99a7 into main Mar 8, 2026
6 checks passed
@paberr paberr deleted the pb/silence-auto-timeout branch March 8, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Silence based recording time out

3 participants