pipecat-facemode 0.3.0__tar.gz → 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/PKG-INFO +3 -3
  2. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/README.md +2 -2
  3. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode/service.py +19 -3
  4. pipecat_facemode-0.3.1/pipecat_facemode/version.py +3 -0
  5. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode.egg-info/PKG-INFO +3 -3
  6. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode.egg-info/SOURCES.txt +1 -0
  7. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pyproject.toml +1 -1
  8. pipecat_facemode-0.3.1/test/test_interruption.py +150 -0
  9. pipecat_facemode-0.3.0/pipecat_facemode/version.py +0 -3
  10. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/LICENSE +0 -0
  11. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode/__init__.py +0 -0
  12. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode/daily_client.py +0 -0
  13. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode/exceptions.py +0 -0
  14. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode/models.py +0 -0
  15. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode.egg-info/dependency_links.txt +0 -0
  16. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode.egg-info/requires.txt +0 -0
  17. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/pipecat_facemode.egg-info/top_level.txt +0 -0
  18. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/setup.cfg +0 -0
  19. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/test/test_contract.py +0 -0
  20. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/test/test_daily.py +0 -0
  21. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/test/test_ingestion.py +0 -0
  22. {pipecat_facemode-0.3.0 → pipecat_facemode-0.3.1}/test/test_reconnect.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipecat-facemode
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: FaceMode avatar integration for Pipecat
5
5
  Author: FaceMode
6
6
  License-Expression: Apache-2.0
@@ -58,7 +58,7 @@ From this directory:
58
58
  pip install .
59
59
  ```
60
60
 
61
- The package supports Pipecat 1.7 through the current 1.x line, LiveKit RTC 1.x, daily-python 0.31 or later (optional), aiohttp 3.x, websockets 14 through 16, and NumPy 2.x. Requires Python 3.13 or later.
61
+ The package requires Python 3.13 or later and supports `pipecat-ai>=1.7,<2`, `livekit>=1.1,<2`, `daily-python>=0.31,<1` (optional), `aiohttp>=3.10,<4`, `websockets>=14,<17`, and `numpy>=2,<3`.
62
62
 
63
63
  ## Basic usage
64
64
 
@@ -179,7 +179,7 @@ The canonical protocol messages are used as follows:
179
179
  - `TTSAudioRawFrame.audio` is sent as binary little-endian signed 16-bit PCM,
180
180
  with no JSON or base64 wrapper.
181
181
  - `end_utterance` follows a TTS stop frame or a short idle period.
182
- - `cancel_utterance` is sent for `StartInterruptionFrame`.
182
+ - `cancel_utterance` is sent for Pipecat interruption frames.
183
183
  - `ping` is sent periodically while the session is alive.
184
184
  - `end_session` is sent during graceful `EndFrame` or pipeline cleanup.
185
185
 
@@ -33,7 +33,7 @@ From this directory:
33
33
  pip install .
34
34
  ```
35
35
 
36
- The package supports Pipecat 1.7 through the current 1.x line, LiveKit RTC 1.x, daily-python 0.31 or later (optional), aiohttp 3.x, websockets 14 through 16, and NumPy 2.x. Requires Python 3.13 or later.
36
+ The package requires Python 3.13 or later and supports `pipecat-ai>=1.7,<2`, `livekit>=1.1,<2`, `daily-python>=0.31,<1` (optional), `aiohttp>=3.10,<4`, `websockets>=14,<17`, and `numpy>=2,<3`.
37
37
 
38
38
  ## Basic usage
39
39
 
@@ -154,7 +154,7 @@ The canonical protocol messages are used as follows:
154
154
  - `TTSAudioRawFrame.audio` is sent as binary little-endian signed 16-bit PCM,
155
155
  with no JSON or base64 wrapper.
156
156
  - `end_utterance` follows a TTS stop frame or a short idle period.
