forked from ag2ai/ag2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Voice hooks in RealtimeAgent (ag2ai#1040)
* input audio messages passed to RealtimeClient * Added AudioObserver * clear outputs from the notebook * notebook formatting * more notebook formatting * even more notebook formatting * exciting more notebook formatting * catch CancelledError * catch queue get exception * see if timeout influences result of test * check the number of calls in test * add timeout in test in order to allow background tasks to run * move away from asyncio * remove asyncio.sleep from the test * skip failing realtime tests
- Loading branch information
1 parent
74902f3
commit 5d2f165
Showing
13 changed files
with
160 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Copyright (c) 2023 - 2025, AG2ai, Inc., AG2ai open-source projects maintainers and core contributors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from typing import TYPE_CHECKING, Optional | ||
|
||
from ....doc_utils import export_module | ||
from .realtime_events import InputAudioBufferDelta, RealtimeEvent | ||
from .realtime_observer import RealtimeObserver | ||
|
||
if TYPE_CHECKING: | ||
from logging import Logger | ||
|
||
|
||
@export_module("autogen.agentchat.realtime.experimental") | ||
class AudioObserver(RealtimeObserver): | ||
"""Observer for user voice input""" | ||
|
||
def __init__(self, *, logger: Optional["Logger"] = None) -> None: | ||
"""Observer for user voice input""" | ||
super().__init__(logger=logger) | ||
|
||
async def on_event(self, event: RealtimeEvent) -> None: | ||
"""Observe voice input events from the Realtime. | ||
Args: | ||
event (dict[str, Any]): The event from the OpenAI Realtime API. | ||
""" | ||
if isinstance(event, InputAudioBufferDelta): | ||
self.logger.info("Received audio buffer delta") | ||
|
||
async def initialize_session(self) -> None: | ||
"""No need to initialize session from this observer""" | ||
pass | ||
|
||
async def run_loop(self) -> None: | ||
"""Run the observer loop.""" | ||
pass | ||
|
||
|
||
if TYPE_CHECKING: | ||
function_observer: RealtimeObserver = AudioObserver() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.