livekit-plugins-lmnt 1.1.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/lmnt/__init__.py +42 -0
- livekit/plugins/lmnt/models.py +27 -0
- livekit/plugins/lmnt/py.typed +0 -0
- livekit/plugins/lmnt/tts.py +255 -0
- livekit/plugins/lmnt/version.py +15 -0
- livekit_plugins_lmnt-1.1.0.dist-info/METADATA +37 -0
- livekit_plugins_lmnt-1.1.0.dist-info/RECORD +8 -0
- livekit_plugins_lmnt-1.1.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,42 @@
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
"""LMNT plugin for LiveKit Agents
|
16
|
+
|
17
|
+
See https://docs.livekit.io/agents/integrations/tts/lmnt/ for more information.
|
18
|
+
"""
|
19
|
+
|
20
|
+
from .tts import TTS, ChunkedStream
|
21
|
+
from .version import __version__
|
22
|
+
|
23
|
+
__all__ = ["TTS", "ChunkedStream", "__version__"]
|
24
|
+
|
25
|
+
from livekit.agents import Plugin
|
26
|
+
|
27
|
+
|
28
|
+
class LMNTPlugin(Plugin):
|
29
|
+
def __init__(self) -> None:
|
30
|
+
super().__init__(__name__, __version__, __package__)
|
31
|
+
|
32
|
+
|
33
|
+
Plugin.register_plugin(LMNTPlugin())
|
34
|
+
|
35
|
+
# Cleanup docs of unexported modules
|
36
|
+
_module = dir()
|
37
|
+
NOT_IN_ALL = [m for m in _module if m not in __all__]
|
38
|
+
|
39
|
+
__pdoc__ = {}
|
40
|
+
|
41
|
+
for n in NOT_IN_ALL:
|
42
|
+
__pdoc__[n] = False
|
@@ -0,0 +1,27 @@
|
|
1
|
+
from typing import Literal
|
2
|
+
|
3
|
+
LMNTAudioFormats = Literal["aac", "mp3", "mulaw", "raw", "wav"]
|
4
|
+
LMNTLanguages = Literal[
|
5
|
+
"auto",
|
6
|
+
"de",
|
7
|
+
"en",
|
8
|
+
"es",
|
9
|
+
"fr",
|
10
|
+
"hi",
|
11
|
+
"id",
|
12
|
+
"it",
|
13
|
+
"ja",
|
14
|
+
"ko",
|
15
|
+
"nl",
|
16
|
+
"pl",
|
17
|
+
"pt",
|
18
|
+
"ru",
|
19
|
+
"sv",
|
20
|
+
"th",
|
21
|
+
"tr",
|
22
|
+
"uk",
|
23
|
+
"vi",
|
24
|
+
"zh",
|
25
|
+
]
|
26
|
+
LMNTModels = Literal["blizzard", "aurora"]
|
27
|
+
LMNTSampleRate = Literal[8000, 16000, 24000]
|
File without changes
|
@@ -0,0 +1,255 @@
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
from __future__ import annotations
|
15
|
+
|
16
|
+
import asyncio
|
17
|
+
import os
|
18
|
+
from dataclasses import dataclass, replace
|
19
|
+
from typing import Final
|
20
|
+
|
21
|
+
import aiohttp
|
22
|
+
|
23
|
+
from livekit.agents import (
|
24
|
+
APIConnectionError,
|
25
|
+
APIConnectOptions,
|
26
|
+
APIStatusError,
|
27
|
+
APITimeoutError,
|
28
|
+
tts,
|
29
|
+
utils,
|
30
|
+
)
|
31
|
+
from livekit.agents.types import (
|
32
|
+
DEFAULT_API_CONNECT_OPTIONS,
|
33
|
+
NOT_GIVEN,
|
34
|
+
NotGivenOr,
|
35
|
+
)
|
36
|
+
from livekit.agents.utils import is_given
|
37
|
+
|
38
|
+
from .models import LMNTAudioFormats, LMNTLanguages, LMNTModels, LMNTSampleRate
|
39
|
+
|
40
|
+
LMNT_BASE_URL: Final[str] = "https://api.lmnt.com/v1/ai/speech/bytes"
|
41
|
+
NUM_CHANNELS: Final[int] = 1
|
42
|
+
MIME_TYPE: dict[str, str] = {
|
43
|
+
"aac": "audio/aac",
|
44
|
+
"mp3": "audio/mpeg",
|
45
|
+
"mulaw": "audio/basic",
|
46
|
+
"raw": "application/octet-stream",
|
47
|
+
"wav": "audio/wav",
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
@dataclass
|
52
|
+
class _TTSOptions:
|
53
|
+
sample_rate: LMNTSampleRate
|
54
|
+
model: LMNTModels
|
55
|
+
format: LMNTAudioFormats
|
56
|
+
language: LMNTLanguages
|
57
|
+
num_channels: int
|
58
|
+
voice: str
|
59
|
+
api_key: str
|
60
|
+
temperature: float
|
61
|
+
top_p: float
|
62
|
+
|
63
|
+
|
64
|
+
class TTS(tts.TTS):
|
65
|
+
"""
|
66
|
+
Text-to-Speech (TTS) plugin for LMNT.
|
67
|
+
"""
|
68
|
+
|
69
|
+
def __init__(
|
70
|
+
self,
|
71
|
+
*,
|
72
|
+
model: LMNTModels = "blizzard",
|
73
|
+
voice: str = "leah",
|
74
|
+
language: LMNTLanguages | None = None,
|
75
|
+
format: LMNTAudioFormats = "mp3",
|
76
|
+
sample_rate: LMNTSampleRate = 24000,
|
77
|
+
api_key: str | None = None,
|
78
|
+
http_session: aiohttp.ClientSession | None = None,
|
79
|
+
temperature: float = 1.0,
|
80
|
+
top_p: float = 0.8,
|
81
|
+
) -> None:
|
82
|
+
"""
|
83
|
+
Create a new instance of LMNT TTS.
|
84
|
+
|
85
|
+
See: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes
|
86
|
+
|
87
|
+
Args:
|
88
|
+
model: The model to use for synthesis. Default is "blizzard".
|
89
|
+
Learn more at: https://docs.lmnt.com/guides/models
|
90
|
+
voice: The voice ID to use. Default is "leah". Find more amazing voices at https://app.lmnt.com/
|
91
|
+
language: Two-letter ISO 639-1 language code. Defaults to None.
|
92
|
+
See: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes#body-language
|
93
|
+
format: Output file format. Options: aac, mp3, mulaw, raw, wav. Default is "mp3".
|
94
|
+
sample_rate: Output sample rate in Hz. Default is 24000.
|
95
|
+
See: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes#body-sample-rate
|
96
|
+
api_key: API key for authentication. Defaults to the LMNT_API_KEY environment variable.
|
97
|
+
http_session: Optional aiohttp ClientSession. A new session is created if not provided.
|
98
|
+
temperature: Influences how expressive and emotionally varied the speech becomes.
|
99
|
+
Lower values (like 0.3) create more neutral, consistent speaking styles.
|
100
|
+
Higher values (like 1.0) allow for more dynamic emotional range and speaking styles.
|
101
|
+
Default is 1.0.
|
102
|
+
top_p: Controls the stability of the generated speech.
|
103
|
+
A lower value (like 0.3) produces more consistent, reliable speech.
|
104
|
+
A higher value (like 0.9) gives more flexibility in how words are spoken,
|
105
|
+
but might occasionally produce unusual intonations or speech patterns.
|
106
|
+
Default is 0.8.
|
107
|
+
"""
|
108
|
+
super().__init__(
|
109
|
+
capabilities=tts.TTSCapabilities(streaming=False),
|
110
|
+
sample_rate=sample_rate,
|
111
|
+
num_channels=NUM_CHANNELS,
|
112
|
+
)
|
113
|
+
api_key = api_key or os.environ.get("LMNT_API_KEY")
|
114
|
+
if not api_key:
|
115
|
+
raise ValueError(
|
116
|
+
"LMNT API key is required. "
|
117
|
+
"Set it via environment variable or pass it as an argument."
|
118
|
+
)
|
119
|
+
|
120
|
+
if not language:
|
121
|
+
language = "auto" if model == "blizzard" else "en"
|
122
|
+
|
123
|
+
self._opts = _TTSOptions(
|
124
|
+
model=model,
|
125
|
+
sample_rate=sample_rate,
|
126
|
+
num_channels=NUM_CHANNELS,
|
127
|
+
language=language,
|
128
|
+
voice=voice,
|
129
|
+
format=format,
|
130
|
+
api_key=api_key,
|
131
|
+
temperature=temperature,
|
132
|
+
top_p=top_p,
|
133
|
+
)
|
134
|
+
|
135
|
+
self._session = http_session
|
136
|
+
|
137
|
+
def synthesize(
|
138
|
+
self,
|
139
|
+
text: str,
|
140
|
+
*,
|
141
|
+
conn_options: APIConnectOptions = DEFAULT_API_CONNECT_OPTIONS,
|
142
|
+
) -> ChunkedStream:
|
143
|
+
return ChunkedStream(
|
144
|
+
tts=self,
|
145
|
+
input_text=text,
|
146
|
+
conn_options=conn_options,
|
147
|
+
)
|
148
|
+
|
149
|
+
def update_options(
|
150
|
+
self,
|
151
|
+
*,
|
152
|
+
model: NotGivenOr[LMNTModels] = NOT_GIVEN,
|
153
|
+
voice: NotGivenOr[str] = NOT_GIVEN,
|
154
|
+
language: NotGivenOr[LMNTLanguages] = NOT_GIVEN,
|
155
|
+
format: NotGivenOr[LMNTAudioFormats] = NOT_GIVEN,
|
156
|
+
sample_rate: NotGivenOr[LMNTSampleRate] = NOT_GIVEN,
|
157
|
+
temperature: NotGivenOr[float] = NOT_GIVEN,
|
158
|
+
top_p: NotGivenOr[float] = NOT_GIVEN,
|
159
|
+
) -> None:
|
160
|
+
"""
|
161
|
+
Update the TTS options.
|
162
|
+
|
163
|
+
Args:
|
164
|
+
model: The model to use for synthesis. Learn more at: https://docs.lmnt.com/guides/models
|
165
|
+
voice: The voice ID to update.
|
166
|
+
language: Two-letter ISO 639-1 code.
|
167
|
+
See: https://docs.lmnt.com/api-reference/speech/synthesize-speech-bytes#body-language
|
168
|
+
format: Audio output format. Options: aac, mp3, mulaw, raw, wav.
|
169
|
+
sample_rate: Output sample rate in Hz.
|
170
|
+
temperature: Controls the expressiveness of the speech. A number between 0.0 and 1.0.
|
171
|
+
top_p: Controls the stability of the generated speech. A number between 0.0 and 1.0.
|
172
|
+
"""
|
173
|
+
if is_given(model):
|
174
|
+
self._opts.model = model
|
175
|
+
if is_given(voice):
|
176
|
+
self._opts.voice = voice
|
177
|
+
if is_given(language):
|
178
|
+
self._opts.language = language
|
179
|
+
if is_given(format):
|
180
|
+
self._opts.format = format
|
181
|
+
if is_given(sample_rate):
|
182
|
+
self._opts.sample_rate = sample_rate
|
183
|
+
if is_given(temperature):
|
184
|
+
self._opts.temperature = temperature
|
185
|
+
if is_given(top_p):
|
186
|
+
self._opts.top_p = top_p
|
187
|
+
|
188
|
+
def _ensure_session(self) -> aiohttp.ClientSession:
|
189
|
+
if not self._session:
|
190
|
+
self._session = utils.http_context.http_session()
|
191
|
+
|
192
|
+
return self._session
|
193
|
+
|
194
|
+
|
195
|
+
class ChunkedStream(tts.ChunkedStream):
|
196
|
+
"""Synthesize text to speech in chunks."""
|
197
|
+
|
198
|
+
def __init__(
|
199
|
+
self,
|
200
|
+
*,
|
201
|
+
tts: TTS,
|
202
|
+
input_text: str,
|
203
|
+
conn_options: APIConnectOptions,
|
204
|
+
) -> None:
|
205
|
+
super().__init__(tts=tts, input_text=input_text, conn_options=conn_options)
|
206
|
+
self._tts = tts
|
207
|
+
self._opts = replace(tts._opts)
|
208
|
+
|
209
|
+
async def _run(self, output_emitter: tts.AudioEmitter) -> None:
|
210
|
+
data = {
|
211
|
+
"text": self._input_text,
|
212
|
+
"voice": self._opts.voice,
|
213
|
+
"language": self._opts.language,
|
214
|
+
"sample_rate": self._opts.sample_rate,
|
215
|
+
"model": self._opts.model,
|
216
|
+
"format": self._opts.format,
|
217
|
+
"temperature": self._opts.temperature,
|
218
|
+
"top_p": self._opts.top_p,
|
219
|
+
}
|
220
|
+
|
221
|
+
try:
|
222
|
+
async with self._tts._ensure_session().post(
|
223
|
+
LMNT_BASE_URL,
|
224
|
+
headers={
|
225
|
+
"Content-Type": "application/json",
|
226
|
+
"X-API-Key": self._opts.api_key,
|
227
|
+
},
|
228
|
+
json=data,
|
229
|
+
timeout=aiohttp.ClientTimeout(
|
230
|
+
total=30,
|
231
|
+
sock_connect=self._conn_options.timeout,
|
232
|
+
),
|
233
|
+
) as resp:
|
234
|
+
resp.raise_for_status()
|
235
|
+
output_emitter.initialize(
|
236
|
+
request_id=utils.shortuuid(),
|
237
|
+
sample_rate=self._opts.sample_rate,
|
238
|
+
num_channels=NUM_CHANNELS,
|
239
|
+
mime_type=MIME_TYPE[self._opts.format],
|
240
|
+
)
|
241
|
+
async for data, _ in resp.content.iter_chunks():
|
242
|
+
output_emitter.push(data)
|
243
|
+
|
244
|
+
output_emitter.flush()
|
245
|
+
except asyncio.TimeoutError:
|
246
|
+
raise APITimeoutError() from None
|
247
|
+
except aiohttp.ClientResponseError as e:
|
248
|
+
raise APIStatusError(
|
249
|
+
message=e.message,
|
250
|
+
status_code=e.status,
|
251
|
+
request_id=None,
|
252
|
+
body=None,
|
253
|
+
) from None
|
254
|
+
except Exception as e:
|
255
|
+
raise APIConnectionError() from e
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Copyright 2023 LiveKit, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
__version__ = "1.1.0"
|
@@ -0,0 +1,37 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: livekit-plugins-lmnt
|
3
|
+
Version: 1.1.0
|
4
|
+
Summary: LMNT TTS plugin for LiveKit agents
|
5
|
+
Project-URL: Documentation, https://docs.livekit.io
|
6
|
+
Project-URL: Website, https://livekit.io/
|
7
|
+
Project-URL: Source, https://github.com/livekit/agents
|
8
|
+
Author-email: LiveKit <hello@livekit.io>
|
9
|
+
License-Expression: Apache-2.0
|
10
|
+
Keywords: LMNT,TTS,audio,livekit,realtime,voice,webrtc
|
11
|
+
Classifier: Intended Audience :: Developers
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
17
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
19
|
+
Requires-Python: >=3.9.0
|
20
|
+
Requires-Dist: livekit-agents>=1.1.0
|
21
|
+
Description-Content-Type: text/markdown
|
22
|
+
|
23
|
+
# LLMNT plugin for LiveKit Agents
|
24
|
+
|
25
|
+
Support for voice synthesis with [LMNT](https://app.lmnt.com/).
|
26
|
+
|
27
|
+
See [https://docs.livekit.io/agents/integrations/tts/lmnt/]https://docs.livekit.io/agents/integrations/tts/lmnt/ for more information.
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
```bash
|
32
|
+
pip install livekit-plugins-lmnt
|
33
|
+
```
|
34
|
+
|
35
|
+
## Pre-requisites
|
36
|
+
|
37
|
+
You'll need an API key from LMNT. It can be set as an environment variable: `LMNT_API_KEY`. You can get it from [here](https://app.lmnt.com/account#api-keys)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
livekit/plugins/lmnt/__init__.py,sha256=tiK3LPV4hSHACsF1ts0OLivlGM15QGROyWO0ZdyRhPo,1182
|
2
|
+
livekit/plugins/lmnt/models.py,sha256=RyZfq6hep14v-yu_wM7pKz7q5d28Wp5rvihswsR_5yg,409
|
3
|
+
livekit/plugins/lmnt/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
4
|
+
livekit/plugins/lmnt/tts.py,sha256=sQDUIZH0OAneHNWuVU_ls8En03fVCoZUVSDEPyoT8iQ,8944
|
5
|
+
livekit/plugins/lmnt/version.py,sha256=7SjyflIFTjH0djSotKGIRoRykPCqMpVYetIlvHMFuh0,600
|
6
|
+
livekit_plugins_lmnt-1.1.0.dist-info/METADATA,sha256=XmRh2-qT8ZJ-YpDj-5S0Bym4vBP_PM8zOJNkXnM63ww,1394
|
7
|
+
livekit_plugins_lmnt-1.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
8
|
+
livekit_plugins_lmnt-1.1.0.dist-info/RECORD,,
|