Skip to content

Fix G.722 ADPCM state reset between TTS chunks causing robotic audio - #47

Closed
codingjoe with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-g722-sound-issue
Closed

Fix G.722 ADPCM state reset between TTS chunks causing robotic audio#47
codingjoe with Copilot wants to merge 3 commits into
mainfrom
copilot/fix-g722-sound-issue

Conversation

Copilot AI commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

G.722 TTS output sounded robotic because each send_rtp_audio() call created a fresh av.AudioCodecContext, resetting the ADPCM predictor at every chunk boundary. The receiver decoded a series of independent ADPCM streams rather than one continuous one.

Changes

  • voip/codecs/base.py: Add PayloadEncoder protocol, PerPacketEncoder (stateless delegate to codec.packetize), and RTPCodec.create_encoder() factory — mirrors the existing decoder pattern
  • voip/codecs/g722.py: Add G722Encoder dataclass with a persistent av.AudioCodecContext that survives across packetize() calls; add G722.create_encoder(). Encoding is eager (not lazy generator) so ADPCM state and PTS advance immediately on each call
  • voip/audio.py: Add payload_encoder: PayloadEncoder to AudioCall, initialized in __post_init__ via codec.create_encoder(), used in send_rtp_audio() replacing self.codec.packetize()
  • docs/codecs.md: Document G722Encoder, PayloadEncoder, PerPacketEncoder
# Before: fresh codec context → ADPCM reset every chunk
for chunk in tts_chunks:
    await self.send_rtp_audio(chunk)  # G722.encode() → new AudioCodecContext each time

# After: persistent context across all chunks for this call
self.payload_encoder = G722.create_encoder()  # one G722Encoder per call
for chunk in tts_chunks:
    await self.send_rtp_audio(chunk)  # G722Encoder.packetize() → state preserved
Original prompt

This section details on the original issue you should resolve

<issue_title>🐛 G.722 is sounding off</issue_title>
<issue_description>### Bug Description

When I use the echo call, the response is audible but broken. It seems too short and sounds "like a robot". The pitch and gain seem correct.

Expected Behavior

I should hear my voice in the echo call clear as day, since it's a high-res call and I have a wired broadband connection to the UAS. My ping stats are round-trip min/avg/max/stddev = 26.084/29.938/32.507/2.109 ms.

Version

0.2.1

Stack trace

No response

Steps to Reproduce

No response</issue_description>

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

@codingjoe #43 worked for the echo call, but the agent suffers from the same strange sound. Open a new PR against main and check if the TTS output is correctly send via G.722

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@codecov

codecov Bot commented Mar 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.36%. Comparing base (53b1491) to head (87410c3).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   94.25%   94.36%   +0.10%     
==========================================
  Files          24       24              
  Lines        1759     1793      +34     
==========================================
+ Hits         1658     1692      +34     
  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 and others added 2 commits March 16, 2026 14:21
Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
…t_chunk

Co-authored-by: codingjoe <1772890+codingjoe@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix G.722 sound issue during echo call Fix G.722 ADPCM state reset between TTS chunks causing robotic audio Mar 16, 2026
Copilot AI requested a review from codingjoe March 16, 2026 14:42
@codingjoe

Copy link
Copy Markdown
Owner

That wasn't it 👎

@codingjoe codingjoe closed this Mar 17, 2026
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.

🐛 G.722 is sounding off

2 participants