-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(avatar): preserve audio wrappers across avatar hot-swaps #5863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
c357c0e
6a23e75
9884666
99f75ce
4d101d5
ca17d29
3e21868
b3c3dd3
5296871
edf8965
f676d3e
b62cd5f
2d952a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -510,7 +510,7 @@ async def _rotate_segment_task(self, old_task: asyncio.Task[None] | None) -> Non | |
| # always create a new impl even if aclose() failed, to avoid leaving | ||
| # self._impl pointing to a closed impl which causes the agent to get stuck | ||
| self._impl = _SegmentSynchronizerImpl( | ||
| options=self._opts, next_in_chain=self._text_output._next_in_chain | ||
| options=self._opts, next_in_chain=self._text_output.next_in_chain | ||
| ) | ||
|
|
||
| # apply the current pause state to the new impl | ||
|
|
@@ -545,19 +545,24 @@ def __init__( | |
| super().__init__( | ||
| label="TranscriptSynchronizer", | ||
| next_in_chain=next_in_chain, | ||
| sample_rate=next_in_chain.sample_rate, | ||
| capabilities=io.AudioOutputCapabilities(pause=True), | ||
| ) | ||
| self._next_in_chain: io.AudioOutput = next_in_chain # redefined for better typing | ||
| self._synchronizer = synchronizer | ||
| self._pushed_duration: float = 0.0 | ||
|
|
||
| @property | ||
| def sample_rate(self) -> int | None: | ||
| if self._sample_rate is not None: | ||
| return self._sample_rate | ||
| return self.next_in_chain.sample_rate if self.next_in_chain else None | ||
|
Comment on lines
+553
to
+557
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 sample_rate is now dynamic instead of fixed at construction time Both Was this helpful? React with 👍 or 👎 to provide feedback. |
||
|
|
||
| async def capture_frame(self, frame: rtc.AudioFrame) -> None: | ||
| # using barrier() on capture should be sufficient, flush() must not be called if | ||
| # capture_frame isn't completed | ||
| await self._synchronizer.barrier() | ||
|
|
||
| await self._next_in_chain.capture_frame(frame) # passthrough audio | ||
| if self.next_in_chain: | ||
| await self.next_in_chain.capture_frame(frame) # passthrough audio | ||
| await super().capture_frame(frame) | ||
| self._pushed_duration += frame.duration | ||
|
|
||
|
|
@@ -587,7 +592,8 @@ async def capture_frame(self, frame: rtc.AudioFrame) -> None: | |
|
|
||
| def flush(self) -> None: | ||
| super().flush() | ||
| self._next_in_chain.flush() | ||
| if self.next_in_chain: | ||
| self.next_in_chain.flush() | ||
|
|
||
| if not self._synchronizer.enabled: | ||
| return | ||
|
|
@@ -600,7 +606,8 @@ def flush(self) -> None: | |
| self._synchronizer._impl.end_audio_input() | ||
|
|
||
| def clear_buffer(self) -> None: | ||
| self._next_in_chain.clear_buffer() | ||
| if self.next_in_chain: | ||
| self.next_in_chain.clear_buffer() | ||
|
|
||
| # this is going to be automatically called by the next_in_chain | ||
| def on_playback_started(self, *, created_at: float) -> None: | ||
|
|
@@ -663,7 +670,6 @@ def __init__( | |
| self, synchronizer: TranscriptSynchronizer, *, next_in_chain: io.TextOutput | None | ||
| ) -> None: | ||
| super().__init__(label="TranscriptSynchronizer", next_in_chain=next_in_chain) | ||
| self._next_in_chain: io.TextOutput | None = next_in_chain | ||
| self._synchronizer = synchronizer | ||
| self._capturing = False | ||
|
|
||
|
|
@@ -682,8 +688,8 @@ async def capture_text(self, text: str) -> None: | |
| "still active; transcription sync is disabled. This usually means " | ||
| "session.output.audio was replaced after AgentSession.start()." | ||
| ) | ||
| if self._next_in_chain: | ||
| await self._next_in_chain.capture_text(text) | ||
| if self.next_in_chain: | ||
| await self.next_in_chain.capture_text(text) | ||
| return | ||
|
|
||
| self._capturing = True | ||
|
|
@@ -699,8 +705,8 @@ async def capture_text(self, text: str) -> None: | |
|
|
||
| def flush(self) -> None: | ||
| if not self._synchronizer.enabled: # passthrough text if the synchronizer is disabled | ||
| if self._next_in_chain: | ||
| self._next_in_chain.flush() | ||
| if self.next_in_chain: | ||
| self.next_in_chain.flush() | ||
| return | ||
|
|
||
| if not self._capturing: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.