Skip to content

Add EchoCall: VAD-based speech echo handler + VoiceActivityCall base + echo CLI#37

Merged
codingjoe merged 6 commits intomainfrom
copilot/fix-echocall-replay-audio
Mar 15, 2026
Merged

Add EchoCall: VAD-based speech echo handler + VoiceActivityCall base + echo CLI#37
codingjoe merged 6 commits intomainfrom
copilot/fix-echocall-replay-audio

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 15, 2026

Adds EchoCall, a call handler that buffers the caller's speech and replays it once sustained silence is detected — useful for latency testing and call-flow demos.

Introduces VoiceActivityCall, a shared VAD base class that eliminates duplicate code between EchoCall and TranscribeCall/AgentCall. Also adds a voip sip … echo CLI command for quick end-to-end testing.

Design

  • VoiceActivityCall encapsulates the shared VAD pattern: speech_threshold, silence_gap, speech_buffer, silence_handle, on_audio_speech, on_audio_silence, flush_speech_buffer, and the speech_buffer_ready hook
  • collect_audio() controls which frames are buffered — default buffers speech only; TranscribeCall overrides to buffer all frames (preserving intra-utterance silences)
  • EchoCall only overrides speech_buffer_ready: resample buffered audio and send via RTP
  • TranscribeCall extends VoiceActivityCall, removing all previously duplicated fields and methods
  • Timer arms only when the buffer is non-empty; cancelled on each speech frame; fires after silence_gap seconds of sustained silence

Usage

class MySession(SessionInitiationProtocol):
    def call_received(self, request: Request) -> None:
        self.answer(request=request, call_class=EchoCall)

Tunable via keyword args:

EchoCall(rtp=..., sip=..., caller=..., media=..., speech_threshold=0.005, silence_gap=1.0)

CLI:

voip sip sips:[email protected] --password secret echo

Changes

  • voip/audio.pyVoiceActivityCall base class and EchoCall; both added to __all__
  • voip/ai.pyTranscribeCall refactored to extend VoiceActivityCall; duplicate fields and methods removed
  • voip/__main__.pyecho CLI subcommand added under sip
  • tests/test_audio.pyTestVoiceActivityCall + lean TestEchoCall (100% module coverage)
  • tests/test_ai.py — updated for renamed silence_handle and moved patch targets
  • tests/test_main.pyTestEchoCLI added
  • docs/calls.mdVoiceActivityCall and EchoCall sections added
Original prompt

This section details on the original issue you should resolve

<issue_title>EchoCall class that waits for the other party to finish (sustained low RMS) and replays the same audio back</issue_title>
<issue_description></issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: SuperJoe
CodingJoe's digital clone following his coding guidelines and best practices.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.12%. Comparing base (986f405) to head (27d1ae6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #37      +/-   ##
==========================================
+ Coverage   94.02%   94.12%   +0.10%     
==========================================
  Files          23       23              
  Lines        1690     1720      +30     
==========================================
+ Hits         1589     1619      +30     
  Misses        101      101              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title [WIP] Fix EchoCall class to replay audio after low RMS Add EchoCall: VAD-based speech echo handler Mar 15, 2026
Copilot AI requested a review from codingjoe March 15, 2026 19:19
Copy link
Copy Markdown
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

@copilot try to avoid duplicate code with the AgentCall class. Add a CLI command too, since it's a great tool to test and debug the library.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 15, 2026

@copilot try to avoid duplicate code with the AgentCall class. Add a CLI command too, since it's a great tool to test and debug the library.

Done in da6d920.

Duplicate code removed: Extracted VoiceActivityCall base class in voip/audio.py that holds all shared VAD infrastructure (speech_threshold, silence_gap, speech_buffer, silence_handle, collect_audio, on_audio_speech, on_audio_silence, flush_speech_buffer, speech_buffer_ready). EchoCall now only overrides speech_buffer_ready. TranscribeCall extends the same base, overrides collect_audio to return True (buffer all frames), and moves the min-length guard into speech_buffer_ready.

CLI command added: voip sip <AOR> --password … echo registers with the SIP carrier and echoes caller speech back — useful for latency testing and debugging.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • releases.astral.sh
    • Triggering command: /home/REDACTED/.local/bin/uv uv run --extra=audio pytest tests/test_audio.py -v (dns block)
  • stun.cloudflare.com
    • Triggering command: /home/REDACTED/work/VoIP/VoIP/.venv/bin/pytest pytest -v (dns block)
    • Triggering command: /home/REDACTED/work/VoIP/VoIP/.venv/bin/pytest pytest -v --tb=short (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add EchoCall: VAD-based speech echo handler Add EchoCall: VAD-based speech echo handler + VoiceActivityCall base + echo CLI Mar 15, 2026
Copilot AI requested a review from codingjoe March 15, 2026 19:40
Copy link
Copy Markdown
Owner

@codingjoe codingjoe left a comment

Choose a reason for hiding this comment

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

LGTM

@codingjoe codingjoe marked this pull request as ready for review March 15, 2026 20:00
Copilot AI review requested due to automatic review settings March 15, 2026 20:00
Copy link
Copy Markdown

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 a new VAD-driven call handler (EchoCall) and factors shared voice-activity / buffering logic into a reusable VoiceActivityCall base, then exposes the echo behavior via a new voip sip … echo CLI subcommand.

Changes:

  • Introduce VoiceActivityCall (shared energy-based VAD, buffering, silence debounce, and flush hook) and implement EchoCall on top of it.
  • Refactor TranscribeCall to inherit from VoiceActivityCall and override buffering behavior for transcription.
  • Add sip echo CLI command plus corresponding tests and API docs updates.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
voip/audio.py Adds VoiceActivityCall + EchoCall, updates codec preference defaults, updates module exports.
voip/ai.py Refactors TranscribeCall to extend VoiceActivityCall and removes duplicated VAD/buffering logic.
voip/__main__.py Adds voip sip … echo command wiring SIP answering to EchoCall.
tests/test_audio.py Adds unit tests for VoiceActivityCall and EchoCall.
tests/test_ai.py Updates tests for the new silence_handle naming and moved patch targets.
tests/test_main.py Adds CLI tests for sip echo and updates module stubs.
docs/calls.md Adds mkdocstrings sections for VoiceActivityCall and EchoCall.

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

@codingjoe codingjoe merged commit 0343b30 into main Mar 15, 2026
26 checks passed
@codingjoe codingjoe deleted the copilot/fix-echocall-replay-audio branch March 15, 2026 20:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EchoCall class that waits for the other party to finish (sustained low RMS) and replays the same audio back

3 participants