Skip to content

Commit 3ec40d1

Browse files
Add interruptions to agents and update poet example
1 parent 1b5ed20 commit 3ec40d1

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

examples/poet_chat/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ async def _openai_recv():
3030
if event.type == "audio":
3131
audio = event.audio.data
3232
await track.send_chunk(audio)
33+
elif event.type == "audio_interrupted":
34+
await track.interrupt()
3335
elif event.type == "raw_model_event":
3436
if event.data.type == "input_audio_transcription_completed":
3537
print(f"Peer said:\n{event.data.transcript}\n")

examples/poet_chat/poet_chat/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"turn_detection": {
1515
"interrupt_response": True,
1616
"create_response": True,
17+
"type": "semantic_vad",
1718
},
1819
}
1920
},

fishjam/agent/agent.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
AgentRequestAddTrack,
1717
AgentRequestAddTrackCodecParameters,
1818
AgentRequestAuthRequest,
19+
AgentRequestInterruptTrack,
1920
AgentResponse,
2021
)
2122
from fishjam.events._protos.fishjam import AgentRequestTrackData as OutgoingTrackData
@@ -82,6 +83,23 @@ async def send_chunk(self, data: bytes):
8283

8384
await self.session._send(message)
8485

86+
async def interrupt(self):
87+
"""
88+
Interrupt current track.
89+
90+
Any audio that has been sent, but not played
91+
will be cleared and be prevented from playing.
92+
93+
Audio sent after the interrupt will be played normally.
94+
"""
95+
message = AgentRequest(
96+
interrupt_track=AgentRequestInterruptTrack(
97+
track_id=self.id,
98+
)
99+
)
100+
101+
await self.session._send(message)
102+
85103

86104
class AgentSession:
87105
def __init__(self, agent: Agent, websocket: ClientConnection):

fishjam/events/_protos/fishjam/__init__.py

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)