livekit-plugins-lmnt 1.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.
@@ -0,0 +1,172 @@
1
+ **/.vscode
2
+ **/.DS_Store
3
+
4
+ # Byte-compiled / optimized / DLL files
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+
9
+ # C extensions
10
+ *.so
11
+
12
+ # Distribution / packaging
13
+ .Python
14
+ build/
15
+ develop-eggs/
16
+ dist/
17
+ downloads/
18
+ eggs/
19
+ .eggs/
20
+ lib/
21
+ lib64/
22
+ parts/
23
+ sdist/
24
+ var/
25
+ wheels/
26
+ share/python-wheels/
27
+ *.egg-info/
28
+ .installed.cfg
29
+ *.egg
30
+ MANIFEST
31
+
32
+ # PyInstaller
33
+ # Usually these files are written by a python script from a template
34
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
35
+ *.manifest
36
+ *.spec
37
+
38
+ # Installer logs
39
+ pip-log.txt
40
+ pip-delete-this-directory.txt
41
+
42
+ # Unit test / coverage reports
43
+ htmlcov/
44
+ .tox/
45
+ .nox/
46
+ .coverage
47
+ .coverage.*
48
+ .cache
49
+ nosetests.xml
50
+ coverage.xml
51
+ *.cover
52
+ *.py,cover
53
+ .hypothesis/
54
+ .pytest_cache/
55
+ cover/
56
+
57
+ # Translations
58
+ *.mo
59
+ *.pot
60
+
61
+ # Django stuff:
62
+ *.log
63
+ local_settings.py
64
+ db.sqlite3
65
+ db.sqlite3-journal
66
+
67
+ # Flask stuff:
68
+ instance/
69
+ .webassets-cache
70
+
71
+ # Scrapy stuff:
72
+ .scrapy
73
+
74
+ # Sphinx documentation
75
+ docs/_build/
76
+
77
+ # PyBuilder
78
+ .pybuilder/
79
+ target/
80
+
81
+ # Jupyter Notebook
82
+ .ipynb_checkpoints
83
+
84
+ # IPython
85
+ profile_default/
86
+ ipython_config.py
87
+
88
+ # pyenv
89
+ # For a library or package, you might want to ignore these files since the code is
90
+ # intended to run in multiple environments; otherwise, check them in:
91
+ # .python-version
92
+
93
+ # pipenv
94
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
95
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
96
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
97
+ # install all needed dependencies.
98
+ #Pipfile.lock
99
+
100
+ # poetry
101
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
102
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
103
+ # commonly ignored for libraries.
104
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
105
+ #poetry.lock
106
+
107
+ # pdm
108
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
109
+ #pdm.lock
110
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
111
+ # in version control.
112
+ # https://pdm.fming.dev/#use-with-ide
113
+ .pdm.toml
114
+
115
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116
+ __pypackages__/
117
+
118
+ # Celery stuff
119
+ celerybeat-schedule
120
+ celerybeat.pid
121
+
122
+ # SageMath parsed files
123
+ *.sage.py
124
+
125
+ # Environments
126
+ .env
127
+ .venv
128
+ env/
129
+ venv/
130
+ ENV/
131
+ env.bak/
132
+ venv.bak/
133
+
134
+ # Spyder project settings
135
+ .spyderproject
136
+ .spyproject
137
+
138
+ # Rope project settings
139
+ .ropeproject
140
+
141
+ # mkdocs documentation
142
+ /site
143
+
144
+ # mypy
145
+ .mypy_cache/
146
+ .dmypy.json
147
+ dmypy.json
148
+
149
+ # trunk
150
+ .trunk/
151
+
152
+ # Pyre type checker
153
+ .pyre/
154
+
155
+ # pytype static type analyzer
156
+ .pytype/
157
+
158
+ # Cython debug symbols
159
+ cython_debug/
160
+
161
+ # PyCharm
162
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
163
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
164
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
165
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
166
+ .idea/
167
+
168
+ node_modules
169
+
170
+ credentials.json
171
+ pyrightconfig.json
172
+ docs/
@@ -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,15 @@
1
+ # LLMNT plugin for LiveKit Agents
2
+
3
+ Support for voice synthesis with [LMNT](https://app.lmnt.com/).
4
+
5
+ See [https://docs.livekit.io/agents/integrations/tts/lmnt/]https://docs.livekit.io/agents/integrations/tts/lmnt/ for more information.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ pip install livekit-plugins-lmnt
11
+ ```
12
+
13
+ ## Pre-requisites
14
+
15
+ 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,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]
@@ -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,40 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "livekit-plugins-lmnt"
7
+ dynamic = ["version"]
8
+ description = "LMNT TTS plugin for LiveKit agents"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.9.0"
12
+ authors = [
13
+ {name = "LiveKit", email = "hello@livekit.io"}
14
+ ]
15
+ keywords = ["webrtc", "realtime", "audio", "livekit", "LMNT", "TTS", "voice"]
16
+ classifiers = [
17
+ "Intended Audience :: Developers",
18
+ "License :: OSI Approved :: Apache Software License",
19
+ "Topic :: Multimedia :: Sound/Audio",
20
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ ]
26
+ dependencies = ["livekit-agents>=1.1.0"]
27
+
28
+ [project.urls]
29
+ Documentation = "https://docs.livekit.io"
30
+ Website = "https://livekit.io/"
31
+ Source = "https://github.com/livekit/agents"
32
+
33
+ [tool.hatch.version]
34
+ path = "livekit/plugins/lmnt/version.py"
35
+
36
+ [tool.hatch.build.targets.wheel]
37
+ packages = ["livekit"]
38
+
39
+ [tool.hatch.build.targets.sdist]
40
+ include = ["/livekit"]