livekit-plugins-cartesia 0.4.10__py3-none-any.whl → 1.0.0__py3-none-any.whl
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/plugins/cartesia/tts.py +46 -39
- livekit/plugins/cartesia/version.py +1 -1
- {livekit_plugins_cartesia-0.4.10.dist-info → livekit_plugins_cartesia-1.0.0.dist-info}/METADATA +10 -20
- livekit_plugins_cartesia-1.0.0.dist-info/RECORD +9 -0
- {livekit_plugins_cartesia-0.4.10.dist-info → livekit_plugins_cartesia-1.0.0.dist-info}/WHEEL +1 -2
- livekit_plugins_cartesia-0.4.10.dist-info/RECORD +0 -10
- livekit_plugins_cartesia-0.4.10.dist-info/top_level.txt +0 -1
livekit/plugins/cartesia/tts.py
CHANGED
@@ -20,9 +20,10 @@ import json
|
|
20
20
|
import os
|
21
21
|
import weakref
|
22
22
|
from dataclasses import dataclass
|
23
|
-
from typing import Any
|
23
|
+
from typing import Any
|
24
24
|
|
25
25
|
import aiohttp
|
26
|
+
|
26
27
|
from livekit.agents import (
|
27
28
|
APIConnectionError,
|
28
29
|
APIConnectOptions,
|
@@ -32,6 +33,12 @@ from livekit.agents import (
|
|
32
33
|
tts,
|
33
34
|
utils,
|
34
35
|
)
|
36
|
+
from livekit.agents.types import (
|
37
|
+
DEFAULT_API_CONNECT_OPTIONS,
|
38
|
+
NOT_GIVEN,
|
39
|
+
NotGivenOr,
|
40
|
+
)
|
41
|
+
from livekit.agents.utils import is_given
|
35
42
|
|
36
43
|
from .log import logger
|
37
44
|
from .models import (
|
@@ -56,8 +63,8 @@ class _TTSOptions:
|
|
56
63
|
encoding: TTSEncoding
|
57
64
|
sample_rate: int
|
58
65
|
voice: str | list[float]
|
59
|
-
speed: TTSVoiceSpeed | float
|
60
|
-
emotion: list[TTSVoiceEmotion | str]
|
66
|
+
speed: NotGivenOr[TTSVoiceSpeed | float]
|
67
|
+
emotion: NotGivenOr[list[TTSVoiceEmotion | str]]
|
61
68
|
api_key: str
|
62
69
|
language: str
|
63
70
|
base_url: str
|
@@ -77,10 +84,10 @@ class TTS(tts.TTS):
|
|
77
84
|
language: str = "en",
|
78
85
|
encoding: TTSEncoding = "pcm_s16le",
|
79
86
|
voice: str | list[float] = TTSDefaultVoiceId,
|
80
|
-
speed: TTSVoiceSpeed | float
|
81
|
-
emotion: list[TTSVoiceEmotion | str]
|
87
|
+
speed: NotGivenOr[TTSVoiceSpeed | float] = NOT_GIVEN,
|
88
|
+
emotion: NotGivenOr[list[TTSVoiceEmotion | str]] = NOT_GIVEN,
|
82
89
|
sample_rate: int = 24000,
|
83
|
-
api_key: str
|
90
|
+
api_key: NotGivenOr[str] = NOT_GIVEN,
|
84
91
|
http_session: aiohttp.ClientSession | None = None,
|
85
92
|
base_url: str = "https://api.cartesia.ai",
|
86
93
|
) -> None:
|
@@ -100,16 +107,15 @@ class TTS(tts.TTS):
|
|
100
107
|
api_key (str, optional): The Cartesia API key. If not provided, it will be read from the CARTESIA_API_KEY environment variable.
|
101
108
|
http_session (aiohttp.ClientSession | None, optional): An existing aiohttp ClientSession to use. If not provided, a new session will be created.
|
102
109
|
base_url (str, optional): The base URL for the Cartesia API. Defaults to "https://api.cartesia.ai".
|
103
|
-
"""
|
110
|
+
""" # noqa: E501
|
104
111
|
|
105
112
|
super().__init__(
|
106
113
|
capabilities=tts.TTSCapabilities(streaming=True),
|
107
114
|
sample_rate=sample_rate,
|
108
115
|
num_channels=NUM_CHANNELS,
|
109
116
|
)
|
110
|
-
|
111
|
-
|
112
|
-
if not api_key:
|
117
|
+
cartesia_api_key = api_key if is_given(api_key) else os.environ.get("CARTESIA_API_KEY")
|
118
|
+
if not cartesia_api_key:
|
113
119
|
raise ValueError("CARTESIA_API_KEY must be set")
|
114
120
|
|
115
121
|
self._opts = _TTSOptions(
|
@@ -120,7 +126,7 @@ class TTS(tts.TTS):
|
|
120
126
|
voice=voice,
|
121
127
|
speed=speed,
|
122
128
|
emotion=emotion,
|
123
|
-
api_key=
|
129
|
+
api_key=cartesia_api_key,
|
124
130
|
base_url=base_url,
|
125
131
|
)
|
126
132
|
self._session = http_session
|
@@ -137,9 +143,7 @@ class TTS(tts.TTS):
|
|
137
143
|
url = self._opts.get_ws_url(
|
138
144
|
f"/tts/websocket?api_key={self._opts.api_key}&cartesia_version={API_VERSION}"
|
139
145
|
)
|
140
|
-
return await asyncio.wait_for(
|
141
|
-
session.ws_connect(url), self._conn_options.timeout
|
142
|
-
)
|
146
|
+
return await asyncio.wait_for(session.ws_connect(url), self._conn_options.timeout)
|
143
147
|
|
144
148
|
async def _close_ws(self, ws: aiohttp.ClientWebSocketResponse):
|
145
149
|
await ws.close()
|
@@ -156,11 +160,11 @@ class TTS(tts.TTS):
|
|
156
160
|
def update_options(
|
157
161
|
self,
|
158
162
|
*,
|
159
|
-
model: TTSModels |
|
160
|
-
language: str
|
161
|
-
voice: str | list[float]
|
162
|
-
speed: TTSVoiceSpeed | float
|
163
|
-
emotion: list[TTSVoiceEmotion | str]
|
163
|
+
model: NotGivenOr[TTSModels | str] = NOT_GIVEN,
|
164
|
+
language: NotGivenOr[str] = NOT_GIVEN,
|
165
|
+
voice: NotGivenOr[str | list[float]] = NOT_GIVEN,
|
166
|
+
speed: NotGivenOr[TTSVoiceSpeed | float] = NOT_GIVEN,
|
167
|
+
emotion: NotGivenOr[list[TTSVoiceEmotion | str]] = NOT_GIVEN,
|
164
168
|
) -> None:
|
165
169
|
"""
|
166
170
|
Update the Text-to-Speech (TTS) configuration options.
|
@@ -175,18 +179,22 @@ class TTS(tts.TTS):
|
|
175
179
|
speed (TTSVoiceSpeed | float, optional): Voice Control - Speed (https://docs.cartesia.ai/user-guides/voice-control)
|
176
180
|
emotion (list[TTSVoiceEmotion], optional): Voice Control - Emotion (https://docs.cartesia.ai/user-guides/voice-control)
|
177
181
|
"""
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
if
|
182
|
+
if is_given(model):
|
183
|
+
self._opts.model = model
|
184
|
+
if is_given(language):
|
185
|
+
self._opts.language = language
|
186
|
+
if is_given(voice):
|
187
|
+
self._opts.voice = voice
|
188
|
+
if is_given(speed):
|
189
|
+
self._opts.speed = speed
|
190
|
+
if is_given(emotion):
|
183
191
|
self._opts.emotion = emotion
|
184
192
|
|
185
193
|
def synthesize(
|
186
194
|
self,
|
187
195
|
text: str,
|
188
196
|
*,
|
189
|
-
conn_options:
|
197
|
+
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
190
198
|
) -> ChunkedStream:
|
191
199
|
return ChunkedStream(
|
192
200
|
tts=self,
|
@@ -197,15 +205,13 @@ class TTS(tts.TTS):
|
|
197
205
|
)
|
198
206
|
|
199
207
|
def stream(
|
200
|
-
self, *, conn_options:
|
201
|
-
) ->
|
202
|
-
|
208
|
+
self, *, conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS
|
209
|
+
) -> SynthesizeStream:
|
210
|
+
return SynthesizeStream(
|
203
211
|
tts=self,
|
204
212
|
pool=self._pool,
|
205
213
|
opts=self._opts,
|
206
214
|
)
|
207
|
-
self._streams.add(stream)
|
208
|
-
return stream
|
209
215
|
|
210
216
|
async def aclose(self) -> None:
|
211
217
|
for stream in list(self._streams):
|
@@ -225,7 +231,7 @@ class ChunkedStream(tts.ChunkedStream):
|
|
225
231
|
input_text: str,
|
226
232
|
opts: _TTSOptions,
|
227
233
|
session: aiohttp.ClientSession,
|
228
|
-
conn_options:
|
234
|
+
conn_options: APIConnectOptions,
|
229
235
|
) -> None:
|
230
236
|
super().__init__(tts=tts, input_text=input_text, conn_options=conn_options)
|
231
237
|
self._opts, self._session = opts, session
|
@@ -379,17 +385,18 @@ class SynthesizeStream(tts.SynthesizeStream):
|
|
379
385
|
|
380
386
|
def _to_cartesia_options(opts: _TTSOptions) -> dict[str, Any]:
|
381
387
|
voice: dict[str, Any] = {}
|
382
|
-
if
|
383
|
-
voice
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
+
if is_given(opts.voice):
|
389
|
+
if isinstance(opts.voice, str):
|
390
|
+
voice["mode"] = "id"
|
391
|
+
voice["id"] = opts.voice
|
392
|
+
else:
|
393
|
+
voice["mode"] = "embedding"
|
394
|
+
voice["embedding"] = opts.voice
|
388
395
|
|
389
396
|
voice_controls: dict = {}
|
390
|
-
if opts.speed
|
397
|
+
if is_given(opts.speed):
|
391
398
|
voice_controls["speed"] = opts.speed
|
392
|
-
if opts.emotion
|
399
|
+
if is_given(opts.emotion):
|
393
400
|
voice_controls["emotion"] = opts.emotion
|
394
401
|
|
395
402
|
if voice_controls:
|
{livekit_plugins_cartesia-0.4.10.dist-info → livekit_plugins_cartesia-1.0.0.dist-info}/METADATA
RENAMED
@@ -1,35 +1,25 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: livekit-plugins-cartesia
|
3
|
-
Version: 0.
|
3
|
+
Version: 1.0.0
|
4
4
|
Summary: LiveKit Agents Plugin for Cartesia
|
5
|
-
Home-page: https://github.com/livekit/agents
|
6
|
-
License: Apache-2.0
|
7
5
|
Project-URL: Documentation, https://docs.livekit.io
|
8
6
|
Project-URL: Website, https://livekit.io/
|
9
7
|
Project-URL: Source, https://github.com/livekit/agents
|
10
|
-
|
8
|
+
Author-email: LiveKit <hello@livekit.io>
|
9
|
+
License-Expression: Apache-2.0
|
10
|
+
Keywords: audio,livekit,realtime,video,webrtc
|
11
11
|
Classifier: Intended Audience :: Developers
|
12
12
|
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
-
Classifier: Topic :: Multimedia :: Sound/Audio
|
14
|
-
Classifier: Topic :: Multimedia :: Video
|
15
|
-
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
16
13
|
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
17
15
|
Classifier: Programming Language :: Python :: 3.9
|
18
16
|
Classifier: Programming Language :: Python :: 3.10
|
19
|
-
Classifier:
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
18
|
+
Classifier: Topic :: Multimedia :: Video
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
20
20
|
Requires-Python: >=3.9.0
|
21
|
+
Requires-Dist: livekit-agents>=1.0.0
|
21
22
|
Description-Content-Type: text/markdown
|
22
|
-
Requires-Dist: livekit-agents<1.0.0,>=0.12.16
|
23
|
-
Dynamic: classifier
|
24
|
-
Dynamic: description
|
25
|
-
Dynamic: description-content-type
|
26
|
-
Dynamic: home-page
|
27
|
-
Dynamic: keywords
|
28
|
-
Dynamic: license
|
29
|
-
Dynamic: project-url
|
30
|
-
Dynamic: requires-dist
|
31
|
-
Dynamic: requires-python
|
32
|
-
Dynamic: summary
|
33
23
|
|
34
24
|
# LiveKit Plugins Cartesia
|
35
25
|
|
@@ -0,0 +1,9 @@
|
|
1
|
+
livekit/plugins/cartesia/__init__.py,sha256=UTa6Q7IxhRBCwPftowHEUDvmBg99J_UjGS_yxTzKD7g,1095
|
2
|
+
livekit/plugins/cartesia/log.py,sha256=4Mnhjng_DU1dIWP9IWjIQGZ67EV3LnQhWMWCHVudJbo,71
|
3
|
+
livekit/plugins/cartesia/models.py,sha256=KGY-r2luJuUNY6a3nnB0Rx-5Td12hikk-GtYLnqvysE,977
|
4
|
+
livekit/plugins/cartesia/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
livekit/plugins/cartesia/tts.py,sha256=rHDiypiCdn0sKykNvYcl5Cf6SZE2XmPRlnLGQA4m7Ks,14443
|
6
|
+
livekit/plugins/cartesia/version.py,sha256=nW89L_U9N4ukT3wAO3BeTqOaa87zLUOsEFz8TkiKIP8,600
|
7
|
+
livekit_plugins_cartesia-1.0.0.dist-info/METADATA,sha256=-kXn2tHzxJ812b3gwTOoRfW4UCEKcFWa61gIqHyVsA8,1253
|
8
|
+
livekit_plugins_cartesia-1.0.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
9
|
+
livekit_plugins_cartesia-1.0.0.dist-info/RECORD,,
|
@@ -1,10 +0,0 @@
|
|
1
|
-
livekit/plugins/cartesia/__init__.py,sha256=UTa6Q7IxhRBCwPftowHEUDvmBg99J_UjGS_yxTzKD7g,1095
|
2
|
-
livekit/plugins/cartesia/log.py,sha256=4Mnhjng_DU1dIWP9IWjIQGZ67EV3LnQhWMWCHVudJbo,71
|
3
|
-
livekit/plugins/cartesia/models.py,sha256=KGY-r2luJuUNY6a3nnB0Rx-5Td12hikk-GtYLnqvysE,977
|
4
|
-
livekit/plugins/cartesia/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
livekit/plugins/cartesia/tts.py,sha256=cOoNFXNlw2NFN5o6PgLTccu_-y_W0MTAwNciNDtxdd8,14128
|
6
|
-
livekit/plugins/cartesia/version.py,sha256=EAXwrHdOWRivmdK-RTQl1YBemh0E8ui_JHvG9dT490M,601
|
7
|
-
livekit_plugins_cartesia-0.4.10.dist-info/METADATA,sha256=TXT6xGvQ3of6Gl9PyCCYLrurnkDdfyiOjzyrXC0gga4,1471
|
8
|
-
livekit_plugins_cartesia-0.4.10.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
|
9
|
-
livekit_plugins_cartesia-0.4.10.dist-info/top_level.txt,sha256=OoDok3xUmXbZRvOrfvvXB-Juu4DX79dlq188E19YHoo,8
|
10
|
-
livekit_plugins_cartesia-0.4.10.dist-info/RECORD,,
|
@@ -1 +0,0 @@
|
|
1
|
-
livekit
|