livekit-streaming-tts 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.
- livekit_streaming_tts-0.1.0/LICENSE +201 -0
- livekit_streaming_tts-0.1.0/PKG-INFO +308 -0
- livekit_streaming_tts-0.1.0/README.md +244 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/__init__.py +28 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/audio.py +101 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/base.py +221 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/__init__.py +8 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/bark.py +46 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/kitten.py +56 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/kokoro.py +72 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/omnivoice.py +95 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/piper.py +53 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/pocket.py +114 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/engines/xtts.py +117 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/normalize.py +203 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/plugin.py +517 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/registry.py +86 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts/server.py +568 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts.egg-info/PKG-INFO +308 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts.egg-info/SOURCES.txt +23 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts.egg-info/dependency_links.txt +1 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts.egg-info/requires.txt +51 -0
- livekit_streaming_tts-0.1.0/livekit_streaming_tts.egg-info/top_level.txt +1 -0
- livekit_streaming_tts-0.1.0/pyproject.toml +70 -0
- livekit_streaming_tts-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Thanush
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: livekit-streaming-tts
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Engine-agnostic, low-latency TTS plugin for LiveKit agents. Pluggable backends: OmniVoice, Pocket TTS, Kokoro, KittenTTS, XTTS, Piper, Bark.
|
|
5
|
+
Author: Thanush
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Thanush101/livekit-streaming-tts
|
|
8
|
+
Project-URL: Issues, https://github.com/Thanush101/livekit-streaming-tts/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/Thanush101/livekit-streaming-tts#readme
|
|
10
|
+
Keywords: livekit,tts,voice,streaming,websocket,speech-synthesis
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.24
|
|
23
|
+
Requires-Dist: fastapi>=0.110
|
|
24
|
+
Requires-Dist: uvicorn[standard]>=0.27
|
|
25
|
+
Requires-Dist: aiohttp>=3.9
|
|
26
|
+
Requires-Dist: pydantic>=2.0
|
|
27
|
+
Requires-Dist: inflect>=7.0
|
|
28
|
+
Requires-Dist: livekit-agents>=0.10
|
|
29
|
+
Requires-Dist: python-multipart>=0.0.6
|
|
30
|
+
Provides-Extra: hq-resample
|
|
31
|
+
Requires-Dist: soxr>=0.3; extra == "hq-resample"
|
|
32
|
+
Provides-Extra: omnivoice
|
|
33
|
+
Requires-Dist: torch>=2.1; extra == "omnivoice"
|
|
34
|
+
Requires-Dist: soundfile>=0.12; extra == "omnivoice"
|
|
35
|
+
Provides-Extra: pocket
|
|
36
|
+
Requires-Dist: torch>=2.1; extra == "pocket"
|
|
37
|
+
Provides-Extra: kokoro
|
|
38
|
+
Requires-Dist: kokoro>=0.7; extra == "kokoro"
|
|
39
|
+
Requires-Dist: torch>=2.1; extra == "kokoro"
|
|
40
|
+
Provides-Extra: kitten
|
|
41
|
+
Requires-Dist: kittentts>=0.1; extra == "kitten"
|
|
42
|
+
Provides-Extra: xtts
|
|
43
|
+
Requires-Dist: TTS>=0.22; extra == "xtts"
|
|
44
|
+
Requires-Dist: torch>=2.1; extra == "xtts"
|
|
45
|
+
Provides-Extra: piper
|
|
46
|
+
Requires-Dist: piper-tts>=1.2; extra == "piper"
|
|
47
|
+
Provides-Extra: bark
|
|
48
|
+
Requires-Dist: bark>=0.1; extra == "bark"
|
|
49
|
+
Requires-Dist: torch>=2.1; extra == "bark"
|
|
50
|
+
Provides-Extra: all
|
|
51
|
+
Requires-Dist: torch>=2.1; extra == "all"
|
|
52
|
+
Requires-Dist: soundfile>=0.12; extra == "all"
|
|
53
|
+
Requires-Dist: kokoro>=0.7; extra == "all"
|
|
54
|
+
Requires-Dist: kittentts>=0.1; extra == "all"
|
|
55
|
+
Requires-Dist: TTS>=0.22; extra == "all"
|
|
56
|
+
Requires-Dist: piper-tts>=1.2; extra == "all"
|
|
57
|
+
Requires-Dist: bark>=0.1; extra == "all"
|
|
58
|
+
Requires-Dist: soxr>=0.3; extra == "all"
|
|
59
|
+
Provides-Extra: dev
|
|
60
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
61
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
62
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
63
|
+
Dynamic: license-file
|
|
64
|
+
|
|
65
|
+
# livekit-streaming-tts
|
|
66
|
+
|
|
67
|
+
Engine-agnostic, low-latency, self-hosted TTS for LiveKit voice agents. One WebSocket protocol, one client plugin, swappable backends — write your agent once, switch from OmniVoice to Pocket TTS to Kokoro by changing one env var.
|
|
68
|
+
|
|
69
|
+
## Why this exists
|
|
70
|
+
|
|
71
|
+
Most LiveKit TTS plugins are tightly coupled to one provider — change the model and you rewrite the plugin, redo latency tuning, and rediscover the same edge cases (idle-closed sockets, half-words from the LLM, no barge-in support, etc.). This package factors out the parts that are the same for every TTS:
|
|
72
|
+
|
|
73
|
+
- A LiveKit `tts.TTS` plugin with pooled WebSockets, sentence-aware streaming, and barge-in.
|
|
74
|
+
- A FastAPI server that does text normalization, sentence chunking, voice caching, and audio encoding (PCM/WAV, any sample rate).
|
|
75
|
+
- A small `TTSEngine` ABC — the only thing each backend implements.
|
|
76
|
+
|
|
77
|
+
## Supported engines
|
|
78
|
+
|
|
79
|
+
| Engine | Voice cloning | Streaming gen | Multilingual | Speed | Footprint |
|
|
80
|
+
|------------|---------------|---------------|--------------|-------|--------------|
|
|
81
|
+
| OmniVoice | yes | no | yes | yes | GPU, ~3GB |
|
|
82
|
+
| Pocket TTS | yes (kvcache) | no | en | no | GPU, ~1GB |
|
|
83
|
+
| Kokoro | no (presets) | no | en/ja/zh | yes | GPU, ~330MB |
|
|
84
|
+
| KittenTTS | no (presets) | no | en | no | CPU, ~50MB |
|
|
85
|
+
| XTTS v2 | yes (zero-shot)| yes | 16 langs | yes | GPU, ~2GB |
|
|
86
|
+
| Piper | no (per-file) | no | many | yes | CPU, ~30MB |
|
|
87
|
+
| Bark | no (presets) | no | yes | no | GPU, ~5GB |
|
|
88
|
+
|
|
89
|
+
## Topology
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
┌────────────────────────────┐ ┌────────────────────────────┐
|
|
93
|
+
│ CLIENT host (CPU) │ WS │ SERVER host (GPU) │
|
|
94
|
+
│ - LiveKit agent │ ◄─────────────►│ - FastAPI + uvicorn │
|
|
95
|
+
│ - StreamingTTS plugin │ │ - TTSEngine (pocket / │
|
|
96
|
+
│ - microphone, speaker │ │ omnivoice / kokoro / …) │
|
|
97
|
+
└────────────────────────────┘ └────────────────────────────┘
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The **same `pip install`** ships both halves:
|
|
101
|
+
- the **server** entrypoint (`create_app`, `examples/run_server.py`)
|
|
102
|
+
- the **client** plugin (`StreamingTTS` — drop into a LiveKit agent)
|
|
103
|
+
|
|
104
|
+
You install the package on the server with the engine extra you want, and on
|
|
105
|
+
the client with no extra (it doesn't need torch / engine deps — only
|
|
106
|
+
`aiohttp` + `livekit-agents`).
|
|
107
|
+
|
|
108
|
+
## Install
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
git clone https://github.com/<you>/livekit-streaming-tts
|
|
112
|
+
cd livekit-streaming-tts
|
|
113
|
+
|
|
114
|
+
# --- server host (GPU box, where the model runs) ---
|
|
115
|
+
pip install -e .[pocket] # or [omnivoice], [kokoro], [xtts] ...
|
|
116
|
+
pip install -e .[kitten] # CPU-only, no GPU needed
|
|
117
|
+
|
|
118
|
+
# --- client host (where your LiveKit agent runs) ---
|
|
119
|
+
pip install -e . # no extras — just the plugin & deps
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Once published to PyPI, those become `pip install livekit-streaming-tts[pocket]`
|
|
123
|
+
on the server and `pip install livekit-streaming-tts` on the client.
|
|
124
|
+
|
|
125
|
+
## Run the server
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
TTS_ENGINE=pocket TTS_PORT=8001 python examples/run_server.py
|
|
129
|
+
TTS_ENGINE=omnivoice TTS_PORT=8001 python examples/run_server.py
|
|
130
|
+
TTS_ENGINE=kitten TTS_PORT=8001 python examples/run_server.py
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
The engine is loaded lazily — only the deps you `pip install`'d are imported.
|
|
134
|
+
|
|
135
|
+
Verify it's up:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
curl http://localhost:8001/health
|
|
139
|
+
# {"status":"ok","engine":"pocket","capabilities":{...},"voices":[...]}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Connect from the client
|
|
143
|
+
|
|
144
|
+
Two supported clients:
|
|
145
|
+
|
|
146
|
+
### 1) LiveKit agent (the main use case)
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from livekit.agents import Agent, AgentSession, WorkerOptions, cli
|
|
150
|
+
from livekit.plugins import openai, silero
|
|
151
|
+
from livekit_streaming_tts import StreamingTTS
|
|
152
|
+
|
|
153
|
+
tts = StreamingTTS(
|
|
154
|
+
ws_url="ws://your-server:8001/tts/ws",
|
|
155
|
+
voice="alba",
|
|
156
|
+
sample_rate=24000, # 8000 for telephony
|
|
157
|
+
format="pcm",
|
|
158
|
+
binary=True,
|
|
159
|
+
)
|
|
160
|
+
tts.prewarm()
|
|
161
|
+
|
|
162
|
+
session = AgentSession(
|
|
163
|
+
vad=silero.VAD.load(),
|
|
164
|
+
stt=openai.STT(),
|
|
165
|
+
llm=openai.LLM(model="gpt-4o-mini"),
|
|
166
|
+
tts=tts, # ← that's the entire integration
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
That's the whole client side. The plugin handles WS pooling, sentence
|
|
171
|
+
tokenization, retries, and barge-in.
|
|
172
|
+
|
|
173
|
+
See `examples/livekit_agent.py` for a runnable version.
|
|
174
|
+
|
|
175
|
+
### 2) Raw WebSocket (non-LiveKit integrations)
|
|
176
|
+
|
|
177
|
+
If you're building a telephony bridge, a CLI, or any non-LiveKit pipeline,
|
|
178
|
+
you can speak the WS protocol directly. See `examples/raw_ws_client.py`:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
python examples/raw_ws_client.py "Hello from the streaming TTS server."
|
|
182
|
+
# wrote 96000 bytes of PCM → output.wav
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The protocol is documented inline in that file and in `server.py`.
|
|
186
|
+
|
|
187
|
+
## Use in a LiveKit agent
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
from livekit_streaming_tts import StreamingTTS
|
|
191
|
+
|
|
192
|
+
tts = StreamingTTS(
|
|
193
|
+
ws_url="ws://your-tts-host:8001/tts/ws",
|
|
194
|
+
voice="alba", # any registered voice / preset / engine default
|
|
195
|
+
sample_rate=24000, # 8000 for telephony — see below
|
|
196
|
+
format="pcm", # "pcm" recommended; "wav" if you need a header
|
|
197
|
+
binary=True, # binary WS frames for PCM (~33% bandwidth saved)
|
|
198
|
+
)
|
|
199
|
+
tts.prewarm() # opens one WS so the first turn is fast
|
|
200
|
+
|
|
201
|
+
session = AgentSession(stt=..., llm=..., tts=tts, vad=...)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## PCM vs WAV — which should you use?
|
|
205
|
+
|
|
206
|
+
**Use PCM with binary frames.** Three reasons:
|
|
207
|
+
|
|
208
|
+
1. **Smaller wire size.** WAV adds a 44-byte RIFF header per chunk (small) plus base64 inflates payload by 33% (significant on long replies). PCM-binary skips both.
|
|
209
|
+
2. **No decode step on the client.** The PCM bytes go straight into LiveKit's `AudioEmitter`. WAV-base64 requires `base64.b64decode` + WAV parse on every chunk.
|
|
210
|
+
3. **Quality is identical.** PCM and WAV are the same int16 samples — WAV just wraps them in a header. There is no quality difference.
|
|
211
|
+
|
|
212
|
+
When to use WAV: only if you're consuming the bytes outside a streaming pipeline (saving to disk, posting to an HTTP endpoint that wants a file format).
|
|
213
|
+
|
|
214
|
+
## Telephony
|
|
215
|
+
|
|
216
|
+
PSTN/SIP is 8kHz μ-law or A-law. LiveKit's SIP integration accepts 8kHz/16kHz PCM and handles G.711 conversion. For lowest latency on phone calls:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
StreamingTTS(sample_rate=8000, format="pcm", binary=True)
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
This makes the server resample once (engine native → 8kHz) and ship 1/3 the bytes vs 24kHz. Install `soxr` for higher-quality resampling:
|
|
223
|
+
|
|
224
|
+
```bash
|
|
225
|
+
pip install livekit-streaming-tts[hq-resample]
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
## Voice cloning
|
|
229
|
+
|
|
230
|
+
Engines that support it: **OmniVoice**, **Pocket TTS**, **XTTS v2**.
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
# Upload a reference clip and register under a voice_id
|
|
234
|
+
curl -F "file=@my-voice.wav" \
|
|
235
|
+
-F "voice_id=alice" \
|
|
236
|
+
-F "ref_text=transcript of the clip" \
|
|
237
|
+
http://your-tts-host:8001/v1/voices/upload
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Then pass `voice="alice"` to `StreamingTTS`. The server caches the prompt — subsequent generations are fast.
|
|
241
|
+
|
|
242
|
+
Pocket TTS bonus: voice prompts are exported to safetensors (kvcache). On restart the server reloads voices from disk in milliseconds instead of recomputing.
|
|
243
|
+
|
|
244
|
+
## Adding a new engine
|
|
245
|
+
|
|
246
|
+
```python
|
|
247
|
+
# my_engine.py
|
|
248
|
+
from livekit_streaming_tts.base import TTSEngine, GenerationParams, AudioChunk, EngineCapabilities
|
|
249
|
+
import numpy as np
|
|
250
|
+
|
|
251
|
+
class MyEngine(TTSEngine):
|
|
252
|
+
name = "myengine"
|
|
253
|
+
native_sample_rate = 22050
|
|
254
|
+
capabilities = EngineCapabilities(voice_cloning=False, multilingual=False)
|
|
255
|
+
|
|
256
|
+
def __init__(self):
|
|
257
|
+
# Load your model here.
|
|
258
|
+
...
|
|
259
|
+
|
|
260
|
+
def generate(self, params: GenerationParams) -> AudioChunk:
|
|
261
|
+
# Your synthesis logic. Return float32 in [-1, 1].
|
|
262
|
+
samples = self._model.synth(params.text)
|
|
263
|
+
return AudioChunk(samples=samples.astype(np.float32),
|
|
264
|
+
sample_rate=self.native_sample_rate, is_final=True)
|
|
265
|
+
|
|
266
|
+
# Register at runtime:
|
|
267
|
+
from livekit_streaming_tts import register_engine
|
|
268
|
+
register_engine("myengine", MyEngine)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
That's it. Sentence chunking, normalization, voice caching, WS protocol, audio encoding, the LiveKit plugin — all reused.
|
|
272
|
+
|
|
273
|
+
## Architecture
|
|
274
|
+
|
|
275
|
+
```
|
|
276
|
+
LLM tokens (sub-word frags)
|
|
277
|
+
│
|
|
278
|
+
│ via livekit input_ch
|
|
279
|
+
▼
|
|
280
|
+
SentenceTokenizer (joins frags → words) ← client side
|
|
281
|
+
│
|
|
282
|
+
▼
|
|
283
|
+
Pooled WebSocket (max 30s session) ← client side
|
|
284
|
+
│
|
|
285
|
+
│ {"type":"text","data":{"text":"word "}}
|
|
286
|
+
▼
|
|
287
|
+
text_buffer + split_sentences (unicode) ← server side
|
|
288
|
+
│
|
|
289
|
+
▼
|
|
290
|
+
normalize_text (numbers, money, units, MD) ← server side, off the GPU thread
|
|
291
|
+
│
|
|
292
|
+
▼
|
|
293
|
+
GPUWorker queue (serialized engine access) ← server side
|
|
294
|
+
│
|
|
295
|
+
▼
|
|
296
|
+
TTSEngine.generate(params) ← swappable backend
|
|
297
|
+
│
|
|
298
|
+
▼
|
|
299
|
+
np.clip + int16 + (optional) resample ← server side
|
|
300
|
+
│
|
|
301
|
+
│ binary PCM frame (or base64 WAV)
|
|
302
|
+
▼
|
|
303
|
+
LiveKit AudioEmitter → WebRTC → user
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## License
|
|
307
|
+
|
|
308
|
+
Apache 2.0.
|