157
- - `cancel_utterance` is sent for `StartInterruptionFrame`.
157
+ - `cancel_utterance` is sent for Pipecat interruption frames.
158
158
  - `ping` is sent periodically while the session is alive.
159
159
  - `end_session` is sent during graceful `EndFrame` or pipeline cleanup.
160
160
 
@@ -341,6 +341,17 @@ class FaceModeVideoService(FrameProcessor):
341
341
  await self.push_frame(frame, direction)
342
342
  return
343
343
 
344
+ # A new synthesis turn proves the pipeline has moved past the
345
+ # interruption, so stale-frame dropping must end here. Neither
346
+ # StartInterruptionFrame nor StopInterruptionFrame exists in any
347
+ # supported pipecat version, which makes these the only reliable
348
+ # reset signals. Use class-name checks so this package remains
349
+ # importable with versions that do not expose every frame type.
350
+ if frame.__class__.__name__ in {"TTSStartedFrame", "BotStartedSpeakingFrame"}:
351
+ self._interrupted = False
352
+ await self.push_frame(frame, direction)
353
+ return
354
+
344
355
  # Pipecat 1.7 emits TTSStoppedFrame after an utterance. Use a class-name
345
356
  # check so this package remains importable with versions that do not expose
346
357
  # that frame, while the required frames above stay explicit and typed.
@@ -1090,7 +1101,7 @@ class FaceModeVideoService(FrameProcessor):
1090
1101
  """Wait for queued audio to reach the wire before a boundary marker."""
1091
1102
  queue = self._audio_drain_queue
1092
1103
  task = self._audio_drain_task
1093
- if queue is None or queue.empty() or task is None or task.done():
1104
+ if queue is None or task is None or task.done():
1094
1105
  return
1095
1106
  with contextlib.suppress(asyncio.TimeoutError):
