pipecat-talksign 0.1.0__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.
- pipecat_talksign-0.1.0/.github/workflows/ci.yml +26 -0
- pipecat_talksign-0.1.0/.gitignore +13 -0
- pipecat_talksign-0.1.0/CHANGELOG.md +9 -0
- pipecat_talksign-0.1.0/LICENSE +202 -0
- pipecat_talksign-0.1.0/PKG-INFO +105 -0
- pipecat_talksign-0.1.0/README.md +73 -0
- pipecat_talksign-0.1.0/examples/signing_bot.py +98 -0
- pipecat_talksign-0.1.0/pyproject.toml +55 -0
- pipecat_talksign-0.1.0/src/pipecat_talksign/__init__.py +12 -0
- pipecat_talksign-0.1.0/src/pipecat_talksign/_version.py +1 -0
- pipecat_talksign-0.1.0/src/pipecat_talksign/py.typed +0 -0
- pipecat_talksign-0.1.0/src/pipecat_talksign/video.py +207 -0
- pipecat_talksign-0.1.0/tests/__init__.py +0 -0
- pipecat_talksign-0.1.0/tests/conftest.py +114 -0
- pipecat_talksign-0.1.0/tests/test_video_service.py +150 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- name: Install ffmpeg
|
|
20
|
+
run: sudo apt-get update && sudo apt-get install -y ffmpeg
|
|
21
|
+
- name: Install
|
|
22
|
+
run: pip install -e ".[dev]"
|
|
23
|
+
- name: Lint
|
|
24
|
+
run: ruff check .
|
|
25
|
+
- name: Test
|
|
26
|
+
run: pytest
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (unreleased)
|
|
4
|
+
|
|
5
|
+
- Requires `talksign>=0.2.0`: the avatar's idle loop is fetched at start (one free call), so the avatar
|
|
6
|
+
appears as soon as its idle clip has downloaded (about 3 s after start in staging tests; plain background
|
|
7
|
+
until then).
|
|
8
|
+
- First release: `TalksignVideoService` signs the bot's replies with a Talksign Echo 2.0 avatar
|
|
9
|
+
(`OutputImageRawFrame` at 30 FPS, idle loop, interruption, all frames passed through). Targets Pipecat 1.17.
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Talksign
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pipecat-talksign
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Talksign sign language avatar for Pipecat: an Echo 2.0 avatar signs your bot's replies.
|
|
5
|
+
Project-URL: Homepage, https://talksign.co
|
|
6
|
+
Project-URL: Documentation, https://github.com/talksign/pipecat-talksign#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/talksign/pipecat-talksign
|
|
8
|
+
Project-URL: Issues, https://github.com/talksign/pipecat-talksign/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/talksign/pipecat-talksign/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Talksign
|
|
11
|
+
License-Expression: Apache-2.0
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: accessibility,asl,avatar,pipecat,sign language,talksign,voice agent
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Multimedia :: Video
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: pipecat-ai<2,>=1.17
|
|
25
|
+
Requires-Dist: talksign[video]>=0.2.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
29
|
+
Requires-Dist: respx>=0.21; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# pipecat-talksign
|
|
34
|
+
|
|
35
|
+
A [Talksign](https://talksign.co) sign language avatar for [Pipecat](https://github.com/pipecat-ai/pipecat).
|
|
36
|
+
Your bot's replies are signed in ASL by an **Echo 2.0** avatar while its voice still plays.
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pip install pipecat-talksign # then add TalksignVideoService() after your TTS
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Maintainer:** Talksign · **Tested with:** Pipecat 1.17.0 · Python 3.10+
|
|
43
|
+
|
|
44
|
+
## What it does
|
|
45
|
+
|
|
46
|
+
`TalksignVideoService` is a frame processor that goes right after the TTS service:
|
|
47
|
+
|
|
48
|
+
- reads the text the bot speaks (`TTSTextFrame`) and streams it to Echo 2.0, sentence by sentence;
|
|
49
|
+
- pushes the avatar video as `OutputImageRawFrame` (RGB) at 30 FPS, with the avatar's idle loop between answers;
|
|
50
|
+
- on `InterruptionFrame` (the user barges in) stops signing at once and returns to idle;
|
|
51
|
+
- passes every frame through unchanged, so audio and text reach the transport as before.
|
|
52
|
+
|
|
53
|
+
Sign → text (Palm) is **coming soon**.
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
Get an API key in the [Developer Console](https://developer.talksign.co) and set `TALKSIGN_API_KEY`.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from pipecat_talksign import TalksignVideoService
|
|
61
|
+
|
|
62
|
+
signer = TalksignVideoService(avatar="arthur", language="asl", width=1280, height=720)
|
|
63
|
+
|
|
64
|
+
pipeline = Pipeline(
|
|
65
|
+
[
|
|
66
|
+
transport.input(),
|
|
67
|
+
stt,
|
|
68
|
+
user_aggregator,
|
|
69
|
+
llm,
|
|
70
|
+
tts,
|
|
71
|
+
signer, # after TTS
|
|
72
|
+
transport.output(),
|
|
73
|
+
assistant_aggregator,
|
|
74
|
+
]
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Enable video on the output transport with the same size:
|
|
79
|
+
`video_out_enabled=True, video_out_is_live=True, video_out_width=1280, video_out_height=720`.
|
|
80
|
+
|
|
81
|
+
| Argument | Default | |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `api_key` | `TALKSIGN_API_KEY` | Talksign API key |
|
|
84
|
+
| `avatar` | `"arthur"` | Avatar id |
|
|
85
|
+
| `language` | `"asl"` | Sign language |
|
|
86
|
+
| `width`, `height`, `fps` | `1280`, `720`, `30` | Output video |
|
|
87
|
+
| `text_source` | `"tts"` | `"tts"`: sign spoken text (`TTSTextFrame`). `"llm"`: sign `LLMTextFrame` (place after the LLM; lower latency) |
|
|
88
|
+
| `client` | new client | Reuse a `talksign.AsyncTalksign` |
|
|
89
|
+
| `source_options` | `{}` | Extra `talksign.video.EchoFrameSource` options (`crossfade_ms`, `background`, …) |
|
|
90
|
+
|
|
91
|
+
## Example
|
|
92
|
+
|
|
93
|
+
[`examples/signing_bot.py`](examples/signing_bot.py): Deepgram + OpenAI + Cartesia voice bot with a signing avatar,
|
|
94
|
+
run with the Pipecat development runner (`python examples/signing_bot.py -t daily`).
|
|
95
|
+
|
|
96
|
+
## Development
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
pip install -e ../talksign-python[video] -e ".[dev]"
|
|
100
|
+
pytest # offline: a fake Talksign API serves tiny ffmpeg-made clips
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Apache-2.0
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# pipecat-talksign
|
|
2
|
+
|
|
3
|
+
A [Talksign](https://talksign.co) sign language avatar for [Pipecat](https://github.com/pipecat-ai/pipecat).
|
|
4
|
+
Your bot's replies are signed in ASL by an **Echo 2.0** avatar while its voice still plays.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
pip install pipecat-talksign # then add TalksignVideoService() after your TTS
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
**Maintainer:** Talksign · **Tested with:** Pipecat 1.17.0 · Python 3.10+
|
|
11
|
+
|
|
12
|
+
## What it does
|
|
13
|
+
|
|
14
|
+
`TalksignVideoService` is a frame processor that goes right after the TTS service:
|
|
15
|
+
|
|
16
|
+
- reads the text the bot speaks (`TTSTextFrame`) and streams it to Echo 2.0, sentence by sentence;
|
|
17
|
+
- pushes the avatar video as `OutputImageRawFrame` (RGB) at 30 FPS, with the avatar's idle loop between answers;
|
|
18
|
+
- on `InterruptionFrame` (the user barges in) stops signing at once and returns to idle;
|
|
19
|
+
- passes every frame through unchanged, so audio and text reach the transport as before.
|
|
20
|
+
|
|
21
|
+
Sign → text (Palm) is **coming soon**.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Get an API key in the [Developer Console](https://developer.talksign.co) and set `TALKSIGN_API_KEY`.
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
from pipecat_talksign import TalksignVideoService
|
|
29
|
+
|
|
30
|
+
signer = TalksignVideoService(avatar="arthur", language="asl", width=1280, height=720)
|
|
31
|
+
|
|
32
|
+
pipeline = Pipeline(
|
|
33
|
+
[
|
|
34
|
+
transport.input(),
|
|
35
|
+
stt,
|
|
36
|
+
user_aggregator,
|
|
37
|
+
llm,
|
|
38
|
+
tts,
|
|
39
|
+
signer, # after TTS
|
|
40
|
+
transport.output(),
|
|
41
|
+
assistant_aggregator,
|
|
42
|
+
]
|
|
43
|
+
)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Enable video on the output transport with the same size:
|
|
47
|
+
`video_out_enabled=True, video_out_is_live=True, video_out_width=1280, video_out_height=720`.
|
|
48
|
+
|
|
49
|
+
| Argument | Default | |
|
|
50
|
+
|---|---|---|
|
|
51
|
+
| `api_key` | `TALKSIGN_API_KEY` | Talksign API key |
|
|
52
|
+
| `avatar` | `"arthur"` | Avatar id |
|
|
53
|
+
| `language` | `"asl"` | Sign language |
|
|
54
|
+
| `width`, `height`, `fps` | `1280`, `720`, `30` | Output video |
|
|
55
|
+
| `text_source` | `"tts"` | `"tts"`: sign spoken text (`TTSTextFrame`). `"llm"`: sign `LLMTextFrame` (place after the LLM; lower latency) |
|
|
56
|
+
| `client` | new client | Reuse a `talksign.AsyncTalksign` |
|
|
57
|
+
| `source_options` | `{}` | Extra `talksign.video.EchoFrameSource` options (`crossfade_ms`, `background`, …) |
|
|
58
|
+
|
|
59
|
+
## Example
|
|
60
|
+
|
|
61
|
+
[`examples/signing_bot.py`](examples/signing_bot.py): Deepgram + OpenAI + Cartesia voice bot with a signing avatar,
|
|
62
|
+
run with the Pipecat development runner (`python examples/signing_bot.py -t daily`).
|
|
63
|
+
|
|
64
|
+
## Development
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
pip install -e ../talksign-python[video] -e ".[dev]"
|
|
68
|
+
pytest # offline: a fake Talksign API serves tiny ffmpeg-made clips
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
Apache-2.0
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Talksign
|
|
3
|
+
#
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""A voice bot whose replies are also signed in ASL by a Talksign Echo 2.0 avatar.
|
|
8
|
+
|
|
9
|
+
pip install "pipecat-ai[daily,deepgram,openai,cartesia,runner]" pipecat-talksign
|
|
10
|
+
export TALKSIGN_API_KEY=... DEEPGRAM_API_KEY=... OPENAI_API_KEY=... CARTESIA_API_KEY=...
|
|
11
|
+
python signing_bot.py -t daily
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
|
17
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
18
|
+
from pipecat.pipeline.worker import PipelineParams, PipelineWorker
|
|
19
|
+
from pipecat.processors.aggregators.llm_context import LLMContext
|
|
20
|
+
from pipecat.processors.aggregators.llm_response_universal import (
|
|
21
|
+
LLMContextAggregatorPair,
|
|
22
|
+
LLMUserAggregatorParams,
|
|
23
|
+
)
|
|
24
|
+
from pipecat.runner.types import RunnerArguments
|
|
25
|
+
from pipecat.runner.utils import create_transport
|
|
26
|
+
from pipecat.services.cartesia.tts import CartesiaTTSService
|
|
27
|
+
from pipecat.services.deepgram.stt import DeepgramSTTService
|
|
28
|
+
from pipecat.services.openai.llm import OpenAILLMService
|
|
29
|
+
from pipecat.transports.base_transport import TransportParams
|
|
30
|
+
from pipecat.transports.daily.transport import DailyParams
|
|
31
|
+
from pipecat.workers.runner import WorkerRunner
|
|
32
|
+
|
|
33
|
+
from pipecat_talksign import TalksignVideoService
|
|
34
|
+
|
|
35
|
+
WIDTH, HEIGHT = 1280, 720
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def params(cls):
|
|
39
|
+
return lambda: cls(
|
|
40
|
+
audio_in_enabled=True,
|
|
41
|
+
audio_out_enabled=True,
|
|
42
|
+
video_out_enabled=True,
|
|
43
|
+
video_out_is_live=True,
|
|
44
|
+
video_out_width=WIDTH,
|
|
45
|
+
video_out_height=HEIGHT,
|
|
46
|
+
video_out_framerate=30,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
transport_params = {"daily": params(DailyParams), "webrtc": params(TransportParams)}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
async def bot(runner_args: RunnerArguments):
|
|
54
|
+
transport = await create_transport(runner_args, transport_params)
|
|
55
|
+
|
|
56
|
+
stt = DeepgramSTTService(api_key=os.environ["DEEPGRAM_API_KEY"])
|
|
57
|
+
llm = OpenAILLMService(
|
|
58
|
+
api_key=os.environ["OPENAI_API_KEY"],
|
|
59
|
+
settings=OpenAILLMService.Settings(
|
|
60
|
+
system_instruction="You are a friendly assistant. Keep answers short and plain.",
|
|
61
|
+
),
|
|
62
|
+
)
|
|
63
|
+
tts = CartesiaTTSService(
|
|
64
|
+
api_key=os.environ["CARTESIA_API_KEY"],
|
|
65
|
+
settings=CartesiaTTSService.Settings(voice="71a7ad14-091c-4e8e-a314-022ece01c121"),
|
|
66
|
+
)
|
|
67
|
+
signer = TalksignVideoService(avatar="arthur", language="asl", width=WIDTH, height=HEIGHT)
|
|
68
|
+
|
|
69
|
+
context = LLMContext()
|
|
70
|
+
aggregators = LLMContextAggregatorPair(
|
|
71
|
+
context, user_params=LLMUserAggregatorParams(vad_analyzer=SileroVADAnalyzer())
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
pipeline = Pipeline(
|
|
75
|
+
[
|
|
76
|
+
transport.input(),
|
|
77
|
+
stt,
|
|
78
|
+
aggregators.user(),
|
|
79
|
+
llm,
|
|
80
|
+
tts,
|
|
81
|
+
signer, # after TTS: signs what is spoken, voice passes through
|
|
82
|
+
transport.output(),
|
|
83
|
+
aggregators.assistant(),
|
|
84
|
+
]
|
|
85
|
+
)
|
|
86
|
+
worker = PipelineWorker(pipeline, params=PipelineParams(enable_metrics=True))
|
|
87
|
+
|
|
88
|
+
@transport.event_handler("on_client_disconnected")
|
|
89
|
+
async def on_client_disconnected(transport, client):
|
|
90
|
+
await worker.cancel()
|
|
91
|
+
|
|
92
|
+
await WorkerRunner(handle_sigint=runner_args.handle_sigint).run(worker)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
if __name__ == "__main__":
|
|
96
|
+
from pipecat.runner.run import main
|
|
97
|
+
|
|
98
|
+
main()
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.21"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pipecat-talksign"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Talksign sign language avatar for Pipecat: an Echo 2.0 avatar signs your bot's replies."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Talksign" }]
|
|
14
|
+
keywords = ["pipecat", "talksign", "sign language", "asl", "avatar", "accessibility", "voice agent"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: Apache Software License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Multimedia :: Video",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["pipecat-ai>=1.17,<2", "talksign[video]>=0.2.0"]
|
|
27
|
+
|
|
28
|
+
[project.optional-dependencies]
|
|
29
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.23", "respx>=0.21", "ruff>=0.6"]
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://talksign.co"
|
|
33
|
+
Documentation = "https://github.com/talksign/pipecat-talksign#readme"
|
|
34
|
+
Repository = "https://github.com/talksign/pipecat-talksign"
|
|
35
|
+
Issues = "https://github.com/talksign/pipecat-talksign/issues"
|
|
36
|
+
Changelog = "https://github.com/talksign/pipecat-talksign/blob/main/CHANGELOG.md"
|
|
37
|
+
|
|
38
|
+
[tool.hatch.version]
|
|
39
|
+
path = "src/pipecat_talksign/_version.py"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/pipecat_talksign"]
|
|
43
|
+
|
|
44
|
+
[tool.pytest.ini_options]
|
|
45
|
+
asyncio_mode = "auto"
|
|
46
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
47
|
+
testpaths = ["tests"]
|
|
48
|
+
addopts = "-q"
|
|
49
|
+
|
|
50
|
+
[tool.ruff]
|
|
51
|
+
line-length = 120
|
|
52
|
+
target-version = "py310"
|
|
53
|
+
|
|
54
|
+
[tool.ruff.lint]
|
|
55
|
+
select = ["E", "F", "W", "I", "B", "UP"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Talksign
|
|
3
|
+
#
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""Talksign sign language avatar for Pipecat."""
|
|
8
|
+
|
|
9
|
+
from ._version import __version__
|
|
10
|
+
from .video import TalksignVideoService
|
|
11
|
+
|
|
12
|
+
__all__ = ["TalksignVideoService", "__version__"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.0"
|
|
File without changes
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Copyright 2026 Talksign
|
|
3
|
+
#
|
|
4
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
#
|
|
6
|
+
|
|
7
|
+
"""Talksign video service: an Echo 2.0 avatar that signs the bot's replies."""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import asyncio
|
|
12
|
+
import contextlib
|
|
13
|
+
from typing import Any, Literal
|
|
14
|
+
|
|
15
|
+
from loguru import logger
|
|
16
|
+
from pipecat.frames.frames import (
|
|
17
|
+
CancelFrame,
|
|
18
|
+
EndFrame,
|
|
19
|
+
Frame,
|
|
20
|
+
InterruptionFrame,
|
|
21
|
+
LLMFullResponseEndFrame,
|
|
22
|
+
LLMTextFrame,
|
|
23
|
+
OutputImageRawFrame,
|
|
24
|
+
StartFrame,
|
|
25
|
+
TextFrame,
|
|
26
|
+
TTSStoppedFrame,
|
|
27
|
+
TTSTextFrame,
|
|
28
|
+
)
|
|
29
|
+
from pipecat.processors.frame_processor import FrameDirection
|
|
30
|
+
from pipecat.services.ai_service import AIService
|
|
31
|
+
from pipecat.services.settings import ServiceSettings
|
|
32
|
+
|
|
33
|
+
try:
|
|
34
|
+
from talksign import AsyncTalksign
|
|
35
|
+
from talksign.video import EchoFrameSource
|
|
36
|
+
except ModuleNotFoundError as e: # pragma: no cover
|
|
37
|
+
logger.error(f"Exception: {e}")
|
|
38
|
+
logger.error("In order to use Talksign, you need to `pip install pipecat-talksign`.")
|
|
39
|
+
raise ImportError(f"Missing module: {e}") from e
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
TextSource = Literal["tts", "llm"]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class TalksignVideoService(AIService):
|
|
46
|
+
"""Signs the bot's replies in sign language with a Talksign Echo 2.0 avatar.
|
|
47
|
+
|
|
48
|
+
Place it after the TTS service. It reads the text the bot speaks (``TTSTextFrame``; or
|
|
49
|
+
``LLMTextFrame`` with ``text_source="llm"``), sends it to Echo 2.0 and pushes the avatar's
|
|
50
|
+
video as ``OutputImageRawFrame`` at ``fps`` frames per second. Between answers the avatar
|
|
51
|
+
plays its idle loop. An ``InterruptionFrame`` stops signing at once. Every frame, audio
|
|
52
|
+
included, passes through unchanged, so the bot's voice still plays.
|
|
53
|
+
|
|
54
|
+
Set the output transport's ``video_out_width`` / ``video_out_height`` to ``width`` /
|
|
55
|
+
``height`` and ``video_out_enabled=True``.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
*,
|
|
61
|
+
api_key: str | None = None,
|
|
62
|
+
avatar: str = "arthur",
|
|
63
|
+
language: str = "asl",
|
|
64
|
+
width: int = 1280,
|
|
65
|
+
height: int = 720,
|
|
66
|
+
fps: float = 30.0,
|
|
67
|
+
text_source: TextSource = "tts",
|
|
68
|
+
base_url: str | None = None,
|
|
69
|
+
client: AsyncTalksign | None = None,
|
|
70
|
+
source_options: dict[str, Any] | None = None,
|
|
71
|
+
**kwargs: Any,
|
|
72
|
+
) -> None:
|
|
73
|
+
"""Initialize the Talksign video service.
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
api_key: Talksign API key. Defaults to the ``TALKSIGN_API_KEY`` environment variable.
|
|
77
|
+
avatar: Avatar id, e.g. ``"arthur"``.
|
|
78
|
+
language: Sign language, e.g. ``"asl"``.
|
|
79
|
+
width: Output video width in pixels.
|
|
80
|
+
height: Output video height in pixels.
|
|
81
|
+
fps: Output frame rate.
|
|
82
|
+
text_source: ``"tts"`` signs ``TTSTextFrame`` (what is actually spoken, default);
|
|
83
|
+
``"llm"`` signs ``LLMTextFrame`` (lower latency; place the service after the LLM).
|
|
84
|
+
base_url: Talksign API base URL. Defaults to ``TALKSIGN_BASE_URL`` or the public API.
|
|
85
|
+
client: An existing ``talksign.AsyncTalksign`` client to use (not closed by the service).
|
|
86
|
+
source_options: Extra keyword arguments for ``talksign.video.EchoFrameSource``
|
|
87
|
+
(e.g. ``crossfade_ms``, ``background``).
|
|
88
|
+
**kwargs: Additional arguments passed to the parent AIService.
|
|
89
|
+
"""
|
|
90
|
+
kwargs.setdefault("settings", ServiceSettings(model=None))
|
|
91
|
+
super().__init__(**kwargs)
|
|
92
|
+
if text_source not in ("tts", "llm"):
|
|
93
|
+
raise ValueError('text_source must be "tts" or "llm"')
|
|
94
|
+
self._api_key = api_key
|
|
95
|
+
self._base_url = base_url
|
|
96
|
+
self._avatar = avatar
|
|
97
|
+
self._language = language
|
|
98
|
+
self._width = int(width)
|
|
99
|
+
self._height = int(height)
|
|
100
|
+
self._fps = float(fps)
|
|
101
|
+
self._text_source: TextSource = text_source
|
|
102
|
+
self._client = client
|
|
103
|
+
self._own_client = client is None
|
|
104
|
+
self._source_options = dict(source_options or {})
|
|
105
|
+
self._source: EchoFrameSource | None = None
|
|
106
|
+
self._video_task: asyncio.Task[None] | None = None
|
|
107
|
+
self._need_space = False
|
|
108
|
+
self._end_of_text: type[Frame] = TTSStoppedFrame if text_source == "tts" else LLMFullResponseEndFrame
|
|
109
|
+
|
|
110
|
+
def can_generate_metrics(self) -> bool:
|
|
111
|
+
"""Talksign does not report Pipecat metrics yet."""
|
|
112
|
+
return False
|
|
113
|
+
|
|
114
|
+
@property
|
|
115
|
+
def is_signing(self) -> bool:
|
|
116
|
+
"""True while the avatar is signing (a word is playing or queued)."""
|
|
117
|
+
return self._source is not None and self._source.is_signing
|
|
118
|
+
|
|
119
|
+
# -- lifecycle --------------------------------------------------------------
|
|
120
|
+
async def start(self, frame: StartFrame) -> None:
|
|
121
|
+
"""Opens the Echo stream and starts pushing video frames."""
|
|
122
|
+
await super().start(frame)
|
|
123
|
+
if self._source is not None:
|
|
124
|
+
return
|
|
125
|
+
if self._client is None:
|
|
126
|
+
self._client = AsyncTalksign(api_key=self._api_key, base_url=self._base_url)
|
|
127
|
+
self._source = EchoFrameSource.from_client(
|
|
128
|
+
self._client,
|
|
129
|
+
avatar=self._avatar,
|
|
130
|
+
language=self._language,
|
|
131
|
+
width=self._width,
|
|
132
|
+
height=self._height,
|
|
133
|
+
fps=self._fps,
|
|
134
|
+
**self._source_options,
|
|
135
|
+
)
|
|
136
|
+
self._video_task = self.create_task(self._video_loop(), "talksign_video")
|
|
137
|
+
|
|
138
|
+
async def stop(self, frame: EndFrame) -> None:
|
|
139
|
+
"""Stops the video and closes the Echo stream."""
|
|
140
|
+
await super().stop(frame)
|
|
141
|
+
await self._close()
|
|
142
|
+
|
|
143
|
+
async def cancel(self, frame: CancelFrame) -> None:
|
|
144
|
+
"""Stops the video and closes the Echo stream at once."""
|
|
145
|
+
await super().cancel(frame)
|
|
146
|
+
await self._close()
|
|
147
|
+
|
|
148
|
+
async def cleanup(self) -> None:
|
|
149
|
+
"""Releases everything still open."""
|
|
150
|
+
await super().cleanup()
|
|
151
|
+
await self._close()
|
|
152
|
+
|
|
153
|
+
async def _close(self) -> None:
|
|
154
|
+
source, self._source = self._source, None
|
|
155
|
+
task, self._video_task = self._video_task, None
|
|
156
|
+
if task is not None:
|
|
157
|
+
await self.cancel_task(task)
|
|
158
|
+
if source is not None:
|
|
159
|
+
with contextlib.suppress(Exception):
|
|
160
|
+
await source.aclose()
|
|
161
|
+
if self._own_client and self._client is not None:
|
|
162
|
+
client, self._client = self._client, None
|
|
163
|
+
with contextlib.suppress(Exception):
|
|
164
|
+
await client.aclose()
|
|
165
|
+
|
|
166
|
+
async def _video_loop(self) -> None:
|
|
167
|
+
source = self._source
|
|
168
|
+
assert source is not None
|
|
169
|
+
size = (self._width, self._height)
|
|
170
|
+
try:
|
|
171
|
+
async for image in source:
|
|
172
|
+
await self.push_frame(OutputImageRawFrame(image=image.tobytes(), size=size, format="RGB"))
|
|
173
|
+
except asyncio.CancelledError:
|
|
174
|
+
raise
|
|
175
|
+
except Exception as e:
|
|
176
|
+
await self.push_error(error_msg=f"Talksign video stopped: {e}", exception=e)
|
|
177
|
+
|
|
178
|
+
# -- frames -----------------------------------------------------------------
|
|
179
|
+
def _wants(self, frame: Frame) -> bool:
|
|
180
|
+
if self._text_source == "tts":
|
|
181
|
+
return isinstance(frame, TTSTextFrame)
|
|
182
|
+
return isinstance(frame, LLMTextFrame)
|
|
183
|
+
|
|
184
|
+
def _push_text(self, frame: TextFrame) -> None:
|
|
185
|
+
if self._source is None or not frame.text:
|
|
186
|
+
return
|
|
187
|
+
text = frame.text
|
|
188
|
+
if not frame.includes_inter_frame_spaces and self._need_space and not text[:1].isspace():
|
|
189
|
+
text = " " + text
|
|
190
|
+
self._source.push_text(text)
|
|
191
|
+
self._need_space = not text[-1:].isspace()
|
|
192
|
+
|
|
193
|
+
async def process_frame(self, frame: Frame, direction: FrameDirection) -> None:
|
|
194
|
+
"""Feeds the bot's text to Echo and passes every frame through unchanged."""
|
|
195
|
+
await super().process_frame(frame, direction)
|
|
196
|
+
|
|
197
|
+
if direction == FrameDirection.DOWNSTREAM and self._source is not None:
|
|
198
|
+
if isinstance(frame, InterruptionFrame):
|
|
199
|
+
self._source.interrupt()
|
|
200
|
+
self._need_space = False
|
|
201
|
+
elif isinstance(frame, TextFrame) and self._wants(frame):
|
|
202
|
+
self._push_text(frame)
|
|
203
|
+
elif isinstance(frame, self._end_of_text):
|
|
204
|
+
self._source.flush()
|
|
205
|
+
self._need_space = False
|
|
206
|
+
|
|
207
|
+
await self.push_frame(frame, direction)
|
|
File without changes
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Offline fakes: a fake Talksign API (respx) serving tiny ffmpeg-made clips. No real hosts, no real keys."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import shutil
|
|
8
|
+
import subprocess
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import httpx
|
|
12
|
+
import numpy as np
|
|
13
|
+
import pytest
|
|
14
|
+
import respx
|
|
15
|
+
|
|
16
|
+
BASE = "https://api.example.invalid" # never a real Talksign host
|
|
17
|
+
CDN = "https://cdn.example.invalid"
|
|
18
|
+
KEY = "sk-live-test_000000000000"
|
|
19
|
+
W, H = 48, 32
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture(autouse=True)
|
|
23
|
+
def _no_env(monkeypatch: pytest.MonkeyPatch) -> None:
|
|
24
|
+
monkeypatch.delenv("TALKSIGN_API_KEY", raising=False)
|
|
25
|
+
monkeypatch.delenv("TALKSIGN_BASE_URL", raising=False)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _make_clip(path: Path, color: str, frames: int) -> bytes:
|
|
29
|
+
subprocess.run(
|
|
30
|
+
[
|
|
31
|
+
"nice",
|
|
32
|
+
"-n",
|
|
33
|
+
"19",
|
|
34
|
+
"ffmpeg",
|
|
35
|
+
"-loglevel",
|
|
36
|
+
"error",
|
|
37
|
+
"-y",
|
|
38
|
+
"-f",
|
|
39
|
+
"lavfi",
|
|
40
|
+
"-i",
|
|
41
|
+
f"color=c={color}:s=64x48:r=30",
|
|
42
|
+
"-frames:v",
|
|
43
|
+
str(frames),
|
|
44
|
+
"-pix_fmt",
|
|
45
|
+
"yuv420p",
|
|
46
|
+
"-c:v",
|
|
47
|
+
"libx264",
|
|
48
|
+
"-preset",
|
|
49
|
+
"ultrafast",
|
|
50
|
+
"-threads",
|
|
51
|
+
"1",
|
|
52
|
+
str(path),
|
|
53
|
+
],
|
|
54
|
+
check=True,
|
|
55
|
+
)
|
|
56
|
+
return path.read_bytes()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.fixture(scope="session")
|
|
60
|
+
def clips(tmp_path_factory: pytest.TempPathFactory) -> dict[str, bytes]:
|
|
61
|
+
if not shutil.which("ffmpeg"):
|
|
62
|
+
pytest.skip("ffmpeg not installed")
|
|
63
|
+
d = tmp_path_factory.mktemp("clips")
|
|
64
|
+
return {
|
|
65
|
+
"red": _make_clip(d / "red.mp4", "red", 6),
|
|
66
|
+
"blue": _make_clip(d / "blue.mp4", "blue", 6),
|
|
67
|
+
"green": _make_clip(d / "green.mp4", "green", 6),
|
|
68
|
+
"idle": _make_clip(d / "idle.mp4", "black", 4),
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def color_of(frame: np.ndarray) -> str:
|
|
73
|
+
r, g, b = frame[frame.shape[0] // 2, frame.shape[1] // 2].astype(int)
|
|
74
|
+
if r > 150 and g < 100 and b < 100:
|
|
75
|
+
return "red"
|
|
76
|
+
if b > 150 and r < 100 and g < 100:
|
|
77
|
+
return "blue"
|
|
78
|
+
if g > 100 and r < 100 and b < 100:
|
|
79
|
+
return "green"
|
|
80
|
+
if r < 40 and g < 40 and b < 40:
|
|
81
|
+
return "black"
|
|
82
|
+
if r > 200 and g > 200 and b > 200:
|
|
83
|
+
return "white"
|
|
84
|
+
return "mix"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class FakeTalksign:
|
|
88
|
+
"""Records every realtime call; each word of the text maps to the clip of the same colour."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, router: respx.MockRouter, clips: dict[str, bytes], delay: float = 0.0) -> None:
|
|
91
|
+
self.texts: list[str] = []
|
|
92
|
+
self.auth: list[str | None] = []
|
|
93
|
+
self.delay = delay
|
|
94
|
+
router.post(BASE + "/v1/speech-to-sign/realtime").mock(side_effect=self._realtime)
|
|
95
|
+
router.get(url__startswith=CDN).mock(
|
|
96
|
+
side_effect=lambda req: httpx.Response(200, content=clips[req.url.path.strip("/").removesuffix(".mp4")])
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
async def _realtime(self, req: httpx.Request) -> httpx.Response:
|
|
100
|
+
body = json.loads(req.content)
|
|
101
|
+
self.texts.append(body["text"])
|
|
102
|
+
self.auth.append(req.headers.get("authorization"))
|
|
103
|
+
await asyncio.sleep(self.delay)
|
|
104
|
+
words = [w.strip(".,!?").lower() for w in body["text"].split()]
|
|
105
|
+
playlist = [{"gloss": w.upper(), "url": f"{CDN}/{w}.mp4?sig=1"} for w in words if w]
|
|
106
|
+
return httpx.Response(
|
|
107
|
+
200, json={"success": True, "data": {"playlist": playlist, "idle": {"url": f"{CDN}/idle.mp4?sig=1"}}}
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@pytest.fixture
|
|
112
|
+
def fake_api(clips):
|
|
113
|
+
with respx.mock(assert_all_called=False) as router: # unmocked hosts raise: nothing leaves the machine
|
|
114
|
+
yield FakeTalksign(router, clips)
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Runs TalksignVideoService inside a real Pipecat pipeline (pipecat.tests.utils.run_test) against a fake API."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from pipecat.frames.frames import (
|
|
7
|
+
CancelFrame,
|
|
8
|
+
InterruptionFrame,
|
|
9
|
+
LLMFullResponseEndFrame,
|
|
10
|
+
LLMFullResponseStartFrame,
|
|
11
|
+
LLMTextFrame,
|
|
12
|
+
OutputImageRawFrame,
|
|
13
|
+
TTSAudioRawFrame,
|
|
14
|
+
TTSStartedFrame,
|
|
15
|
+
TTSStoppedFrame,
|
|
16
|
+
TTSTextFrame,
|
|
17
|
+
)
|
|
18
|
+
from pipecat.tests.utils import SleepFrame, run_test
|
|
19
|
+
|
|
20
|
+
from pipecat_talksign import TalksignVideoService
|
|
21
|
+
|
|
22
|
+
from .conftest import BASE, KEY, H, W, color_of
|
|
23
|
+
|
|
24
|
+
OPTS = {"crossfade_ms": 0}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def make_service(**kw):
|
|
28
|
+
return TalksignVideoService(api_key=KEY, base_url=BASE, width=W, height=H, source_options=OPTS, **kw)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def images(frames):
|
|
32
|
+
out = []
|
|
33
|
+
for f in frames:
|
|
34
|
+
if isinstance(f, OutputImageRawFrame):
|
|
35
|
+
assert f.size == (W, H) and f.format == "RGB" and len(f.image) == W * H * 3
|
|
36
|
+
out.append(np.frombuffer(f.image, dtype=np.uint8).reshape(H, W, 3))
|
|
37
|
+
return out
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def runs(colors):
|
|
41
|
+
return [c for i, c in enumerate(colors) if i == 0 or colors[i - 1] != c]
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def tts_words(*words):
|
|
45
|
+
return [TTSTextFrame(text=w, text_type="word") for w in words]
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def test_signs_tts_text_in_order_and_passes_frames_through(fake_api):
|
|
49
|
+
service = make_service()
|
|
50
|
+
audio = TTSAudioRawFrame(audio=b"\x00\x01" * 160, sample_rate=16000, num_channels=1)
|
|
51
|
+
llm = LLMTextFrame(text="ignored in tts mode")
|
|
52
|
+
sent = [
|
|
53
|
+
TTSStartedFrame(),
|
|
54
|
+
audio,
|
|
55
|
+
llm,
|
|
56
|
+
*tts_words("Red", "blue."),
|
|
57
|
+
*tts_words("Green"),
|
|
58
|
+
TTSStoppedFrame(),
|
|
59
|
+
SleepFrame(sleep=1.5),
|
|
60
|
+
]
|
|
61
|
+
down, _ = await run_test(service, frames_to_send=sent)
|
|
62
|
+
|
|
63
|
+
# text reached Echo in order, sentence by sentence (the TTS stop flushes the partial one)
|
|
64
|
+
assert fake_api.texts == ["Red blue.", "Green"]
|
|
65
|
+
assert all(a == f"Bearer {KEY}" for a in fake_api.auth)
|
|
66
|
+
|
|
67
|
+
# every non-video frame passed through unchanged and in order
|
|
68
|
+
others = [f for f in down if not isinstance(f, OutputImageRawFrame)]
|
|
69
|
+
assert others[1] is audio and others[2] is llm
|
|
70
|
+
assert [type(f).__name__ for f in others] == [
|
|
71
|
+
"TTSStartedFrame",
|
|
72
|
+
"TTSAudioRawFrame",
|
|
73
|
+
"LLMTextFrame",
|
|
74
|
+
"TTSTextFrame",
|
|
75
|
+
"TTSTextFrame",
|
|
76
|
+
"TTSTextFrame",
|
|
77
|
+
"TTSStoppedFrame",
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
imgs = images(down)
|
|
81
|
+
assert len(imgs) >= 30 # ~30 FPS for ~1.5 s
|
|
82
|
+
seq = [c for c in runs([color_of(i) for i in imgs]) if c in ("red", "blue", "green", "black")]
|
|
83
|
+
assert seq.index("red") < seq.index("blue") < seq.index("green")
|
|
84
|
+
assert seq[-1] == "black" # back to the idle loop after the answer
|
|
85
|
+
assert service._source is None # EndFrame closed it
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def test_llm_text_source(fake_api):
|
|
89
|
+
service = make_service(text_source="llm")
|
|
90
|
+
sent = [
|
|
91
|
+
LLMFullResponseStartFrame(),
|
|
92
|
+
LLMTextFrame(text="Blue "),
|
|
93
|
+
LLMTextFrame(text="red"),
|
|
94
|
+
*tts_words("green."),
|
|
95
|
+
LLMFullResponseEndFrame(),
|
|
96
|
+
SleepFrame(sleep=0.6),
|
|
97
|
+
]
|
|
98
|
+
down, _ = await run_test(service, frames_to_send=sent)
|
|
99
|
+
assert fake_api.texts == ["Blue red"]
|
|
100
|
+
assert sum(isinstance(f, TTSTextFrame) for f in down) == 1
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
async def test_interruption_stops_signing_and_returns_to_idle(fake_api):
|
|
104
|
+
service = make_service()
|
|
105
|
+
long = " ".join(["red", "blue"] * 10) + "."
|
|
106
|
+
|
|
107
|
+
sent = [
|
|
108
|
+
*tts_words("green."),
|
|
109
|
+
SleepFrame(sleep=0.5),
|
|
110
|
+
*tts_words(long),
|
|
111
|
+
SleepFrame(sleep=0.5),
|
|
112
|
+
InterruptionFrame(),
|
|
113
|
+
SleepFrame(sleep=0.8),
|
|
114
|
+
]
|
|
115
|
+
down, _ = await run_test(service, frames_to_send=sent)
|
|
116
|
+
|
|
117
|
+
assert fake_api.texts[0] == "green."
|
|
118
|
+
assert len(fake_api.texts) == 2
|
|
119
|
+
idx = next(i for i, f in enumerate(down) if isinstance(f, InterruptionFrame))
|
|
120
|
+
before = runs([color_of(i) for i in images(down[:idx])])
|
|
121
|
+
after = [color_of(i) for i in images(down[idx:])]
|
|
122
|
+
assert "red" in before or "blue" in before # was signing the long answer
|
|
123
|
+
# 20 words x 6 frames would take ~4 s; after the interruption only idle frames follow
|
|
124
|
+
assert after[-10:] == ["black"] * 10
|
|
125
|
+
assert after.count("red") + after.count("blue") <= 6
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
async def test_cancel_frame_shuts_down_cleanly(fake_api):
|
|
129
|
+
service = make_service()
|
|
130
|
+
sent = [*tts_words("red."), SleepFrame(sleep=0.4), CancelFrame()]
|
|
131
|
+
down, _ = await run_test(service, frames_to_send=sent, send_end_frame=False)
|
|
132
|
+
assert any(isinstance(f, OutputImageRawFrame) for f in down)
|
|
133
|
+
assert service._source is None and service._video_task is None and service._client is None
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
async def test_external_client_is_not_closed(fake_api):
|
|
137
|
+
from talksign import AsyncTalksign
|
|
138
|
+
|
|
139
|
+
async with AsyncTalksign(api_key=KEY, base_url=BASE) as client:
|
|
140
|
+
service = TalksignVideoService(client=client, width=W, height=H, source_options=OPTS)
|
|
141
|
+
await run_test(service, frames_to_send=[*tts_words("blue."), SleepFrame(sleep=0.3)])
|
|
142
|
+
assert service._client is client
|
|
143
|
+
assert fake_api.texts == ["blue."]
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
def test_bad_text_source():
|
|
147
|
+
import pytest
|
|
148
|
+
|
|
149
|
+
with pytest.raises(ValueError):
|
|
150
|
+
TalksignVideoService(api_key=KEY, text_source="audio") # type: ignore[arg-type]
|