pipecat-alkove 0.2.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_alkove-0.2.0/.gitignore +3 -0
- pipecat_alkove-0.2.0/LICENSE +202 -0
- pipecat_alkove-0.2.0/NOTICE +27 -0
- pipecat_alkove-0.2.0/PKG-INFO +56 -0
- pipecat_alkove-0.2.0/README.md +37 -0
- pipecat_alkove-0.2.0/example.py +41 -0
- pipecat_alkove-0.2.0/pipecat_alkove/__init__.py +10 -0
- pipecat_alkove-0.2.0/pipecat_alkove/filter.py +55 -0
- pipecat_alkove-0.2.0/pipecat_alkove/models.py +16 -0
- pipecat_alkove-0.2.0/pipecat_alkove/py.typed +0 -0
- pipecat_alkove-0.2.0/pipecat_alkove/vad.py +39 -0
- pipecat_alkove-0.2.0/pyproject.toml +26 -0
- pipecat_alkove-0.2.0/tests/test_pipecat.py +97 -0
|
@@ -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 [yyyy] [name of copyright owner]
|
|
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,27 @@
|
|
|
1
|
+
Alkove
|
|
2
|
+
Copyright 2026 Eddy Bordi
|
|
3
|
+
|
|
4
|
+
This product includes software developed by third parties:
|
|
5
|
+
|
|
6
|
+
- alkove-focus-1-preview is derived from GTCRN
|
|
7
|
+
(https://github.com/Xiaobin-Rong/gtcrn), under the MIT License:
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2024 Rong Xiaobin
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pipecat-alkove
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Alkove for Pipecat: AlkoveFilter keeps the user's voice, AlkoveVADAnalyzer finds speech, on the bot's CPU
|
|
5
|
+
Project-URL: Homepage, https://alkove.ai
|
|
6
|
+
Project-URL: Repository, https://github.com/alkove-ai/alkove
|
|
7
|
+
Author: Eddy Bordi
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
License-File: NOTICE
|
|
11
|
+
Keywords: noise-cancellation,on-device,pipecat,vad,voice,voice-agent,voice-isolation
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Requires-Dist: alkove<0.3,>=0.2
|
|
16
|
+
Requires-Dist: numpy>=1.21
|
|
17
|
+
Requires-Dist: pipecat-ai<2,>=1.0
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# pipecat-alkove
|
|
21
|
+
|
|
22
|
+
[Alkove](https://alkove.ai) for [Pipecat](https://github.com/pipecat-ai/pipecat): `AlkoveFilter` keeps the user's voice and removes the others and the noise (Focus), `AlkoveVADAnalyzer` finds where they speak (Cue). Both run on the bot's CPU, with no server and no key, with the chain of Alkove's web SDK; where speech starts and ends is Pipecat's `VADParams`.
|
|
23
|
+
|
|
24
|
+
Maintained by Alkove, not by the Pipecat team.
|
|
25
|
+
|
|
26
|
+
## Install
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
pip install pipecat-alkove
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The models (Focus 1.1 MB, Cue 1.1 MB) are downloaded once into the cache and checked by their sha256: the analyzer loads them when it is created, as Silero's does, the filter when the transport starts. Pass `models=alkove.Models.load(["focus", "cue"], dir=...)` to read them from your own folder.
|
|
33
|
+
|
|
34
|
+
## Use
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from pipecat.audio.vad.vad_analyzer import VADParams
|
|
38
|
+
from pipecat.transports.base_transport import TransportParams
|
|
39
|
+
from pipecat_alkove import AlkoveFilter, AlkoveVADAnalyzer
|
|
40
|
+
|
|
41
|
+
params = TransportParams(audio_in_enabled=True, audio_in_filter=AlkoveFilter())
|
|
42
|
+
vad = AlkoveVADAnalyzer() # VADParams(confidence=0.5) unless you pass params
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Give the analyzer to your user aggregator (`LLMUserAggregatorParams(vad_analyzer=vad)`) or to a `VADProcessor`, as you would Silero's.
|
|
46
|
+
|
|
47
|
+
- **`AlkoveFilter`** keeps the closest voice, or with `voiceprint=` the voice of that print; `strength=` and `normalize=` work as in the web SDK. It works at the transport's input rate. `FilterEnableFrame(False)` gives the raw microphone back at the same delay; `FilterUpdateSettingsFrame(settings={"strength": 0.5})` and `{"voiceprint": ...}` change it while it runs. It returns the samples that are ready: a little less than the input at the start (Focus's 16 ms), then about the input's size.
|
|
48
|
+
- **`AlkoveVADAnalyzer`** gives Cue's speech probability every 30 ms, at any input rate. Cue was tuned with a confidence of 0.5, so that is its default. Behind `AlkoveFilter`, it hears only the user.
|
|
49
|
+
|
|
50
|
+
`example.py` runs both on your microphone and prints when you speak.
|
|
51
|
+
|
|
52
|
+
Tested with pipecat-ai 1.13.0.
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
Apache-2.0. See [NOTICE](./NOTICE).
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# pipecat-alkove
|
|
2
|
+
|
|
3
|
+
[Alkove](https://alkove.ai) for [Pipecat](https://github.com/pipecat-ai/pipecat): `AlkoveFilter` keeps the user's voice and removes the others and the noise (Focus), `AlkoveVADAnalyzer` finds where they speak (Cue). Both run on the bot's CPU, with no server and no key, with the chain of Alkove's web SDK; where speech starts and ends is Pipecat's `VADParams`.
|
|
4
|
+
|
|
5
|
+
Maintained by Alkove, not by the Pipecat team.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pip install pipecat-alkove
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The models (Focus 1.1 MB, Cue 1.1 MB) are downloaded once into the cache and checked by their sha256: the analyzer loads them when it is created, as Silero's does, the filter when the transport starts. Pass `models=alkove.Models.load(["focus", "cue"], dir=...)` to read them from your own folder.
|
|
14
|
+
|
|
15
|
+
## Use
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from pipecat.audio.vad.vad_analyzer import VADParams
|
|
19
|
+
from pipecat.transports.base_transport import TransportParams
|
|
20
|
+
from pipecat_alkove import AlkoveFilter, AlkoveVADAnalyzer
|
|
21
|
+
|
|
22
|
+
params = TransportParams(audio_in_enabled=True, audio_in_filter=AlkoveFilter())
|
|
23
|
+
vad = AlkoveVADAnalyzer() # VADParams(confidence=0.5) unless you pass params
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Give the analyzer to your user aggregator (`LLMUserAggregatorParams(vad_analyzer=vad)`) or to a `VADProcessor`, as you would Silero's.
|
|
27
|
+
|
|
28
|
+
- **`AlkoveFilter`** keeps the closest voice, or with `voiceprint=` the voice of that print; `strength=` and `normalize=` work as in the web SDK. It works at the transport's input rate. `FilterEnableFrame(False)` gives the raw microphone back at the same delay; `FilterUpdateSettingsFrame(settings={"strength": 0.5})` and `{"voiceprint": ...}` change it while it runs. It returns the samples that are ready: a little less than the input at the start (Focus's 16 ms), then about the input's size.
|
|
29
|
+
- **`AlkoveVADAnalyzer`** gives Cue's speech probability every 30 ms, at any input rate. Cue was tuned with a confidence of 0.5, so that is its default. Behind `AlkoveFilter`, it hears only the user.
|
|
30
|
+
|
|
31
|
+
`example.py` runs both on your microphone and prints when you speak.
|
|
32
|
+
|
|
33
|
+
Tested with pipecat-ai 1.13.0.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
Apache-2.0. See [NOTICE](./NOTICE).
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Alkove on your microphone with Pipecat: AlkoveFilter keeps your voice, AlkoveVADAnalyzer says when you speak.
|
|
2
|
+
|
|
3
|
+
pip install "pipecat-ai[local]" pipecat-alkove
|
|
4
|
+
python example.py
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import asyncio
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from loguru import logger
|
|
11
|
+
from pipecat.frames.frames import Frame, VADUserStartedSpeakingFrame, VADUserStoppedSpeakingFrame
|
|
12
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
13
|
+
from pipecat.pipeline.worker import PipelineWorker
|
|
14
|
+
from pipecat.processors.audio.vad_processor import VADProcessor
|
|
15
|
+
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
|
|
16
|
+
from pipecat.transports.local.audio import LocalAudioTransport, LocalAudioTransportParams
|
|
17
|
+
from pipecat.workers.runner import WorkerRunner
|
|
18
|
+
|
|
19
|
+
from pipecat_alkove import AlkoveFilter, AlkoveVADAnalyzer
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class SpeechLogger(FrameProcessor):
|
|
23
|
+
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
|
24
|
+
await super().process_frame(frame, direction)
|
|
25
|
+
if isinstance(frame, VADUserStartedSpeakingFrame):
|
|
26
|
+
logger.info("you speak")
|
|
27
|
+
elif isinstance(frame, VADUserStoppedSpeakingFrame):
|
|
28
|
+
logger.info("you stopped")
|
|
29
|
+
await self.push_frame(frame, direction)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
async def main():
|
|
33
|
+
transport = LocalAudioTransport(LocalAudioTransportParams(audio_in_enabled=True, audio_in_filter=AlkoveFilter()))
|
|
34
|
+
pipeline = Pipeline([transport.input(), VADProcessor(vad_analyzer=AlkoveVADAnalyzer()), SpeechLogger()])
|
|
35
|
+
runner = WorkerRunner(handle_sigint=sys.platform != "win32")
|
|
36
|
+
await runner.add_workers(PipelineWorker(pipeline))
|
|
37
|
+
await runner.run()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
if __name__ == "__main__":
|
|
41
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""Alkove for Pipecat: `AlkoveFilter` as the transport's input filter, `AlkoveVADAnalyzer` as the VAD, both on the bot's CPU."""
|
|
2
|
+
|
|
3
|
+
from alkove import Models
|
|
4
|
+
|
|
5
|
+
from .filter import AlkoveFilter
|
|
6
|
+
from .models import models
|
|
7
|
+
from .vad import AlkoveVADAnalyzer
|
|
8
|
+
|
|
9
|
+
__version__ = "0.2.0"
|
|
10
|
+
__all__ = ["AlkoveFilter", "AlkoveVADAnalyzer", "Models", "models", "__version__"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
from typing import Any, Optional
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
from pipecat.audio.filters.base_audio_filter import BaseAudioFilter
|
|
8
|
+
from pipecat.frames.frames import FilterControlFrame, FilterEnableFrame, FilterUpdateSettingsFrame
|
|
9
|
+
|
|
10
|
+
import alkove
|
|
11
|
+
|
|
12
|
+
from .models import models as shared_models
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class AlkoveFilter(BaseAudioFilter):
|
|
16
|
+
"""Alkove Focus as the transport's `audio_in_filter`: keeps the user's voice, the closest one or the voice of a print, and removes the others and the noise."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, *, models: Optional[alkove.Models] = None, voiceprint: Any = None, strength: float = 1.0, normalize: bool = False) -> None:
|
|
19
|
+
self._models = models
|
|
20
|
+
self._voiceprint = voiceprint
|
|
21
|
+
self._strength = strength
|
|
22
|
+
self._normalize = normalize
|
|
23
|
+
self._enabled = True
|
|
24
|
+
self._live: Optional[alkove.Live] = None
|
|
25
|
+
|
|
26
|
+
async def start(self, sample_rate: int) -> None:
|
|
27
|
+
m = self._models or await asyncio.to_thread(shared_models)
|
|
28
|
+
self._live = alkove.Live(m, sample_rate, normalize=self._normalize, strength=self._strength, voiceprint=self._voiceprint)
|
|
29
|
+
self._live.set_enabled(self._enabled)
|
|
30
|
+
|
|
31
|
+
async def stop(self) -> None:
|
|
32
|
+
self._live = None
|
|
33
|
+
|
|
34
|
+
# FilterUpdateSettingsFrame: `strength` (0 to 1) and `voiceprint` (192 numbers, or None)
|
|
35
|
+
async def process_frame(self, frame: FilterControlFrame) -> None:
|
|
36
|
+
if isinstance(frame, FilterEnableFrame):
|
|
37
|
+
self._enabled = frame.enable
|
|
38
|
+
if self._live is not None:
|
|
39
|
+
self._live.set_enabled(frame.enable)
|
|
40
|
+
elif isinstance(frame, FilterUpdateSettingsFrame):
|
|
41
|
+
if "strength" in frame.settings:
|
|
42
|
+
self._strength = float(frame.settings["strength"])
|
|
43
|
+
if self._live is not None:
|
|
44
|
+
self._live.set_strength(self._strength)
|
|
45
|
+
if "voiceprint" in frame.settings:
|
|
46
|
+
self._voiceprint = frame.settings["voiceprint"]
|
|
47
|
+
if self._live is not None:
|
|
48
|
+
self._live.set_voiceprint(self._voiceprint)
|
|
49
|
+
|
|
50
|
+
# the samples that are ready, b"" while the first hop fills; disabled, the raw mic at the same delay
|
|
51
|
+
async def filter(self, audio: bytes) -> bytes:
|
|
52
|
+
if self._live is None:
|
|
53
|
+
return audio
|
|
54
|
+
out, _ = self._live.push(np.frombuffer(audio, dtype=np.int16))
|
|
55
|
+
return alkove.to_int16(out).tobytes()
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
import alkove
|
|
5
|
+
|
|
6
|
+
_lock = threading.Lock()
|
|
7
|
+
_models: Optional[alkove.Models] = None
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def models(*, download: bool = True) -> alkove.Models:
|
|
11
|
+
"""Focus and Cue, loaded once for the process and shared by every session: downloaded once into the cache, checked by their sha256; `download=False` on the event loop."""
|
|
12
|
+
global _models
|
|
13
|
+
with _lock:
|
|
14
|
+
if _models is None:
|
|
15
|
+
_models = alkove.Models.load(["focus", "cue"], download=download)
|
|
16
|
+
return _models
|
|
File without changes
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from pipecat.audio.vad.vad_analyzer import VADAnalyzer, VADParams
|
|
7
|
+
|
|
8
|
+
import alkove
|
|
9
|
+
|
|
10
|
+
from .models import models as shared_models
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AlkoveVADAnalyzer(VADAnalyzer):
|
|
14
|
+
"""Alkove Cue as Pipecat's VAD: a speech probability every 30 ms, at any input rate; behind `AlkoveFilter` it hears only the user."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, *, sample_rate: Optional[int] = None, params: Optional[VADParams] = None, models: Optional[alkove.Models] = None) -> None:
|
|
17
|
+
# Cue was tuned at 0.5; Pipecat's default of 0.7 misses quiet speech
|
|
18
|
+
super().__init__(sample_rate=sample_rate, params=params or VADParams(confidence=0.5))
|
|
19
|
+
# loaded here, as Silero's analyzer does, rather than when the transport sets the rate on the event loop
|
|
20
|
+
self._models = models or shared_models()
|
|
21
|
+
self._processor: Optional[alkove.Processor] = None
|
|
22
|
+
self._last = 0.0
|
|
23
|
+
|
|
24
|
+
def set_sample_rate(self, sample_rate: int) -> None:
|
|
25
|
+
super().set_sample_rate(sample_rate)
|
|
26
|
+
self._processor = alkove.Processor(self._models, cue=True, trace=True, rate=self.sample_rate)
|
|
27
|
+
self._last = 0.0
|
|
28
|
+
|
|
29
|
+
def num_frames_required(self) -> int:
|
|
30
|
+
return round(0.03 * self.sample_rate)
|
|
31
|
+
|
|
32
|
+
# Cue answers one window late: the latest probability it gave
|
|
33
|
+
def voice_confidence(self, buffer: bytes) -> float:
|
|
34
|
+
if self._processor is None:
|
|
35
|
+
return 0.0
|
|
36
|
+
part = self._processor.push(np.frombuffer(buffer, dtype=np.int16))
|
|
37
|
+
if part.trace and part.trace["cue"]:
|
|
38
|
+
self._last = part.trace["cue"][-1]["speech"]
|
|
39
|
+
return self._last
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pipecat-alkove"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Alkove for Pipecat: AlkoveFilter keeps the user's voice, AlkoveVADAnalyzer finds speech, on the bot's CPU"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
authors = [{ name = "Eddy Bordi" }]
|
|
14
|
+
keywords = ["voice", "pipecat", "noise-cancellation", "voice-isolation", "vad", "voice-agent", "on-device"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
18
|
+
]
|
|
19
|
+
dependencies = ["alkove>=0.2,<0.3", "pipecat-ai>=1.0,<2", "numpy>=1.21"]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://alkove.ai"
|
|
23
|
+
Repository = "https://github.com/alkove-ai/alkove"
|
|
24
|
+
|
|
25
|
+
[tool.hatch.version]
|
|
26
|
+
path = "pipecat_alkove/__init__.py"
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""The integration against the Pipecat classes it plugs into, on the SDK's test files."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import wave
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import pytest
|
|
9
|
+
from pipecat.audio.vad.vad_analyzer import VADState
|
|
10
|
+
from pipecat.frames.frames import FilterEnableFrame, FilterUpdateSettingsFrame
|
|
11
|
+
|
|
12
|
+
import alkove
|
|
13
|
+
from pipecat_alkove import AlkoveFilter, AlkoveVADAnalyzer
|
|
14
|
+
|
|
15
|
+
ROOT = Path(__file__).resolve().parents[3]
|
|
16
|
+
FIXTURES = ROOT / "packages/alkove/test/fixtures"
|
|
17
|
+
MODELS = ROOT / "packages/alkove/.cache/models"
|
|
18
|
+
|
|
19
|
+
pytestmark = pytest.mark.skipif(not (MODELS / "alkove-focus-1-preview.alk").exists(), reason="the models are not in packages/alkove/.cache/models")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.fixture(scope="module")
|
|
23
|
+
def models():
|
|
24
|
+
return alkove.Models.load(["focus", "cue"], dir=MODELS)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def wav(name, rate=16000):
|
|
28
|
+
with wave.open(str(FIXTURES / name)) as w:
|
|
29
|
+
pcm = np.frombuffer(w.readframes(w.getnframes()), dtype="<i2").astype(np.float32) / 32768
|
|
30
|
+
return alkove.to_int16(alkove.resample(pcm, 16000, rate))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def chunks(pcm, n):
|
|
34
|
+
return [pcm[i : i + n].tobytes() for i in range(0, len(pcm), n)]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_filter_is_alkove_live_on_the_transport_audio(models):
|
|
38
|
+
async def go():
|
|
39
|
+
f = AlkoveFilter(models=models)
|
|
40
|
+
await f.start(24000)
|
|
41
|
+
pcm = wav("mix.wav", 24000)
|
|
42
|
+
out = [await f.filter(c) for c in chunks(pcm, 480)]
|
|
43
|
+
live = alkove.Live(models, 24000)
|
|
44
|
+
want = [alkove.to_int16(live.push(np.frombuffer(c, np.int16))[0]).tobytes() for c in chunks(pcm, 480)]
|
|
45
|
+
assert out == want
|
|
46
|
+
got = np.frombuffer(b"".join(out), np.int16)
|
|
47
|
+
assert len(pcm) - 480 < len(got) <= len(pcm)
|
|
48
|
+
assert np.abs(got.astype(np.int32) - pcm[: len(got)]).max() > 1000
|
|
49
|
+
await f.stop()
|
|
50
|
+
assert await f.filter(b"\x01\x00") == b"\x01\x00"
|
|
51
|
+
|
|
52
|
+
asyncio.run(go())
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_filter_control_frames(models):
|
|
56
|
+
async def go():
|
|
57
|
+
pcm = wav("mix.wav")
|
|
58
|
+
f = AlkoveFilter(models=models)
|
|
59
|
+
await f.start(16000)
|
|
60
|
+
await f.process_frame(FilterEnableFrame(enable=False))
|
|
61
|
+
off = np.frombuffer(b"".join([await f.filter(c) for c in chunks(pcm, 320)]), np.int16)
|
|
62
|
+
# disabled: the raw mic, Focus's 256 samples late
|
|
63
|
+
assert np.abs(off[4000:].astype(np.int32) - pcm[4000 - 256 : len(off) - 256]).max() <= 1
|
|
64
|
+
g = AlkoveFilter(models=models)
|
|
65
|
+
await g.start(16000)
|
|
66
|
+
await g.process_frame(FilterUpdateSettingsFrame(settings={"strength": 0}))
|
|
67
|
+
raw = np.frombuffer(b"".join([await g.filter(c) for c in chunks(pcm, 320)]), np.int16)
|
|
68
|
+
assert np.abs(raw[4000:].astype(np.int32) - pcm[4000 - 256 : len(raw) - 256]).max() <= 1
|
|
69
|
+
|
|
70
|
+
asyncio.run(go())
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@pytest.mark.parametrize("rate", [16000, 48000])
|
|
74
|
+
def test_vad_hears_speech_then_quiet(models, rate):
|
|
75
|
+
async def go():
|
|
76
|
+
vad = AlkoveVADAnalyzer(models=models)
|
|
77
|
+
vad.set_sample_rate(rate)
|
|
78
|
+
assert vad.num_frames_required() == rate * 3 // 100
|
|
79
|
+
pcm = np.concatenate([wav("speech.wav", rate), np.zeros(rate, np.int16)])
|
|
80
|
+
states = [await vad.analyze_audio(c) for c in chunks(pcm, rate // 50)]
|
|
81
|
+
# speech.wav's voice is clear from 1.26 s; SPEAKING after start_secs (0.2 s)
|
|
82
|
+
first = states.index(VADState.SPEAKING)
|
|
83
|
+
assert 1.3 < first / 50 < 1.7
|
|
84
|
+
assert states[-1] == VADState.QUIET
|
|
85
|
+
await vad.cleanup()
|
|
86
|
+
|
|
87
|
+
asyncio.run(go())
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_vad_confidence_is_cues_probability(models):
|
|
91
|
+
vad = AlkoveVADAnalyzer(models=models)
|
|
92
|
+
vad.set_sample_rate(16000)
|
|
93
|
+
pcm = wav("speech.wav")
|
|
94
|
+
got = [vad.voice_confidence(c) for c in chunks(pcm, 480)]
|
|
95
|
+
p = alkove.Processor(models, cue=True, trace=True)
|
|
96
|
+
want = [r["speech"] for c in chunks(pcm, 480) for r in (p.push(np.frombuffer(c, np.int16)).trace or {"cue": []})["cue"]]
|
|
97
|
+
assert got[1 : len(want) + 1] == want
|