1096
1107
  await asyncio.wait_for(
@@ -1247,15 +1258,20 @@ class FaceModeVideoService(FrameProcessor):
1247
1258
  # Flush queued audio first so the end marker cannot overtake the
1248
1259
  # tail of a paced burst and split it into an implicit utterance.
1249
1260
  await self._flush_audio_drain()
1261
+ if self._interrupted or self._stopping:
1262
+ return
1250
1263
  await self._send_control("end_utterance")
1251
1264
 
1252
1265
  async def _cancel_utterance(self) -> None:
1253
1266
  self._cancel_utterance_timer()
1254
- was_active = self._utterance_active
1255
1267
  self._utterance_active = False
1256
1268
  self._utterance_context_id = None
1257
1269
  self._purge_audio_drain()
1258
- if was_active and self._protocol_started and self.websocket is not None:
1270
+ # The server-side cancel wipes all queued speech unconditionally, so it
1271
+ # is sent even when the client-side utterance already ended: playback of
1272
+ # the server-side drain may still be in flight, and a redundant cancel
1273
+ # on an idle server queue is harmless.
1274
+ if self._protocol_started and self.websocket is not None:
1259
1275
  await self._send_control("cancel_utterance")
1260
1276
 
1261
1277
  def _arm_utterance_end_timer(self) -> None:
@@ -0,0 +1,3 @@
1
+ """Package version."""
2
+
3
+ __version__ = "0.3.1"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pipecat-facemode
3
- Version: 0.3.0
3
+ Version: 0.3.1
4
4
  Summary: FaceMode avatar integration for Pipecat
5
5
  Author: FaceMode
6
6
  License-Expression: Apache-2.0
@@ -58,7 +58,7 @@ From this directory:
58
58
  pip install .
59
59
  ```
60
60
 
61
- The package supports Pipecat 1.7 through the current 1.x line, LiveKit RTC 1.x, daily-python 0.31 or later (optional), aiohttp 3.x, websockets 14 through 16, and NumPy 2.x. Requires Python 3.13 or later.
61
+ The package requires Python 3.13 or later and supports `pipecat-ai>=1.7,<2`, `livekit>=1.1,<2`, `daily-python>=0.31,<1` (optional), `aiohttp>=3.10,<4`, `websockets>=14,<17`, and `numpy>=2,<3`.
62
62
 
63
63
  ## Basic usage
64
64
 
@@ -179,7 +179,7 @@ The canonical protocol messages are used as follows:
179
179
  - `TTSAudioRawFrame.audio` is sent as binary little-endian signed 16-bit PCM,
180
180
  with no JSON or base64 wrapper.
181
181
  - `end_utterance` follows a TTS stop frame or a short idle period.
182
- - `cancel_utterance` is sent for `StartInterruptionFrame`.
182
+ - `cancel_utterance` is sent for Pipecat interruption frames.
183
183
  - `ping` is sent periodically while the session is alive.
184
184
  - `end_session` is sent during graceful `EndFrame` or pipeline cleanup.
185
185
 
@@ -15,4 +15,5 @@ pipecat_facemode.egg-info/top_level.txt
15
15
  test/test_contract.py
16
16
  test/test_daily.py
17
17
  test/test_ingestion.py
18
+ test/test_interruption.py
18
19
  test/test_reconnect.py
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pipecat-facemode"
7
- version = "0.3.0"
7
+ version = "0.3.1"
8
8
  license = "Apache-2.0"
9
9
  license-files = ["LICENSE"]
10
10
  authors = [{name = "FaceMode"}]
@@ -0,0 +1,150 @@
1
+ import asyncio
2
+ import json
3
+ import unittest
4
+
5
+ from pipecat.frames.frames import InterruptionFrame, TTSAudioRawFrame, TTSStartedFrame
6
+ from pipecat.processors.frame_processor import FrameDirection
7
+
8
+ from pipecat_facemode.models import LiveKitRoom, SessionDetails
9
+ from pipecat_facemode.service import FaceModeVideoService
10
+
11
+ from test_reconnect import (
12
+ _FakeWebSocket,
13
+ _RecordingClient,
14
+ _session_payload,
15
+ )
16
+
17
+
18
+ def _started_service(testcase, websocket=None):
19
+ service = FaceModeVideoService(
20
+ api_key="api-key",
21
+ room=testcase.room,
22
+ http_session=_RecordingClient(),
23
+ input_provider="deepgram",
24
+ protocol_timeout=5.0,
25
+ )
26
+ service.session = SessionDetails.from_api(_session_payload("token-initial", testcase.room))
27
+ service.websocket = websocket or _FakeWebSocket()
28
+ service._started = True
29
+ service._protocol_started = True
30
+ service._protocol_start_sent = True
31
+ service._protocol_started_event.set()
32
+ service._audio_sample_rate = 24_000
33
+ service._audio_channels = 1
34
+ service._transport_ready_event.set()
35
+ return service
36
+
37
+
38
+ def _tts_frame(service, samples=240):
39
+ return TTSAudioRawFrame(
40
+ audio=b"\x01\x00" * samples,
41
+ sample_rate=service._audio_sample_rate,
42
+ num_channels=service._audio_channels,
43
+ )
44
+
45
+
46
+ class InterruptionHandlingTests(unittest.IsolatedAsyncioTestCase):
47
+ def setUp(self):
48
+ self.room = LiveKitRoom(
49
+ url="wss://livekit.example.test",
50
+ token="worker-room-token",
51
+ name="room-123",
52
+ )
53
+ self.service = None
54
+
55
+ async def asyncTearDown(self):
56
+ if self.service is not None:
57
+ self.service._stopping = True
58
+ await self.service._shutdown(send_end_session=False)
59
+
60
+ def control_types(self, service):
61
+ return [
62
+ json.loads(raw)["type"]
63
+ for raw in service.websocket.sent_text
64
+ if json.loads(raw)["type"] in ("start_utterance", "end_utterance", "cancel_utterance")
65
+ ]
66
+
67
+ async def test_interrupted_state_resets_on_tts_started_frame(self):
68
+ service = _started_service(self)
69
+ self.service = service
70
+ service._interrupted = True
71
+
72
+ await service.process_frame(TTSStartedFrame(), FrameDirection.DOWNSTREAM)
73
+ self.assertFalse(service._interrupted)
74
+
75
+ async def test_tts_audio_flows_again_after_interruption_reset(self):
76
+ service = _started_service(self)
77
+ self.service = service
78
+
79
+ # user interrupts: gate closes, cancel goes out
80
+ await service.process_frame(InterruptionFrame(), FrameDirection.DOWNSTREAM)
81
+ self.assertTrue(service._interrupted)
82
+ self.assertIn("cancel_utterance", self.control_types(service))
83
+
84
+ # frames of the interrupted turn still in flight are dropped
85
+ before = len(service.websocket.sent_binary)
86
+ await service.process_frame(_tts_frame(service), FrameDirection.DOWNSTREAM)
87
+ self.assertEqual(len(service.websocket.sent_binary), before)
88
+
89
+ # the new conversational turn reopens the gate
90
+ await service.process_frame(TTSStartedFrame(), FrameDirection.DOWNSTREAM)
91
+ self.assertFalse(service._interrupted)
92
+
93
+ async def test_cancel_sent_even_after_utterance_already_ended(self):
94
+ service = _started_service(self)
95
+ self.service = service
96
+ # utterance already ended client-side (idle timer or TTSStoppedFrame),
97
+ # but the server-side drain may still be playing out
98
+ service._utterance_active = False
99
+
100
+ await service.process_frame(InterruptionFrame(), FrameDirection.DOWNSTREAM)
101
+ self.assertIn("cancel_utterance", self.control_types(service))
102
+
103
+ async def test_end_utterance_suppressed_when_interrupted(self):
104
+ service = _started_service(self)
105
+ self.service = service
106
+ service._utterance_active = True
107
+ service._interrupted = True
108
+
109
+ await service._end_utterance()
110
+ self.assertNotIn("end_utterance", self.control_types(service))
111
+
112
+ async def test_end_utterance_sent_normally_when_not_interrupted(self):
113
+ service = _started_service(self)
114
+ self.service = service
115
+ service._utterance_active = True
116
+
117
+ await service._end_utterance()
118
+ self.assertIn("end_utterance", self.control_types(service))
119
+
120
+ async def test_flush_audio_drain_waits_for_mid_drain_item(self):
121
+ service = _started_service(self)
122
+ self.service = service
123
+
124
+ consumed = asyncio.Event()
125
+ release = asyncio.Event()
126
+
127
+ async def slow_send(chunk):
128
+ consumed.set()
129
+ await release.wait()
130
+
131
+ service._send_binary = slow_send # type: ignore[method-assign]
132
+ service._audio_drain_queue = asyncio.Queue()
133
+ service._audio_drain_task = asyncio.create_task(service._audio_drain_loop())
134
+ service._audio_send_due = 0.0
135
+ await service._audio_drain_queue.put(b"x" * 100)
136
+ await asyncio.wait_for(consumed.wait(), timeout=5)
137
+
138
+ # the item is dequeued but not finished: empty() is True here, yet the
139
+ # flush must still wait for task_done rather than returning early
140
+ self.assertTrue(service._audio_drain_queue.empty())
141
+ flush = asyncio.create_task(service._flush_audio_drain(timeout=2.0))
142
+ await asyncio.sleep(0.05)
143
+ self.assertFalse(flush.done())
144
+
145
+ release.set()
146
+ await asyncio.wait_for(flush, timeout=5)
147
+
148
+
149
+ if __name__ == "__main__":
150
+ unittest.main()
@@ -1,3 +0,0 @@
1
- """Package version."""
2
-
3
- __version__ = "0.3.0"